Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qaudioengine_threaded_p.h
Go to the documentation of this file.
1// Copyright (C) 2026 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_THREADED_P_H
5#define QAUDIOENGINE_THREADED_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/private/qtspatialaudioglobal_p.h>
19#include <QtSpatialAudio/private/qaudioengine_p.h>
20#include <QtCore/qmutex.h>
21#include <QtCore/qthread.h>
22#include <QtMultimedia/qaudiodevice.h>
23
24namespace vraudio {
25class ResonanceAudio;
26} // namespace vraudio
27
28QT_BEGIN_NAMESPACE
29
30class QSpatialSound;
31class QAmbientSound;
33class QAudioRoom;
34class QAudioListener;
35
37{
38public:
39 static QAudioEngineThreaded *get(QAudioEngine *engine)
40 {
41 return engine ? static_cast<QAudioEngineThreaded *>(engine->d_func()) : nullptr;
42 }
43
44 explicit QAudioEngineThreaded(int sampleRate);
47
48 void start() override;
49 void stop() override;
50 void setPaused(bool paused) override;
51 bool isPaused() const override;
52 void setOutputDevice(const QAudioDevice &device) override;
53 QAudioDevice outputDevice() const override { return m_device; }
55 QAudioEngine::OutputMode outputMode() const override { return m_outputMode; };
56
58 bool roomEffectsEnabled() const override;
59 void setListenerPosition(std::optional<QVector3D> pos) override;
60
61 void addSpatialSound(QSpatialSound *sound) override;
62 void removeSpatialSound(QSpatialSound *sound) override;
63 void addStereoSound(QAmbientSound *sound) override;
64 void removeStereoSound(QAmbientSound *sound) override;
65
66 void addRoom(QAudioRoom *room) override;
67 void removeRoom(QAudioRoom *room) override;
68 QAudioRoom *currentRoom() const override { return m_currentRoom; }
69 void updateRooms();
70
71private:
72 friend class QAudioOutputStream;
73 QAudioEngine::OutputMode m_outputMode = QAudioEngine::Surround;
74 bool m_roomEffectsEnabled = true;
75
76 QMutex mutex;
77 QAudioDevice m_device;
78 QAtomicInteger<bool> m_paused = false;
79
80 QThread audioThread;
81 std::unique_ptr<QAudioOutputStream> outputStream;
82
83 QList<QSpatialSound *> sources;
84 QList<QAmbientSound *> stereoSources;
85 QList<QAudioRoom *> rooms;
86 mutable bool listenerPositionDirty = true;
87 QAudioRoom *m_currentRoom = nullptr;
88};
89
90QT_END_NAMESPACE
91
92#endif
void setOutputMode(QAudioEngine::OutputMode) override
void addRoom(QAudioRoom *room) override
static QAudioEngineThreaded * get(QAudioEngine *engine)
QAudioDevice outputDevice() const override
void setListenerPosition(std::optional< QVector3D > pos) override
void addSpatialSound(QSpatialSound *sound) override
QAudioEngine::OutputMode outputMode() const override
void addStereoSound(QAmbientSound *sound) override
void setPaused(bool paused) override
void setOutputDevice(const QAudioDevice &device) override
bool isPaused() const override
void setRoomEffectsEnabled(bool) override
void removeSpatialSound(QSpatialSound *sound) override
bool roomEffectsEnabled() const override
Returns true if room effects are enabled.
void removeStereoSound(QAmbientSound *sound) override
void removeRoom(QAudioRoom *room) override
QAudioRoom * currentRoom() const override
qint64 readData(char *data, qint64 len) override
Reads up to maxSize bytes from the device into data, and returns the number of bytes read or -1 if an...
bool atEnd() const override
Returns true if the current read and write position is at the end of the device (i....
~QAudioOutputStream() override
qint64 pos() const override
For random-access devices, this function returns the position that data is written to or read from.
QAudioOutputStream(QAudioEngineThreaded *d)
bool isSequential() const override
Returns true if this device is sequential; otherwise returns false.
qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
qint64 writeData(const char *, qint64) override
Writes up to maxSize bytes from data to the device.
qint64 size() const override
For open random-access devices, this function returns the size of the device.
QT_BEGIN_NAMESPACE const int bufferTimeMs