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)>;
29 class Audio :
public AudioScriptingInterface,
protected ReadWriteLockable {
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)
124 static QString AUDIO;
126 static QString DESKTOP;
128 static float loudnessToLevel(
float loudness);
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;
142 void showMicMeter(
bool show);
145 void setMutedDesktop(
bool isMuted);
146 bool getMutedDesktop()
const;
147 void setMutedHMD(
bool isMuted);
148 bool getMutedHMD()
const;
149 void setPTT(
bool enabled);
151 void setPushingToTalk(
bool pushingToTalk);
152 bool getPushingToTalk()
const;
155 void setPTTDesktop(
bool enabled);
156 bool getPTTDesktop()
const;
157 void setPTTHMD(
bool enabled);
158 bool getPTTHMD()
const;
170 Q_INVOKABLE
void setInputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
178 Q_INVOKABLE
void setOutputDevice(
const HifiAudioDeviceInfo& device,
bool isHMD);
211 Q_INVOKABLE
void setReverb(
bool enable);
218 Q_INVOKABLE
void setReverbOptions(
const AudioEffectOptions options);
225 Q_INVOKABLE
void setAvatarGain(
float gain);
238 Q_INVOKABLE
float getAvatarGain();
245 Q_INVOKABLE
void setInjectorGain(
float gain);
252 Q_INVOKABLE
float getInjectorGain();
259 Q_INVOKABLE
void setLocalInjectorGain(
float gain);
266 Q_INVOKABLE
float getLocalInjectorGain();
273 Q_INVOKABLE
void setSystemInjectorGain(
float gain);
280 Q_INVOKABLE
float getSystemInjectorGain();
287 Q_INVOKABLE
void setNoiseReductionThreshold(
float threshold);
294 Q_INVOKABLE
float getNoiseReductionThreshold();
313 Q_INVOKABLE QUuid startRecording();
319 Q_INVOKABLE
void stopRecording();
326 Q_INVOKABLE
bool getRecording();
334 Q_INVOKABLE
void setPushingToTalkOutputGainDesktop(
float gain);
342 Q_INVOKABLE
float getPushingToTalkOutputGainDesktop();
364 void mutedChanged(
bool isMuted);
376 void mutedDesktopChanged(
bool isMuted);
384 void mutedHMDChanged(
bool isMuted);
396 void pushToTalkChanged(
bool enabled);
404 void pushToTalkDesktopChanged(
bool enabled);
412 void pushToTalkHMDChanged(
bool enabled);
420 void noiseReductionChanged(
bool isEnabled);
428 void noiseReductionAutomaticChanged(
bool isEnabled);
437 void noiseReductionThresholdChanged(
float threshold);
445 void warnWhenMutedChanged(
bool isEnabled);
453 void acousticEchoCancellationChanged(
bool isEnabled);
464 void inputVolumeChanged(
float volume);
473 void inputLevelChanged(
float level);
481 void clippingChanged(
bool isClipping);
489 void contextChanged(
const QString& context);
497 void pushingToTalkChanged(
bool talking);
505 void avatarGainChanged(
float gain);
513 void localInjectorGainChanged(
float gain);
521 void serverInjectorGainChanged(
float gain);
529 void systemInjectorGainChanged(
float gain);
537 void pushingToTalkOutputGainDesktopChanged(
float gain);
545 void onContextChanged();
547 void handlePushedToTalk(
bool enabled);
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);
564 bool _settingsLoaded {
false };
565 float _inputVolume { 1.0f };
566 float _inputLevel { 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 };
572 float _systemInjectorGain { 0.0f };
573 float _pttOutputGainDesktop { 0.0f };
574 float _noiseReductionThreshold { 0.1f };
575 bool _isClipping {
false };
576 bool _enableNoiseReduction {
true };
577 bool _noiseReductionAutomatic {
true };
578 bool _enableWarnWhenMuted {
true };
579 bool _enableAcousticEchoCancellation {
true };
580 bool _contextIsHMD {
false };
581 AudioDevices* getDevices() {
return &_devices; }
582 AudioDevices _devices;
585 Setting::Handle<bool> _pttDesktopSetting{ QStringList { Audio::AUDIO,
"pushToTalkDesktop" },
false };
587 bool _mutedDesktop{
true };
588 bool _mutedHMD{
false };
589 bool _pttDesktop{
false };
590 bool _pttHMD{
false };
591 bool _pushingToTalk{
false };