12 #ifndef hifi_scripting_Audio_h
13 #define hifi_scripting_Audio_h
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>
24 using MutedGetter = std::function<bool()>;
25 using MutedSetter = std::function<void(
bool)>;
27 #define OVERTE_AUDIO_STRING "Audio"
28 #define OVERTE_AUDIO_HMD_STRING "VR"
29 #define OVERTE_AUDIO_DESKTOP_STRING "Desktop"
33 class Audio :
public AudioScriptingInterface,
protected ReadWriteLockable {
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)
128 static QString AUDIO;
130 static QString DESKTOP;
132 static float loudnessToLevel(
float loudness);
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;
146 void showMicMeter(
bool show);
149 void setMutedDesktop(
bool isMuted);
150 bool getMutedDesktop()
const;
151 void setMutedHMD(
bool isMuted);
152 bool getMutedHMD()
const;
153 void setPTT(
bool enabled);
155 void setPushingToTalk(
bool pushingToTalk);
156 bool getPushingToTalk()
const;
159 void setPTTDesktop(
bool enabled);
160 bool getPTTDesktop()
const;
161 void setPTTHMD(
bool enabled);
162 bool getPTTHMD()
const;
174 Q_INVOKABLE
void setInputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
182 Q_INVOKABLE
void setOutputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
215 Q_INVOKABLE
void setReverb(
bool enable);
222 Q_INVOKABLE
void setReverbOptions(
const AudioEffectOptions options);
229 Q_INVOKABLE
void setAvatarGain(
float gain);
242 Q_INVOKABLE
float getAvatarGain();
249 Q_INVOKABLE
void setInjectorGain(
float gain);
256 Q_INVOKABLE
float getInjectorGain();
263 Q_INVOKABLE
void setLocalInjectorGain(
float gain);
270 Q_INVOKABLE
float getLocalInjectorGain();
277 Q_INVOKABLE
void setSystemInjectorGain(
float gain);
284 Q_INVOKABLE
float getSystemInjectorGain();
291 Q_INVOKABLE
void setNoiseReductionThreshold(
float threshold);
298 Q_INVOKABLE
float getNoiseReductionThreshold();
317 Q_INVOKABLE QUuid startRecording();
323 Q_INVOKABLE
void stopRecording();
330 Q_INVOKABLE
bool getRecording();
338 Q_INVOKABLE
void setPushingToTalkOutputGainDesktop(
float gain);
346 Q_INVOKABLE
float getPushingToTalkOutputGainDesktop();
368 void mutedChanged(
bool isMuted);
380 void mutedDesktopChanged(
bool isMuted);
388 void mutedHMDChanged(
bool isMuted);
400 void pushToTalkChanged(
bool enabled);
408 void pushToTalkDesktopChanged(
bool enabled);
416 void pushToTalkHMDChanged(
bool enabled);
424 void noiseReductionChanged(
bool isEnabled);
432 void noiseReductionAutomaticChanged(
bool isEnabled);
441 void noiseReductionThresholdChanged(
float threshold);
449 void warnWhenMutedChanged(
bool isEnabled);
457 void acousticEchoCancellationChanged(
bool isEnabled);
468 void inputVolumeChanged(
float volume);
477 void inputLevelChanged(
float level);
485 void clippingChanged(
bool isClipping);
493 void contextChanged(
const QString& context);
501 void pushingToTalkChanged(
bool talking);
509 void avatarGainChanged(
float gain);
517 void localInjectorGainChanged(
float gain);
525 void serverInjectorGainChanged(
float gain);
533 void systemInjectorGainChanged(
float gain);
541 void pushingToTalkOutputGainDesktopChanged(
float gain);
549 void onContextChanged();
551 void handlePushedToTalk(
bool enabled);
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);
568 bool _settingsLoaded {
false };
569 float _inputVolume { 1.0f };
570 float _inputLevel { 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 };
576 float _systemInjectorGain { 0.0f };
577 float _pttOutputGainDesktop { 0.0f };
578 float _noiseReductionThreshold { 0.1f };
579 bool _isClipping {
false };
580 bool _enableNoiseReduction {
true };
581 bool _noiseReductionAutomatic {
true };
582 bool _enableWarnWhenMuted {
true };
583 bool _enableAcousticEchoCancellation {
true };
584 bool _contextIsHMD {
false };
585 AudioDevices* getDevices() {
return &_devices; }
586 AudioDevices _devices;
589 Setting::Handle<bool> _pttDesktopSetting{ QStringList { Audio::AUDIO,
"pushToTalkDesktop" },
false };
591 bool _mutedDesktop{
false };
592 bool _mutedHMD{
false };
593 bool _pttDesktop{
false };
594 bool _pttHMD{
false };
595 bool _pushingToTalk{
false };