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
4#ifndef QAUDIOENGINE_P_H
5#define QAUDIOENGINE_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of other Qt classes. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtSpatialAudio/qaudioengine.h>
19#include <QtSpatialAudio/private/qtspatialaudioglobal_p.h>
20#include <QtMultimedia/qaudiodevice.h>
21#include <QtCore/qthread.h>
22#include <QtCore/qtclasshelpermacros.h>
23#include <QtCore/qmutex.h>
24
25namespace vraudio {
26class ResonanceAudio;
27} // namespace vraudio
28
29QT_BEGIN_NAMESPACE
30
31class QSpatialSound;
32class QAmbientSound;
33class QAudioOutputStream;
34class QAudioRoom;
35class QAudioListener;
36class QAudioEngine;
37
38class QAudioEnginePrivate
39{
40public:
41 static QAudioEnginePrivate *get(QAudioEngine *engine) { return engine ? engine->d : nullptr; }
42
43 static constexpr int bufferSize = 128;
44
45 explicit QAudioEnginePrivate(QAudioEngine *);
46 Q_DISABLE_COPY_MOVE(QAudioEnginePrivate)
47 ~QAudioEnginePrivate();
48
49 std::unique_ptr<vraudio::ResonanceAudio> resonanceAudio;
50 int sampleRate = 44100;
51 float masterVolume = 1.;
52 QAudioEngine::OutputMode outputMode = QAudioEngine::Surround;
53 bool roomEffectsEnabled = true;
54
55 void start();
56 void stop();
57 void setPaused(bool paused);
58 void setOutputDevice(const QAudioDevice &device);
59 void setOutputMode(QAudioEngine::OutputMode);
60
61 // Resonance Audio uses meters internally, while Qt Quick 3D and our API uses cm by
62 // default. To make things independent from the scale setting, we store all distances in
63 // meters internally and convert in the setters and getters.
64 float distanceScale = 0.01f;
65
66 QMutex mutex;
67 QAudioDevice device;
68 QAtomicInteger<bool> paused = false;
69
70 QThread audioThread;
71 std::unique_ptr<QAudioOutputStream> outputStream;
72
73 QAudioListener *listener = nullptr;
74 QList<QSpatialSound *> sources;
75 QList<QAmbientSound *> stereoSources;
76 QList<QAudioRoom *> rooms;
77 mutable bool listenerPositionDirty = true;
78 QAudioRoom *currentRoom = nullptr;
79
80 void addSpatialSound(QSpatialSound *sound);
81 void removeSpatialSound(QSpatialSound *sound);
82 void addStereoSound(QAmbientSound *sound);
83 void removeStereoSound(QAmbientSound *sound);
84
85 void addRoom(QAudioRoom *room);
86 void removeRoom(QAudioRoom *room);
87 void updateRooms();
88
89 QVector3D listenerPosition() const;
90 QAudioEngine *q;
91};
92
93QT_END_NAMESPACE
94
95#endif
96

source code of qtmultimedia/src/spatialaudio/qaudioengine_p.h