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 <qtspatialaudioglobal_p.h> |
19 | #include <qaudioengine.h> |
20 | #include <qaudiodevice.h> |
21 | #include <qaudiodecoder.h> |
22 | #include <qthread.h> |
23 | #include <qmutex.h> |
24 | #include <qurl.h> |
25 | #include <qaudiobuffer.h> |
26 | #include <qvector3d.h> |
27 | #include <qfile.h> |
28 | |
29 | namespace vraudio { |
30 | class ResonanceAudio; |
31 | } |
32 | |
33 | QT_BEGIN_NAMESPACE |
34 | |
35 | class QSpatialSound; |
36 | class QAmbientSound; |
37 | class QAudioSink; |
38 | class QAudioOutputStream; |
39 | class QAmbisonicDecoder; |
40 | class QAudioDecoder; |
41 | class QAudioRoom; |
42 | class QAudioListener; |
43 | |
44 | class QAudioEnginePrivate |
45 | { |
46 | public: |
47 | static QAudioEnginePrivate *get(QAudioEngine *engine) { return engine ? engine->d : nullptr; } |
48 | |
49 | static constexpr int bufferSize = 128; |
50 | |
51 | QAudioEnginePrivate(); |
52 | ~QAudioEnginePrivate(); |
53 | vraudio::ResonanceAudio *resonanceAudio = nullptr; |
54 | int sampleRate = 44100; |
55 | float masterVolume = 1.; |
56 | QAudioEngine::OutputMode outputMode = QAudioEngine::Surround; |
57 | bool roomEffectsEnabled = true; |
58 | |
59 | // Resonance Audio uses meters internally, while Qt Quick 3D and our API uses cm by default. |
60 | // To make things independent from the scale setting, we store all distances in meters internally |
61 | // and convert in the setters and getters. |
62 | float distanceScale = 0.01f; |
63 | |
64 | QMutex mutex; |
65 | QAudioDevice device; |
66 | QAtomicInteger<bool> paused = false; |
67 | |
68 | QThread audioThread; |
69 | std::unique_ptr<QAudioOutputStream> outputStream; |
70 | |
71 | QAudioListener *listener = nullptr; |
72 | QList<QSpatialSound *> sources; |
73 | QList<QAmbientSound *> stereoSources; |
74 | QList<QAudioRoom *> rooms; |
75 | mutable bool listenerPositionDirty = true; |
76 | QAudioRoom *currentRoom = nullptr; |
77 | |
78 | void addSpatialSound(QSpatialSound *sound); |
79 | void removeSpatialSound(QSpatialSound *sound); |
80 | void addStereoSound(QAmbientSound *sound); |
81 | void removeStereoSound(QAmbientSound *sound); |
82 | |
83 | void addRoom(QAudioRoom *room); |
84 | void removeRoom(QAudioRoom *room); |
85 | void updateRooms(); |
86 | |
87 | QVector3D listenerPosition() const; |
88 | }; |
89 | |
90 | QT_END_NAMESPACE |
91 | |
92 | #endif |
93 | |