Overte C++ Documentation
AudioEffectOptions.h
1 //
2 // AudioEffectOptions.h
3 // libraries/audio/src
4 //
5 // Copyright 2013 High Fidelity, Inc.
6 // Copyright 2022-2023 Overte e.V.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 // SPDX-License-Identifier: Apache-2.0
11 //
12 
13 #ifndef hifi_AudioEffectOptions_h
14 #define hifi_AudioEffectOptions_h
15 
16 #include <QObject>
17 #include <ScriptValue.h>
18 
19 class ScriptContext;
20 class ScriptEngine;
21 
22 /*@jsdoc
23  * Audio effect options used by the {@link Audio} API.
24  *
25  * <p>Create using <code>new AudioEffectOptions(...)</code>.</p>
26  *
27  * @class AudioEffectOptions
28  * @param {AudioEffectOptions.ReverbOptions} [reverbOptions=null] - Reverberation options.
29  *
30  * @hifi-interface
31  * @hifi-client-entity
32  * @hifi-avatar
33  * @hifi-server-entity
34  * @hifi-assignment-client
35  *
36  * @property {number} bandwidth=10000 - The corner frequency (Hz) of the low-pass filter at reverb input.
37  * @property {number} preDelay=20 - The delay (milliseconds) between dry signal and the onset of early reflections.
38  * @property {number} lateDelay=0 - The delay (milliseconds) between early reflections and the onset of reverb tail.
39  * @property {number} reverbTime=2 - The time (seconds) for the reverb tail to decay by 60dB, also known as RT60.
40  * @property {number} earlyDiffusion=100 - Adjusts the buildup of echo density in the early reflections, normally 100%.
41  * @property {number} lateDiffusion=100 - Adjusts the buildup of echo density in the reverb tail, normally 100%.
42  * @property {number} roomSize=50 - The apparent room size, from small (0%) to large (100%).
43  * @property {number} density=100 - Adjusts the echo density in the reverb tail, normally 100%.
44  * @property {number} bassMult=1.5 - Adjusts the bass-frequency reverb time, as multiple of reverbTime.
45  * @property {number} bassFreq=250 - The crossover frequency (Hz) for the onset of bassMult.
46  * @property {number} highGain=-6 - Reduces the high-frequency reverb time, as attenuation (dB).
47  * @property {number} highFreq=3000 - The crossover frequency (Hz) for the onset of highGain.
48  * @property {number} modRate=2.3 - The rate of modulation (Hz) of the LFO-modulated delay lines.
49  * @property {number} modDepth=50 - The depth of modulation (percent) of the LFO-modulated delay lines.
50  * @property {number} earlyGain=0 - Adjusts the relative level (dB) of the early reflections.
51  * @property {number} lateGain=0 - Adjusts the relative level (dB) of the reverb tail.
52  * @property {number} earlyMixLeft=20 - The apparent distance of the source (percent) in the early reflections.
53  * @property {number} earlyMixRight=20 - The apparent distance of the source (percent) in the early reflections.
54  * @property {number} lateMixLeft=90 - The apparent distance of the source (percent) in the reverb tail.
55  * @property {number} lateMixRight=90 - The apparent distance of the source (percent) in the reverb tail.
56  * @property {number} wetDryMix=50 - Adjusts the wet/dry ratio, from completely dry (0%) to completely wet (100%).
57  */
58 
59 class AudioEffectOptions : public QObject {
60  Q_OBJECT
61 
62  Q_PROPERTY(float bandwidth READ getBandwidth WRITE setBandwidth)
63  Q_PROPERTY(float preDelay READ getPreDelay WRITE setPreDelay)
64  Q_PROPERTY(float lateDelay READ getLateDelay WRITE setLateDelay)
65  Q_PROPERTY(float reverbTime READ getReverbTime WRITE setReverbTime)
66  Q_PROPERTY(float earlyDiffusion READ getEarlyDiffusion WRITE setEarlyDiffusion)
67  Q_PROPERTY(float lateDiffusion READ getLateDiffusion WRITE setLateDiffusion)
68  Q_PROPERTY(float roomSize READ getRoomSize WRITE setRoomSize)
69  Q_PROPERTY(float density READ getDensity WRITE setDensity)
70  Q_PROPERTY(float bassMult READ getBassMult WRITE setBassMult)
71  Q_PROPERTY(float bassFreq READ getBassFreq WRITE setBassFreq)
72  Q_PROPERTY(float highGain READ getHighGain WRITE setHighGain)
73  Q_PROPERTY(float highFreq READ getHighFreq WRITE setHighFreq)
74  Q_PROPERTY(float modRate READ getModRate WRITE setModRate)
75  Q_PROPERTY(float modDepth READ getModDepth WRITE setModDepth)
76  Q_PROPERTY(float earlyGain READ getEarlyGain WRITE setEarlyGain)
77  Q_PROPERTY(float lateGain READ getLateGain WRITE setLateGain)
78  Q_PROPERTY(float earlyMixLeft READ getEarlyMixLeft WRITE setEarlyMixLeft)
79  Q_PROPERTY(float earlyMixRight READ getEarlyMixRight WRITE setEarlyMixRight)
80  Q_PROPERTY(float lateMixLeft READ getLateMixLeft WRITE setLateMixLeft)
81  Q_PROPERTY(float lateMixRight READ getLateMixRight WRITE setLateMixRight)
82  Q_PROPERTY(float wetDryMix READ getWetDryMix WRITE setWetDryMix)
83 
84 public:
85  AudioEffectOptions(const ScriptValue& arguments = ScriptValue());
86  AudioEffectOptions(const AudioEffectOptions &other);
87  AudioEffectOptions& operator=(const AudioEffectOptions &other);
88 
89  static ScriptValue constructor(ScriptContext* context, ScriptEngine* engine);
90 
91  float getBandwidth() const { return _bandwidth; }
92  void setBandwidth(float bandwidth) { _bandwidth = bandwidth; }
93 
94  float getPreDelay() const { return _preDelay; }
95  void setPreDelay(float preDelay) { _preDelay = preDelay; }
96 
97  float getLateDelay() const { return _lateDelay; }
98  void setLateDelay(float lateDelay) { _lateDelay = lateDelay; }
99 
100  float getReverbTime() const { return _reverbTime; }
101  void setReverbTime(float reverbTime) { _reverbTime = reverbTime; }
102 
103  float getEarlyDiffusion() const { return _earlyDiffusion; }
104  void setEarlyDiffusion(float earlyDiffusion) { _earlyDiffusion = earlyDiffusion; }
105 
106  float getLateDiffusion() const { return _lateDiffusion; }
107  void setLateDiffusion(float lateDiffusion) { _lateDiffusion = lateDiffusion; }
108 
109  float getRoomSize() const { return _roomSize; }
110  void setRoomSize(float roomSize) { _roomSize = roomSize; }
111 
112  float getDensity() const { return _density; }
113  void setDensity(float density) { _density = density; }
114 
115  float getBassMult() const { return _bassMult; }
116  void setBassMult(float bassMult) { _bassMult = bassMult; }
117 
118  float getBassFreq() const { return _bassFreq; }
119  void setBassFreq(float bassFreq) { _bassFreq = bassFreq; }
120 
121  float getHighGain() const { return _highGain; }
122  void setHighGain(float highGain) { _highGain = highGain; }
123 
124  float getHighFreq() const { return _highFreq; }
125  void setHighFreq(float highFreq) { _highFreq = highFreq; }
126 
127  float getModRate() const { return _modRate; }
128  void setModRate(float modRate) { _modRate = modRate; }
129 
130  float getModDepth() const { return _modDepth; }
131  void setModDepth(float modDepth) { _modDepth = modDepth; }
132 
133  float getEarlyGain() const { return _earlyGain; }
134  void setEarlyGain(float earlyGain) { _earlyGain = earlyGain; }
135 
136  float getLateGain() const { return _lateGain; }
137  void setLateGain(float lateGain) { _lateGain = lateGain; }
138 
139  float getEarlyMixLeft() const { return _earlyMixLeft; }
140  void setEarlyMixLeft(float earlyMixLeft) { _earlyMixLeft = earlyMixLeft; }
141 
142  float getEarlyMixRight() const { return _earlyMixRight; }
143  void setEarlyMixRight(float earlyMixRight) { _earlyMixRight = earlyMixRight; }
144 
145  float getLateMixLeft() const { return _lateMixLeft; }
146  void setLateMixLeft(float lateMixLeft) { _lateMixLeft = lateMixLeft; }
147 
148  float getLateMixRight() const { return _lateMixRight; }
149  void setLateMixRight(float lateMixRight) { _lateMixRight = lateMixRight; }
150 
151  float getWetDryMix() const { return _wetDryMix; }
152  void setWetDryMix(float wetDryMix) { _wetDryMix = wetDryMix; }
153 
154 private:
155  float _bandwidth; // [20, 24000] Hz
156 
157  float _preDelay; // [0, 333] ms
158  float _lateDelay; // [0, 166] ms
159 
160  float _reverbTime; // [0.1, 100] seconds
161 
162  float _earlyDiffusion; // [0, 100] percent
163  float _lateDiffusion; // [0, 100] percent
164 
165  float _roomSize; // [0, 100] percent
166  float _density; // [0, 100] percent
167 
168  float _bassMult; // [0.1, 10] ratio
169  float _bassFreq; // [10, 500] Hz
170  float _highGain; // [-24, 0] dB
171  float _highFreq; // [1000, 12000] Hz
172 
173  float _modRate; // [0.1, 10] Hz
174  float _modDepth; // [0, 100] percent
175 
176  float _earlyGain; // [-96, +24] dB
177  float _lateGain; // [-96, +24] dB
178 
179  float _earlyMixLeft; // [0, 100] percent
180  float _earlyMixRight; // [0, 100] percent
181  float _lateMixLeft; // [0, 100] percent
182  float _lateMixRight; // [0, 100] percent
183 
184  float _wetDryMix; // [0, 100] percent
185 };
186 
187 Q_DECLARE_METATYPE(AudioEffectOptions);
188 
189 ScriptValue audioEffectOptionsToScriptValue(ScriptEngine* scriptEngine, const AudioEffectOptions& audioEffectOptions);
190 
191 bool audioEffectOptionsFromScriptValue(const ScriptValue& scriptValue, AudioEffectOptions& audioEffectOptions);
192 
193 #endif // hifi_AudioEffectOptions_h
[ScriptInterface] Provides an engine-independent interface for QScriptContext
Definition: ScriptContext.h:55
Provides an engine-independent interface for a scripting engine.
Definition: ScriptEngine.h:93
[ScriptInterface] Provides an engine-independent interface for QScriptValue
Definition: ScriptValue.h:40