From b5dab39f83505d7cd763f666c67c776285fe5075 Mon Sep 17 00:00:00 2001 From: Zach Pomerantz Date: Mon, 12 Jun 2017 18:41:32 -0400 Subject: [PATCH] sticky mic meter / noise reduction --- interface/src/Application.cpp | 7 ++++--- interface/src/scripting/Audio.cpp | 20 ++++++++++++++------ interface/src/scripting/Audio.h | 27 ++++++++++++++------------- 3 files changed, 32 insertions(+), 22 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 297f44f87e..57f0409747 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -721,10 +721,12 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo } }); - auto audioScriptingInterface = DependencyManager::set(); connect(audioThread, &QThread::started, audioIO.data(), &AudioClient::start); connect(audioIO.data(), &AudioClient::destroyed, audioThread, &QThread::quit); connect(audioThread, &QThread::finished, audioThread, &QThread::deleteLater); + audioThread->start(); + + auto audioScriptingInterface = DependencyManager::set(); connect(audioIO.data(), &AudioClient::mutedByMixer, audioScriptingInterface.data(), &AudioScriptingInterface::mutedByMixer); connect(audioIO.data(), &AudioClient::receivedFirstPacket, audioScriptingInterface.data(), &AudioScriptingInterface::receivedFirstPacket); connect(audioIO.data(), &AudioClient::disconnected, audioScriptingInterface.data(), &AudioScriptingInterface::disconnected); @@ -743,8 +745,6 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo connect(this, &Application::activeDisplayPluginChanged, reinterpret_cast(audioScriptingInterface.data()), &scripting::Audio::onChangedContext); - audioThread->start(); - ResourceManager::init(); // Make sure we don't time out during slow operations at startup updateHeartbeat(); @@ -1932,6 +1932,7 @@ void Application::initializeUi() { auto audio = reinterpret_cast(DependencyManager::get().data()); connect(ai, &AvatarInputs::showAudioToolsChanged, audio, &scripting::Audio::onChangedMicMeter); connect(audio, &scripting::Audio::changedMicMeter, ai, &AvatarInputs::setShowAudioTools); + ai->setShowAudioTools(audio->micMeterShown()); } if (auto steamClient = PluginManager::getInstance()->getSteamClientPlugin()) { diff --git a/interface/src/scripting/Audio.cpp b/interface/src/scripting/Audio.cpp index de2eda76da..0830899356 100644 --- a/interface/src/scripting/Audio.cpp +++ b/interface/src/scripting/Audio.cpp @@ -20,14 +20,18 @@ using namespace scripting; static const QString DESKTOP_CONTEXT { "Desktop" }; static const QString HMD_CONTEXT { "VR" }; +static const QString AUDIO { "Audio" }; +Setting::Handle enableNoiseReductionSetting { QStringList(AUDIO) << "NoiseReduction", true }; +Setting::Handle showMicMeterSetting { QStringList(AUDIO) << "MicMeter", false }; + Audio::Audio() { auto client = DependencyManager::get(); connect(client.data(), &AudioClient::muteToggled, this, &Audio::onChangedMuted); connect(&_devices._inputs, &AudioDeviceList::deviceChanged, this, &Audio::onInputChanged); - // TODO: make noise reduction sticky - // TODO: make mic meter sticky (need to reinitialize in AvatarInputs) + enableNoiseReduction(enableNoiseReductionSetting.get()); + _showMicMeter = showMicMeterSetting.get(); } void Audio::setReverb(bool enable) { @@ -73,11 +77,14 @@ void Audio::setMuted(bool isMuted) { } void Audio::enableNoiseReduction(bool enable) { - auto client = DependencyManager::get().data(); - QMetaObject::invokeMethod(client, "setNoiseReduction", Qt::BlockingQueuedConnection, Q_ARG(bool, enable)); + if (_enableNoiseReduction != enable) { + auto client = DependencyManager::get().data(); + QMetaObject::invokeMethod(client, "setNoiseReduction", Qt::BlockingQueuedConnection, Q_ARG(bool, enable)); - _enableNoiseReduction = enable; - emit changedNoiseReduction(enable); + enableNoiseReductionSetting.set(enable); + _enableNoiseReduction = enable; + emit changedNoiseReduction(enable); + } } void Audio::onChangedMicMeter(bool show) { @@ -86,6 +93,7 @@ void Audio::onChangedMicMeter(bool show) { void Audio::showMicMeter(bool show) { if (_showMicMeter != show) { + showMicMeterSetting.set(show); _showMicMeter = show; emit changedMicMeter(show); } diff --git a/interface/src/scripting/Audio.h b/interface/src/scripting/Audio.h index f05e2b616b..752880cc2f 100644 --- a/interface/src/scripting/Audio.h +++ b/interface/src/scripting/Audio.h @@ -15,6 +15,7 @@ #include "AudioScriptingInterface.h" #include "AudioDevices.h" #include "AudioEffectOptions.h" +#include "SettingHandle.h" namespace scripting { @@ -32,6 +33,17 @@ class Audio : public AudioScriptingInterface { public: virtual ~Audio() {} + bool isMuted() const { return _isMuted; } + bool noiseReductionEnabled() const { return _enableNoiseReduction; } + bool micMeterShown() const { return _showMicMeter; } + float getInputVolume() const { return _inputVolume; } + QString getContext() const; + + void setMuted(bool muted); + void enableNoiseReduction(bool enable); + void showMicMeter(bool show); + void setInputVolume(float volume); + Q_INVOKABLE void setReverb(bool enable); Q_INVOKABLE void setReverbOptions(const AudioEffectOptions* options); @@ -53,21 +65,10 @@ protected: Audio(); private: - bool isMuted() const { return _isMuted; } - bool noiseReductionEnabled() const { return _enableNoiseReduction; } - bool micMeterShown() const { return _showMicMeter; } - float getInputVolume() const { return _inputVolume; } - QString getContext() const; - - void setMuted(bool muted); - void enableNoiseReduction(bool enable); - void showMicMeter(bool show); - void setInputVolume(float volume); - float _inputVolume { 1.0f }; bool _isMuted { false }; - bool _enableNoiseReduction { true }; - bool _showMicMeter { false }; + bool _enableNoiseReduction; + bool _showMicMeter; bool _contextIsHMD { false }; AudioDevices* getDevices() { return &_devices; }