Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qaudiolistener.cpp
Go to the documentation of this file.
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 "qaudiolistener.h"
4#include "qaudioengine_p.h"
5#include "resonance_audio.h"
6#include <qaudiosink.h>
7#include <qurl.h>
8#include <qdebug.h>
9#include <qaudiodecoder.h>
10
12
20
42
47{
48 // Unregister this listener from the engine
49 setEngine(nullptr);
50 delete d;
51}
52
60{
61 auto *ep = QAudioEnginePrivate::get(d->engine);
62 if (!ep)
63 return;
64 pos *= ep->distanceScale;
65 if (d->pos == pos)
66 return;
67
68 d->pos = pos;
69 if (ep && ep->resonanceAudio->api) {
70 ep->resonanceAudio->api->SetHeadPosition(pos.x(), pos.y(), pos.z());
71 ep->listenerPositionDirty = true;
72 }
73}
74
79{
80 auto *ep = QAudioEnginePrivate::get(d->engine);
81 if (!ep)
82 return QVector3D();
83 return d->pos/ep->distanceScale;
84}
85
90{
91 d->rotation = q;
92 auto *ep = QAudioEnginePrivate::get(d->engine);
93 if (ep && ep->resonanceAudio->api)
94 ep->resonanceAudio->api->SetHeadRotation(d->rotation.x(), d->rotation.y(), d->rotation.z(), d->rotation.scalar());
95}
96
101{
102 return d->rotation;
103}
104
108void QAudioListener::setEngine(QAudioEngine *engine)
109{
110 if (d->engine) {
111 auto *ed = QAudioEnginePrivate::get(d->engine);
112 ed->listener = nullptr;
113 }
114 d->engine = engine;
115 if (d->engine) {
116 auto *ed = QAudioEnginePrivate::get(d->engine);
117 if (ed->listener) {
118 qWarning() << "Ignoring attempt to add a second listener to the spatial audio engine.";
119 d->engine = nullptr;
120 return;
121 }
122 ed->listener = this;
123 }
124}
125
130{
131 return d->engine;
132}
133
static QAudioEnginePrivate * get(QAudioEngine *engine)
\inmodule QtSpatialAudio
QVector3D position() const
Returns the current position of the listener.
~QAudioListener()
Destroys the listener.
QAudioEngine * engine() const
Returns the engine associated with this listener.
void setRotation(const QQuaternion &q)
Sets the listener's orientation in 3D space to q.
void setPosition(QVector3D pos)
Sets the listener's position in 3D space to pos.
QQuaternion rotation() const
Returns the listener's orientation in 3D space.
QAudioListener(QAudioEngine *engine)
Creates a listener for the spatial audio engine for engine.
The QQuaternion class represents a quaternion consisting of a vector and scalar.
The QVector3D class represents a vector or vertex in 3D space.
Definition qvectornd.h:171
Combined button and popup list for selecting options.
#define qWarning
Definition qlogging.h:166
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
QJSEngine engine
[0]