Qt 6.x
The Qt SDK
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
14{
15public:
16 QAudioEngine *engine = nullptr;
19};
20
39{
40 setEngine(engine);
41}
42
47{
48 delete d;
49}
50
58{
59 auto *ep = QAudioEnginePrivate::get(d->engine);
60 pos *= ep->distanceScale;
61 if (d->pos == pos)
62 return;
63
64 d->pos = pos;
65 if (ep && ep->resonanceAudio->api) {
66 ep->resonanceAudio->api->SetHeadPosition(pos.x(), pos.y(), pos.z());
67 ep->listenerPositionDirty = true;
68 }
69}
70
75{
76 auto *ep = QAudioEnginePrivate::get(d->engine);
77 return d->pos/ep->distanceScale;
78}
79
84{
85 d->rotation = q;
86 auto *ep = QAudioEnginePrivate::get(d->engine);
87 if (ep && ep->resonanceAudio->api)
88 ep->resonanceAudio->api->SetHeadRotation(d->rotation.x(), d->rotation.y(), d->rotation.z(), d->rotation.scalar());
89}
90
95{
96 return d->rotation;
97}
98
102void QAudioListener::setEngine(QAudioEngine *engine)
103{
104 if (d->engine) {
105 auto *ed = QAudioEnginePrivate::get(d->engine);
106 ed->listener = nullptr;
107 }
108 d->engine = engine;
109 if (d->engine) {
110 auto *ed = QAudioEnginePrivate::get(d->engine);
111 if (ed->listener) {
112 qWarning() << "Ignoring attempt to add a second listener to the spatial audio engine.";
113 d->engine = nullptr;
114 return;
115 }
116 ed->listener = this;
117 }
118}
119
124{
125 return d->engine;
126}
127
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.
Definition qquaternion.h:21
float z() const
Returns the z coordinate of this quaternion's vector.
float scalar() const
Returns the scalar component of this quaternion.
float x() const
Returns the x coordinate of this quaternion's vector.
float y() const
Returns the y coordinate of this quaternion's vector.
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:162
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
QJSEngine engine
[0]