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#ifndef QSPATIALSOUND_H
4#define QSPATIALSOUND_H
5
6#include <QtSpatialAudio/qtspatialaudioglobal.h>
7#include <QtCore/QObject>
8#include <QtGui/qvector3d.h>
9#include <QtGui/qquaternion.h>
10
11QT_BEGIN_NAMESPACE
12
13class QAudioEngine;
14class QAmbientSoundPrivate;
15
16class QSpatialSoundPrivate;
17class Q_SPATIALAUDIO_EXPORT QSpatialSound : public QObject
18{
19 Q_OBJECT
20 Q_PROPERTY(QUrl source READ source WRITE setSource NOTIFY sourceChanged)
21 Q_PROPERTY(QVector3D position READ position WRITE setPosition NOTIFY positionChanged)
22 Q_PROPERTY(QQuaternion rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
23 Q_PROPERTY(float volume READ volume WRITE setVolume NOTIFY volumeChanged)
24 Q_PROPERTY(DistanceModel distanceModel READ distanceModel WRITE setDistanceModel NOTIFY distanceModelChanged)
25 Q_PROPERTY(float size READ size WRITE setSize NOTIFY sizeChanged)
26 Q_PROPERTY(float distanceCutoff READ distanceCutoff WRITE setDistanceCutoff NOTIFY distanceCutoffChanged)
27 Q_PROPERTY(float manualAttenuation READ manualAttenuation WRITE setManualAttenuation NOTIFY manualAttenuationChanged)
28 Q_PROPERTY(float occlusionIntensity READ occlusionIntensity WRITE setOcclusionIntensity NOTIFY occlusionIntensityChanged)
29 Q_PROPERTY(float directivity READ directivity WRITE setDirectivity NOTIFY directivityChanged)
30 Q_PROPERTY(float directivityOrder READ directivityOrder WRITE setDirectivityOrder NOTIFY directivityOrderChanged)
31 Q_PROPERTY(float nearFieldGain READ nearFieldGain WRITE setNearFieldGain NOTIFY nearFieldGainChanged)
32 Q_PROPERTY(int loops READ loops WRITE setLoops NOTIFY loopsChanged)
33 Q_PROPERTY(bool autoPlay READ autoPlay WRITE setAutoPlay NOTIFY autoPlayChanged)
34
35public:
36 explicit QSpatialSound(QAudioEngine *engine);
37 ~QSpatialSound();
38
39 void setSource(const QUrl &url);
40 QUrl source() const;
41
42 enum Loops
43 {
44 Infinite = -1,
45 Once = 1
46 };
47 Q_ENUM(Loops)
48
49 int loops() const;
50 void setLoops(int loops);
51
52 bool autoPlay() const;
53 void setAutoPlay(bool autoPlay);
54
55 void setPosition(QVector3D pos);
56 QVector3D position() const;
57
58 void setRotation(const QQuaternion &q);
59 QQuaternion rotation() const;
60
61 void setVolume(float volume);
62 float volume() const;
63
64 enum class DistanceModel {
65 Logarithmic,
66 Linear,
67 ManualAttenuation
68 };
69 Q_ENUM(DistanceModel);
70
71 void setDistanceModel(DistanceModel model);
72 DistanceModel distanceModel() const;
73
74 void setSize(float size);
75 float size() const;
76
77 void setDistanceCutoff(float cutoff);
78 float distanceCutoff() const;
79
80 void setManualAttenuation(float attenuation);
81 float manualAttenuation() const;
82
83 void setOcclusionIntensity(float occlusion);
84 float occlusionIntensity() const;
85
86 void setDirectivity(float alpha);
87 float directivity() const;
88
89 void setDirectivityOrder(float alpha);
90 float directivityOrder() const;
91
92 void setNearFieldGain(float gain);
93 float nearFieldGain() const;
94
95 QAudioEngine *engine() const;
96
97Q_SIGNALS:
98 void sourceChanged();
99 void loopsChanged();
100 void autoPlayChanged();
101 void positionChanged();
102 void rotationChanged();
103 void volumeChanged();
104 void distanceModelChanged();
105 void sizeChanged();
106 void distanceCutoffChanged();
107 void manualAttenuationChanged();
108 void occlusionIntensityChanged();
109 void directivityChanged();
110 void directivityOrderChanged();
111 void nearFieldGainChanged();
112
113public Q_SLOTS:
114 void play();
115 void pause();
116 void stop();
117
118private:
119 void setEngine(QAudioEngine *engine);
120 friend class QAmbientSoundPrivate;
121 friend class QSpatialSoundPrivate;
122 QSpatialSoundPrivate *d = nullptr;
123};
124
125QT_END_NAMESPACE
126
127#endif
128

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