Overte C++ Documentation
Audio.h
1 //
2 // Audio.h
3 // interface/src/scripting
4 //
5 // Created by Zach Pomerantz on 28/5/2017.
6 // Copyright 2017 High Fidelity, Inc.
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 //
11 
12 #ifndef hifi_scripting_Audio_h
13 #define hifi_scripting_Audio_h
14 
15 #include <functional>
16 #include "AudioScriptingInterface.h"
17 #include "AudioDevices.h"
18 #include "AudioEffectOptions.h"
19 #include "SettingHandle.h"
20 #include "AudioFileWav.h"
21 #include <shared/ReadWriteLockable.h>
22 #include <HifiAudioDeviceInfo.h>
23 
24 using MutedGetter = std::function<bool()>;
25 using MutedSetter = std::function<void(bool)>;
26 
27 namespace scripting {
28 
29 class Audio : public AudioScriptingInterface, protected ReadWriteLockable {
30  Q_OBJECT
31  SINGLETON_DEPENDENCY
32 
33  /*@jsdoc
34  * The <code>Audio</code> API provides facilities to interact with audio inputs and outputs and to play sounds.
35  *
36  * @namespace Audio
37  *
38  * @hifi-interface
39  * @hifi-client-entity
40  * @hifi-avatar
41  * @hifi-server-entity
42  * @hifi-assignment-client
43  *
44  * @property {boolean} muted - <code>true</code> if the audio input is muted for the current user context (desktop or HMD),
45  * otherwise <code>false</code>.
46  * @property {boolean} mutedDesktop - <code>true</code> if desktop audio input is muted, otherwise <code>false</code>.
47  * @property {boolean} mutedHMD - <code>true</code> if the HMD input is muted, otherwise <code>false</code>.
48  * @property {boolean} warnWhenMuted - <code>true</code> if the "muted" warning is enabled, otherwise <code>false</code>.
49  * When enabled, if you speak while your microphone is muted, "muted" is displayed on the screen as a warning.
50  * @property {boolean} noiseReduction - <code>true</code> if noise reduction is enabled, otherwise <code>false</code>. When
51  * enabled, the input audio signal is blocked (fully attenuated) when it falls below an adaptive threshold set just
52  * above the noise floor.
53  * @property {boolean} noiseReductionAutomatic - <code>true</code> if audio input noise reduction automatic mode is enabled,
54  * <code>false</code> if in manual mode. Manual mode allows you to use <code>Audio.noiseReductionThreshold</code>
55  * to set a manual sensitivity for the noise gate.
56  * @property {number} noiseReductionThreshold - Sets the noise gate threshold before your mic audio is transmitted.
57  * (Applies only if <code>Audio.noiseReductionAutomatic</code> is <code>false</code>.)
58  * @property {number} inputVolume - Adjusts the volume of the input audio, range <code>0.0</code> &ndash; <code>1.0</code>.
59  * If set to a value, the resulting value depends on the input device: for example, the volume can't be changed on some
60  * devices, and others might only support values of <code>0.0</code> and <code>1.0</code>.
61  * @property {number} inputLevel - The loudness of the audio input, range <code>0.0</code> (no sound) &ndash;
62  * <code>1.0</code> (the onset of clipping). <em>Read-only.</em>
63  * @property {boolean} clipping - <code>true</code> if the audio input is clipping, otherwise <code>false</code>.
64  * @property {string} context - The current context of the audio: either <code>"Desktop"</code> or <code>"HMD"</code>.
65  * <em>Read-only.</em>
66  * @property {object} devices - <em>Read-only.</em>
67  * <p class="important">Deprecated: This property is deprecated and will be removed.
68  * @property {boolean} pushToTalk - <code>true</code> if push-to-talk is enabled for the current user context (desktop or
69  * HMD), otherwise <code>false</code>.
70  * @property {boolean} pushToTalkDesktop - <code>true</code> if desktop push-to-talk is enabled, otherwise
71  * <code>false</code>.
72  * @property {boolean} pushToTalkHMD - <code>true</code> if HMD push-to-talk is enabled, otherwise <code>false</code>.
73  * @property {boolean} pushingToTalk - <code>true</code> if the user is currently pushing-to-talk, otherwise
74  * <code>false</code>.
75 
76  * @property {number} avatarGain - The gain (relative volume in dB) that avatars' voices are played at. This gain is used
77  * at the server.
78  * @property {number} localInjectorGain - The gain (relative volume in dB) that local injectors (local environment sounds)
79  * are played at.
80  * @property {number} serverInjectorGain - The gain (relative volume in dB) that server injectors (server environment
81  * sounds) are played at. This gain is used at the server.
82  * @property {number} systemInjectorGain - The gain (relative volume in dB) that system sounds are played at.
83  * @property {number} pushingToTalkOutputGainDesktop - The gain (relative volume in dB) that all sounds are played at when
84  * the user is holding the push-to-talk key in desktop mode.
85  * @property {boolean} acousticEchoCancellation - <code>true</code> if acoustic echo cancellation is enabled, otherwise
86  * <code>false</code>. When enabled, sound from the audio output is suppressed when it echos back to the input audio
87  * signal.
88  *
89  * @comment The following properties are from AudioScriptingInterface.h.
90  * @property {boolean} isStereoInput - <code>true</code> if the input audio is being used in stereo, otherwise
91  * <code>false</code>. Some devices do not support stereo, in which case the value is always <code>false</code>.
92  * @property {boolean} isSoloing - <code>true</code> if currently audio soloing, i.e., playing audio from only specific
93  * avatars. <em>Read-only.</em>
94  * @property {Uuid[]} soloList - The list of currently soloed avatar IDs. Empty list if not currently audio soloing.
95  * <em>Read-only.</em>
96  */
97 
98  Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged)
99  Q_PROPERTY(bool noiseReduction READ noiseReductionEnabled WRITE enableNoiseReduction NOTIFY noiseReductionChanged)
100  Q_PROPERTY(bool noiseReductionAutomatic READ noiseReductionAutomatic WRITE enableNoiseReductionAutomatic NOTIFY noiseReductionAutomaticChanged)
101  Q_PROPERTY(float noiseReductionThreshold READ getNoiseReductionThreshold WRITE setNoiseReductionThreshold NOTIFY noiseReductionThresholdChanged)
102  Q_PROPERTY(bool warnWhenMuted READ warnWhenMutedEnabled WRITE enableWarnWhenMuted NOTIFY warnWhenMutedChanged)
103  Q_PROPERTY(bool acousticEchoCancellation
104  READ acousticEchoCancellationEnabled WRITE enableAcousticEchoCancellation NOTIFY acousticEchoCancellationChanged)
105  Q_PROPERTY(float inputVolume READ getInputVolume WRITE setInputVolume NOTIFY inputVolumeChanged)
106  Q_PROPERTY(float inputLevel READ getInputLevel NOTIFY inputLevelChanged)
107  Q_PROPERTY(bool clipping READ isClipping NOTIFY clippingChanged)
108  Q_PROPERTY(QString context READ getContext NOTIFY contextChanged)
109  Q_PROPERTY(AudioDevices* devices READ getDevices NOTIFY nop)
110  Q_PROPERTY(bool mutedDesktop READ getMutedDesktop WRITE setMutedDesktop NOTIFY mutedDesktopChanged)
111  Q_PROPERTY(bool mutedHMD READ getMutedHMD WRITE setMutedHMD NOTIFY mutedHMDChanged)
112  Q_PROPERTY(bool pushToTalk READ getPTT WRITE setPTT NOTIFY pushToTalkChanged);
113  Q_PROPERTY(bool pushToTalkDesktop READ getPTTDesktop WRITE setPTTDesktop NOTIFY pushToTalkDesktopChanged)
114  Q_PROPERTY(bool pushToTalkHMD READ getPTTHMD WRITE setPTTHMD NOTIFY pushToTalkHMDChanged)
115  Q_PROPERTY(bool pushingToTalk READ getPushingToTalk WRITE setPushingToTalk NOTIFY pushingToTalkChanged)
116  Q_PROPERTY(float pushingToTalkOutputGainDesktop READ getPushingToTalkOutputGainDesktop
117  WRITE setPushingToTalkOutputGainDesktop NOTIFY pushingToTalkOutputGainDesktopChanged)
118  Q_PROPERTY(float avatarGain READ getAvatarGain WRITE setAvatarGain NOTIFY avatarGainChanged)
119  Q_PROPERTY(float localInjectorGain READ getLocalInjectorGain WRITE setLocalInjectorGain NOTIFY localInjectorGainChanged)
120  Q_PROPERTY(float serverInjectorGain READ getInjectorGain WRITE setInjectorGain NOTIFY serverInjectorGainChanged)
121  Q_PROPERTY(float systemInjectorGain READ getSystemInjectorGain WRITE setSystemInjectorGain NOTIFY systemInjectorGainChanged)
122 
123 public:
124  static QString AUDIO;
125  static QString HMD;
126  static QString DESKTOP;
127 
128  static float loudnessToLevel(float loudness);
129 
130  virtual ~Audio() {}
131 
132  bool isMuted() const;
133  bool noiseReductionEnabled() const;
134  bool noiseReductionAutomatic() const;
135  bool warnWhenMutedEnabled() const;
136  bool acousticEchoCancellationEnabled() const;
137  float getInputVolume() const;
138  float getInputLevel() const;
139  bool isClipping() const;
140  QString getContext() const;
141 
142  void showMicMeter(bool show);
143 
144  // Mute setting setters and getters
145  void setMutedDesktop(bool isMuted);
146  bool getMutedDesktop() const;
147  void setMutedHMD(bool isMuted);
148  bool getMutedHMD() const;
149  void setPTT(bool enabled);
150  bool getPTT();
151  void setPushingToTalk(bool pushingToTalk);
152  bool getPushingToTalk() const;
153 
154  // Push-To-Talk setters and getters
155  void setPTTDesktop(bool enabled);
156  bool getPTTDesktop() const;
157  void setPTTHMD(bool enabled);
158  bool getPTTHMD() const;
159 
160  // Settings handlers
161  void saveData();
162  void loadData();
163 
164  /*@jsdoc
165  * @function Audio.setInputDevice
166  * @param {object} device - Device.
167  * @param {boolean} isHMD - Is HMD.
168  * @deprecated This function is deprecated and will be removed.
169  */
170  Q_INVOKABLE void setInputDevice(const HifiAudioDeviceInfo& device, bool isHMD);
171 
172  /*@jsdoc
173  * @function Audio.setOutputDevice
174  * @param {object} device - Device.
175  * @param {boolean} isHMD - Is HMD.
176  * @deprecated This function is deprecated and will be removed.
177  */
178  Q_INVOKABLE void setOutputDevice(const HifiAudioDeviceInfo& device, bool isHMD);
179 
180  /*@jsdoc
181  * Enables or disables reverberation. Reverberation is done by the client on the post-mix audio. The reverberation options
182  * come from either the domain's audio zone configured on the server or settings scripted by
183  * {@link Audio.setReverbOptions|setReverbOptions}.
184  * @function Audio.setReverb
185  * @param {boolean} enable - <code>true</code> to enable reverberation, <code>false</code> to disable.
186  * @example <caption>Enable reverberation for a short while.</caption>
187  * var sound = SoundCache.getSound(Script.resourcesPath() + "sounds/sample.wav");
188  * var injector;
189  * var injectorOptions = {
190  * position: MyAvatar.position
191  * };
192  *
193  * Script.setTimeout(function () {
194  * print("Reverb OFF");
195  * Audio.setReverb(false);
196  * injector = Audio.playSound(sound, injectorOptions);
197  * }, 1000);
198  *
199  * Script.setTimeout(function () {
200  * var reverbOptions = new AudioEffectOptions();
201  * reverbOptions.roomSize = 100;
202  * Audio.setReverbOptions(reverbOptions);
203  * print("Reverb ON");
204  * Audio.setReverb(true);
205  * }, 4000);
206  *
207  * Script.setTimeout(function () {
208  * print("Reverb OFF");
209  * Audio.setReverb(false);
210  * }, 8000); */
211  Q_INVOKABLE void setReverb(bool enable);
212 
213  /*@jsdoc
214  * Configures reverberation options. Use {@link Audio.setReverb|setReverb} to enable or disable reverberation.
215  * @function Audio.setReverbOptions
216  * @param {AudioEffectOptions} options - The reverberation options.
217  */
218  Q_INVOKABLE void setReverbOptions(const AudioEffectOptions options);
219 
220  /*@jsdoc
221  * Sets the gain (relative volume) that avatars' voices are played at. This gain is used at the server.
222  * @function Audio.setAvatarGain
223  * @param {number} gain - The avatar gain (dB) at the server.
224  */
225  Q_INVOKABLE void setAvatarGain(float gain);
226 
227  /*@jsdoc
228  * Gets the gain (relative volume) that avatars' voices are played at. This gain is used at the server.
229  * @function Audio.getAvatarGain
230  * @returns {number} The avatar gain (dB) at the server.
231  * @example <caption>Report current audio gain settings.</caption>
232  * // 0 value = normal volume; -ve value = quieter; +ve value = louder.
233  * print("Avatar gain: " + Audio.getAvatarGain());
234  * print("Environment server gain: " + Audio.getInjectorGain());
235  * print("Environment local gain: " + Audio.getLocalInjectorGain());
236  * print("System gain: " + Audio.getSystemInjectorGain());
237  */
238  Q_INVOKABLE float getAvatarGain();
239 
240  /*@jsdoc
241  * Sets the gain (relative volume) that environment sounds from the server are played at.
242  * @function Audio.setInjectorGain
243  * @param {number} gain - The injector gain (dB) at the server.
244  */
245  Q_INVOKABLE void setInjectorGain(float gain);
246 
247  /*@jsdoc
248  * Gets the gain (relative volume) that environment sounds from the server are played at.
249  * @function Audio.getInjectorGain
250  * @returns {number} The injector gain (dB) at the server.
251  */
252  Q_INVOKABLE float getInjectorGain();
253 
254  /*@jsdoc
255  * Sets the gain (relative volume) that environment sounds from the client are played at.
256  * @function Audio.setLocalInjectorGain
257  * @param {number} gain - The injector gain (dB) in the client.
258  */
259  Q_INVOKABLE void setLocalInjectorGain(float gain);
260 
261  /*@jsdoc
262  * Gets the gain (relative volume) that environment sounds from the client are played at.
263  * @function Audio.getLocalInjectorGain
264  * @returns {number} The injector gain (dB) in the client.
265  */
266  Q_INVOKABLE float getLocalInjectorGain();
267 
268  /*@jsdoc
269  * Sets the gain (relative volume) that system sounds are played at.
270  * @function Audio.setSystemInjectorGain
271  * @param {number} gain - The injector gain (dB) in the client.
272  */
273  Q_INVOKABLE void setSystemInjectorGain(float gain);
274 
275  /*@jsdoc
276  * Gets the gain (relative volume) that system sounds are played at.
277  * @function Audio.getSystemInjectorGain
278  * @returns {number} The injector gain (dB) in the client.
279  */
280  Q_INVOKABLE float getSystemInjectorGain();
281 
282  /*@jsdoc
283  * Sets the noise gate threshold before your mic audio is transmitted. (Applies only if <code>Audio.noiseReductionAutomatic</code> is <code>false</code>.)
284  * @function Audio.setNoiseReductionThreshold
285  * @param {number} threshold - The level that your input must surpass to be transmitted. <code>0.0</code> (open the gate completely) &ndash; <code>1.0</code>
286  */
287  Q_INVOKABLE void setNoiseReductionThreshold(float threshold);
288 
289  /*@jsdoc
290  * Gets the noise reduction threshold.
291  * @function Audio.getNoiseReductionThreshold
292  * @returns {number} The noise reduction threshold. <code>0.0</code> &ndash; <code>1.0</code>
293  */
294  Q_INVOKABLE float getNoiseReductionThreshold();
295 
296  /*@jsdoc
297  * Starts making an audio recording of the audio being played in-world (i.e., not local-only audio) to a file in WAV format.
298  * Audio is recorded to snapshots directory specified in settings.
299  * @function Audio.startRecording
300  * @returns {Uuid} A valid <code>Uuid</code> if the specified file could be opened and audio recording has started, otherwise
301  * <code>Uuid.NULL</code>.
302  * @example <caption>Make a 10 second audio recording.</caption>
303  * if (Audio.startRecording() !== Uuid.NULL) {
304  * Script.setTimeout(function () {
305  * Audio.stopRecording();
306  * print("Audio recording finished.");
307  * }, 10000);
308  *
309  * } else {
310  * print("Could not make an audio recording file.");
311  * }
312  */
313  Q_INVOKABLE QUuid startRecording();
314 
315  /*@jsdoc
316  * Finishes making an audio recording started with {@link Audio.startRecording|startRecording}.
317  * @function Audio.stopRecording
318  */
319  Q_INVOKABLE void stopRecording();
320 
321  /*@jsdoc
322  * Checks whether an audio recording is currently being made.
323  * @function Audio.getRecording
324  * @returns {boolean} <code>true</code> if an audio recording is currently being made, otherwise <code>false</code>.
325  */
326  Q_INVOKABLE bool getRecording();
327 
328  /*@jsdoc
329  * Sets the output volume gain that will be used when the user is holding the push-to-talk key.
330  * Should be negative.
331  * @function Audio.setPushingToTalkOutputGainDesktop
332  * @param {number} gain - The output volume gain (dB) while using push-to-talk.
333  */
334  Q_INVOKABLE void setPushingToTalkOutputGainDesktop(float gain);
335 
336  /*@jsdoc
337  * Gets the output volume gain that is used when the user is holding the push-to-talk key.
338  * Should be negative.
339  * @function Audio.getPushingToTalkOutputGainDesktop
340  * @returns {number} gain - The output volume gain (dB) while using push-to-talk.
341  */
342  Q_INVOKABLE float getPushingToTalkOutputGainDesktop();
343 
344 signals:
345 
346  /*@jsdoc
347  * @function Audio.nop
348  * @returns {Signal}
349  * @deprecated This signal is deprecated and will be removed.
350  */
351  void nop();
352 
353  /*@jsdoc
354  * Triggered when the audio input is muted or unmuted for the current context (desktop or HMD).
355  * @function Audio.mutedChanged
356  * @param {boolean} isMuted - <code>true</code> if the audio input is muted for the current context (desktop or HMD),
357  * otherwise <code>false</code>.
358  * @returns {Signal}
359  * @example <caption>Report when audio input is muted or unmuted</caption>
360  * Audio.mutedChanged.connect(function (isMuted) {
361  * print("Audio muted: " + isMuted);
362  * });
363  */
364  void mutedChanged(bool isMuted);
365 
366  /*@jsdoc
367  * Triggered when desktop audio input is muted or unmuted.
368  * @function Audio.mutedDesektopChanged
369  * @param {boolean} isMuted - <code>true</code> if desktop audio input is muted, otherwise <code>false</code>.
370  * @returns {Signal}
371  * @example <caption>Report when desktop muting changes.</caption>
372  * Audio.mutedDesktopChanged.connect(function (isMuted) {
373  * print("Desktop muted: " + isMuted);
374  * });
375  */
376  void mutedDesktopChanged(bool isMuted);
377 
378  /*@jsdoc
379  * Triggered when HMD audio input is muted or unmuted.
380  * @function Audio.mutedHMDChanged
381  * @param {boolean} isMuted - <code>true</code> if HMD audio input is muted, otherwise <code>false</code>.
382  * @returns {Signal}
383  */
384  void mutedHMDChanged(bool isMuted);
385 
386  /*@jsdoc
387  * Triggered when push-to-talk is enabled or disabled for the current context (desktop or HMD).
388  * @function Audio.pushToTalkChanged
389  * @param {boolean} enabled - <code>true</code> if push-to-talk is enabled, otherwise <code>false</code>.
390  * @returns {Signal}
391  * @example <caption>Report when push-to-talk changes.</caption>
392  * Audio.pushToTalkChanged.connect(function (enabled) {
393  * print("Push to talk: " + (enabled ? "on" : "off"));
394  * });
395  */
396  void pushToTalkChanged(bool enabled);
397 
398  /*@jsdoc
399  * Triggered when push-to-talk is enabled or disabled for desktop mode.
400  * @function Audio.pushToTalkDesktopChanged
401  * @param {boolean} enabled - <code>true</code> if push-to-talk is enabled for desktop mode, otherwise <code>false</code>.
402  * @returns {Signal}
403  */
404  void pushToTalkDesktopChanged(bool enabled);
405 
406  /*@jsdoc
407  * Triggered when push-to-talk is enabled or disabled for HMD mode.
408  * @function Audio.pushToTalkHMDChanged
409  * @param {boolean} enabled - <code>true</code> if push-to-talk is enabled for HMD mode, otherwise <code>false</code>.
410  * @returns {Signal}
411  */
412  void pushToTalkHMDChanged(bool enabled);
413 
414  /*@jsdoc
415  * Triggered when audio input noise reduction is enabled or disabled.
416  * @function Audio.noiseReductionChanged
417  * @param {boolean} isEnabled - <code>true</code> if audio input noise reduction is enabled, otherwise <code>false</code>.
418  * @returns {Signal}
419  */
420  void noiseReductionChanged(bool isEnabled);
421 
422  /*@jsdoc
423  * Triggered when the audio input noise reduction mode is changed.
424  * @function Audio.noiseReductionAutomaticChanged
425  * @param {boolean} isEnabled - <code>true</code> if audio input noise reduction automatic mode is enabled, <code>false</code> if in manual mode.
426  * @returns {Signal}
427  */
428  void noiseReductionAutomaticChanged(bool isEnabled);
429 
430  /*@jsdoc
431  * Triggered when the audio input noise reduction threshold is changed.
432  * @function Audio.noiseReductionThresholdChanged
433  * @param {number} threshold - The threshold for the audio input noise reduction, range <code>0.0</code> (open the gate completely) &ndash; <code>1.0</code>
434  * (close the gate completely).
435  * @returns {Signal}
436  */
437  void noiseReductionThresholdChanged(float threshold);
438 
439  /*@jsdoc
440  * Triggered when "warn when muted" is enabled or disabled.
441  * @function Audio.warnWhenMutedChanged
442  * @param {boolean} isEnabled - <code>true</code> if "warn when muted" is enabled, otherwise <code>false</code>.
443  * @returns {Signal}
444  */
445  void warnWhenMutedChanged(bool isEnabled);
446 
447  /*@jsdoc
448  * Triggered when acoustic echo cancellation is enabled or disabled.
449  * @function Audio.acousticEchoCancellationChanged
450  * @param {boolean} isEnabled - <code>true</code> if acoustic echo cancellation is enabled, otherwise <code>false</code>.
451  * @returns {Signal}
452  */
453  void acousticEchoCancellationChanged(bool isEnabled);
454 
455  /*@jsdoc
456  * Triggered when the input audio volume changes.
457  * @function Audio.inputVolumeChanged
458  * @param {number} volume - The requested volume to be applied to the audio input, range <code>0.0</code> &ndash;
459  * <code>1.0</code>. The resulting value of <code>Audio.inputVolume</code> depends on the capabilities of the device.
460  * For example, the volume can't be changed on some devices, while others might only support values of <code>0.0</code>
461  * and <code>1.0</code>.
462  * @returns {Signal}
463  */
464  void inputVolumeChanged(float volume);
465 
466  /*@jsdoc
467  * Triggered when the input audio level changes.
468  * @function Audio.inputLevelChanged
469  * @param {number} level - The loudness of the input audio, range <code>0.0</code> (no sound) &ndash; <code>1.0</code> (the
470  * onset of clipping).
471  * @returns {Signal}
472  */
473  void inputLevelChanged(float level);
474 
475  /*@jsdoc
476  * Triggered when the clipping state of the input audio changes.
477  * @function Audio.clippingChanged
478  * @param {boolean} isClipping - <code>true</code> if the audio input is clipping, otherwise <code>false</code>.
479  * @returns {Signal}
480  */
481  void clippingChanged(bool isClipping);
482 
483  /*@jsdoc
484  * Triggered when the current context of the audio changes.
485  * @function Audio.contextChanged
486  * @param {string} context - The current context of the audio: either <code>"Desktop"</code> or <code>"HMD"</code>.
487  * @returns {Signal}
488  */
489  void contextChanged(const QString& context);
490 
491  /*@jsdoc
492  * Triggered when the user starts or stops push-to-talk.
493  * @function Audio.pushingToTalkChanged
494  * @param {boolean} talking - <code>true</code> if started push-to-talk, <code>false</code> if stopped push-to-talk.
495  * @returns {Signal}
496  */
497  void pushingToTalkChanged(bool talking);
498 
499  /*@jsdoc
500  * Triggered when the avatar gain changes.
501  * @function Audio.avatarGainChanged
502  * @param {number} gain - The new avatar gain value (dB).
503  * @returns {Signal}
504  */
505  void avatarGainChanged(float gain);
506 
507  /*@jsdoc
508  * Triggered when the local injector gain changes.
509  * @function Audio.localInjectorGainChanged
510  * @param {number} gain - The new local injector gain value (dB).
511  * @returns {Signal}
512  */
513  void localInjectorGainChanged(float gain);
514 
515  /*@jsdoc
516  * Triggered when the server injector gain changes.
517  * @function Audio.serverInjectorGainChanged
518  * @param {number} gain - The new server injector gain value (dB).
519  * @returns {Signal}
520  */
521  void serverInjectorGainChanged(float gain);
522 
523  /*@jsdoc
524  * Triggered when the system injector gain changes.
525  * @function Audio.systemInjectorGainChanged
526  * @param {number} gain - The new system injector gain value (dB).
527  * @returns {Signal}
528  */
529  void systemInjectorGainChanged(float gain);
530 
531  /*@jsdoc
532  * Triggered when the push to talk gain changes.
533  * @function Audio.pushingToTalkOutputGainDesktopChanged
534  * @param {number} gain - The new output gain value (dB).
535  * @returns {Signal}
536  */
537  void pushingToTalkOutputGainDesktopChanged(float gain);
538 
539 public slots:
540 
541  /*@jsdoc
542  * @function Audio.onContextChanged
543  * @deprecated This function is deprecated and will be removed.
544  */
545  void onContextChanged();
546 
547  void handlePushedToTalk(bool enabled);
548 
549 private slots:
550  void setMuted(bool muted);
551  void enableNoiseReduction(bool enable);
552  void enableNoiseReductionAutomatic(bool enable);
553  void enableWarnWhenMuted(bool enable);
554  void enableAcousticEchoCancellation(bool enable);
555  void setInputVolume(float volume);
556  void onInputLoudnessChanged(float loudness, bool isClipping);
557 
558 protected:
559  // Audio must live on a separate thread from AudioClient to avoid deadlocks
560  Audio();
561 
562 private:
563 
564  bool _settingsLoaded { false };
565  float _inputVolume { 1.0f };
566  float _inputLevel { 0.0f };
567  Setting::Handle<float> _avatarGainSetting { QStringList { Audio::AUDIO, "AvatarGain" }, 0.0f };
568  Setting::Handle<float> _injectorGainSetting { QStringList { Audio::AUDIO, "InjectorGain" }, 0.0f };
569  Setting::Handle<float> _localInjectorGainSetting { QStringList { Audio::AUDIO, "LocalInjectorGain" }, 0.0f };
570  Setting::Handle<float> _systemInjectorGainSetting { QStringList { Audio::AUDIO, "SystemInjectorGain" }, 0.0f };
571  float _localInjectorGain { 0.0f }; // in dB
572  float _systemInjectorGain { 0.0f }; // in dB
573  float _pttOutputGainDesktop { 0.0f }; // in dB
574  float _noiseReductionThreshold { 0.1f }; // Match default value of AudioClient::_noiseReductionThreshold.
575  bool _isClipping { false };
576  bool _enableNoiseReduction { true }; // Match default value of AudioClient::_isNoiseGateEnabled.
577  bool _noiseReductionAutomatic { true }; // Match default value of AudioClient::_noiseReductionAutomatic.
578  bool _enableWarnWhenMuted { true };
579  bool _enableAcousticEchoCancellation { true }; // AudioClient::_isAECEnabled
580  bool _contextIsHMD { false };
581  AudioDevices* getDevices() { return &_devices; }
582  AudioDevices _devices;
583  Setting::Handle<bool> _mutedDesktopSetting{ QStringList { Audio::AUDIO, "mutedDesktop" }, true };
584  Setting::Handle<bool> _mutedHMDSetting{ QStringList { Audio::AUDIO, "mutedHMD" }, true };
585  Setting::Handle<bool> _pttDesktopSetting{ QStringList { Audio::AUDIO, "pushToTalkDesktop" }, false };
586  Setting::Handle<bool> _pttHMDSetting{ QStringList { Audio::AUDIO, "pushToTalkHMD" }, false };
587  bool _mutedDesktop{ true };
588  bool _mutedHMD{ false };
589  bool _pttDesktop{ false };
590  bool _pttHMD{ false };
591  bool _pushingToTalk{ false };
592 };
593 
594 };
595 
596 #endif // hifi_scripting_Audio_h