1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-3.0-only
3#include <qquick3daudiolistener_p.h>
4#include <qquick3dspatialsound_p.h>
5#include <qquick3daudioengine_p.h>
6
7QT_BEGIN_NAMESPACE
8
9/*!
10 \qmltype AudioListener
11 \inqmlmodule QtQuick3D.SpatialAudio
12 \ingroup quick3d_spatialaudio
13 \ingroup multimedia_audio_qml
14
15 \brief defines the position and orientation of the person listening to a sound field
16 defined by a AudioEngine.
17
18 A AudioEngine can have exactly one listener, that defines the position and orientation
19 of the person listening to the sounds defined by the objects placed within the audio engine.
20
21 In most cases, the AudioListener should simply be a child of the Camera element in QtQuick3D.
22 This will ensure that the sound experience is aligned with the visual rendering of the scene.
23 */
24
25QQuick3DAudioListener::QQuick3DAudioListener()
26{
27 m_listener = new QAudioListener(QQuick3DAudioEngine::getEngine());
28 connect(sender: this, signal: &QQuick3DNode::scenePositionChanged, context: this, slot: &QQuick3DAudioListener::updatePosition);
29 connect(sender: this, signal: &QQuick3DNode::sceneRotationChanged, context: this, slot: &QQuick3DAudioListener::updateRotation);
30 updatePosition();
31 updateRotation();
32}
33
34QQuick3DAudioListener::~QQuick3DAudioListener()
35{
36 delete m_listener;
37}
38
39void QQuick3DAudioListener::updatePosition()
40{
41 m_listener->setPosition(scenePosition());
42}
43
44void QQuick3DAudioListener::updateRotation()
45{
46 m_listener->setRotation(sceneRotation());
47}
48
49QT_END_NAMESPACE
50

source code of qtmultimedia/src/spatialaudioquick3d/qquick3daudiolistener.cpp