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