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_H
5#define QAUDIOENGINE_H
6
7#include <QtSpatialAudio/qtspatialaudioglobal.h>
8#include <QtCore/qobject.h>
9
10QT_BEGIN_NAMESPACE
11
12class QAudioEnginePrivate;
13class QAudioDevice;
14
15class Q_SPATIALAUDIO_EXPORT QAudioEngine : public QObject
16{
17 Q_OBJECT
18 Q_PROPERTY(OutputMode outputMode READ outputMode WRITE setOutputMode NOTIFY outputModeChanged)
19 Q_PROPERTY(QAudioDevice outputDevice READ outputDevice WRITE setOutputDevice NOTIFY outputDeviceChanged)
20 Q_PROPERTY(float masterVolume READ masterVolume WRITE setMasterVolume NOTIFY masterVolumeChanged)
21 Q_PROPERTY(bool paused READ paused WRITE setPaused NOTIFY pausedChanged)
22 Q_PROPERTY(float distanceScale READ distanceScale WRITE setDistanceScale NOTIFY distanceScaleChanged)
23public:
24 QAudioEngine() : QAudioEngine(nullptr) {};
25 explicit QAudioEngine(QObject *parent) : QAudioEngine(44100, parent) {}
26 explicit QAudioEngine(int sampleRate, QObject *parent = nullptr);
27 ~QAudioEngine();
28
29 enum OutputMode {
30 Surround,
31 Stereo,
32 Headphone
33 };
34 Q_ENUM(OutputMode)
35
36 void setOutputMode(OutputMode mode);
37 OutputMode outputMode() const;
38
39 int sampleRate() const;
40
41 void setOutputDevice(const QAudioDevice &device);
42 QAudioDevice outputDevice() const;
43
44 void setMasterVolume(float volume);
45 float masterVolume() const;
46
47 void setPaused(bool paused);
48 bool paused() const;
49
50 void setRoomEffectsEnabled(bool enabled);
51 bool roomEffectsEnabled() const;
52
53 static constexpr float DistanceScaleCentimeter = 1.f;
54 static constexpr float DistanceScaleMeter = 100.f;
55
56 void setDistanceScale(float scale);
57 float distanceScale() const;
58
59Q_SIGNALS:
60 void outputModeChanged();
61 void outputDeviceChanged();
62 void masterVolumeChanged();
63 void pausedChanged();
64 void distanceScaleChanged();
65
66public Q_SLOTS:
67 void start();
68 void stop();
69
70 void pause() { setPaused(true); }
71 void resume() { setPaused(false); }
72
73private:
74 friend class QAudioEnginePrivate;
75 QAudioEnginePrivate *d;
76};
77
78QT_END_NAMESPACE
79
80#endif
81

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