From 15f32693388f2201118912f03439728fc337d4f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 18 Jul 2021 00:07:05 +0200 Subject: [PATCH 1/2] Implement the option for auto audio devices switching for Windows too (previously SDL-only) --- UI/GameSettingsScreen.cpp | 8 ++++++-- Windows/WASAPIStream.cpp | 4 ++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index ba5851c96d..a4f69ffd1f 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -634,16 +634,20 @@ void GameSettingsScreen::CreateViews() { MicChoice->OnChoice.Handle(this, &GameSettingsScreen::OnMicDeviceChange); } + bool sdlAudio = false; #if defined(SDL) std::vector audioDeviceList; SplitString(System_GetProperty(SYSPROP_AUDIO_DEVICE_LIST), '\0', audioDeviceList); audioDeviceList.insert(audioDeviceList.begin(), a->T("Auto")); PopupMultiChoiceDynamic *audioDevice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sAudioDevice, a->T("Device"), audioDeviceList, nullptr, screenManager())); audioDevice->OnChoice.Handle(this, &GameSettingsScreen::OnAudioDevice); - - audioSettings->Add(new CheckBox(&g_Config.bAutoAudioDevice, a->T("Switch on new audio device"))); + sdlAudio = true; #endif + if (sdlAudio || g_Config.iAudioBackend == AUDIO_BACKEND_WASAPI) { + audioSettings->Add(new CheckBox(&g_Config.bAutoAudioDevice, a->T("Use new audio devices automatically"))); + } + #if defined(__ANDROID__) CheckBox *extraAudio = audioSettings->Add(new CheckBox(&g_Config.bExtraAudioBuffering, a->T("AudioBufferingForBluetooth", "Bluetooth-friendly buffer (slower)"))); extraAudio->SetEnabledPtr(&g_Config.bEnableSound); diff --git a/Windows/WASAPIStream.cpp b/Windows/WASAPIStream.cpp index 3a7b6565b2..f88b6c10e9 100644 --- a/Windows/WASAPIStream.cpp +++ b/Windows/WASAPIStream.cpp @@ -59,7 +59,7 @@ public: deviceChanged_ = false; } - bool HasDeviceChanged() { + bool HasDefaultDeviceChanged() const { return deviceChanged_; } @@ -529,7 +529,7 @@ void WASAPIAudioThread::Run() { } // Check if we should use a new device. - if (notificationClient_ && notificationClient_->HasDeviceChanged()) { + if (notificationClient_ && notificationClient_->HasDefaultDeviceChanged() && g_Config.bAutoAudioDevice) { hresult = audioInterface_->Stop(); ShutdownAudioDevice(); From 254c25692b290151c5f4248b0d0667058f41cc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 18 Jul 2021 00:09:01 +0200 Subject: [PATCH 2/2] Audio settings: Move microphone list to the bottom. --- UI/GameSettingsScreen.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index a4f69ffd1f..996638b294 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -627,13 +627,6 @@ void GameSettingsScreen::CreateViews() { } #endif - std::vector micList = Microphone::getDeviceList(); - if (!micList.empty()) { - audioSettings->Add(new ItemHeader(a->T("Microphone"))); - PopupMultiChoiceDynamic *MicChoice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sMicDevice, a->T("Microphone Device"), micList, nullptr, screenManager())); - MicChoice->OnChoice.Handle(this, &GameSettingsScreen::OnMicDeviceChange); - } - bool sdlAudio = false; #if defined(SDL) std::vector audioDeviceList; @@ -659,6 +652,13 @@ void GameSettingsScreen::CreateViews() { } #endif + std::vector micList = Microphone::getDeviceList(); + if (!micList.empty()) { + audioSettings->Add(new ItemHeader(a->T("Microphone"))); + PopupMultiChoiceDynamic *MicChoice = audioSettings->Add(new PopupMultiChoiceDynamic(&g_Config.sMicDevice, a->T("Microphone Device"), micList, nullptr, screenManager())); + MicChoice->OnChoice.Handle(this, &GameSettingsScreen::OnMicDeviceChange); + } + // Control ViewGroup *controlsSettingsScroll = new ScrollView(ORIENT_VERTICAL, new LinearLayoutParams(FILL_PARENT, FILL_PARENT)); controlsSettingsScroll->SetTag("GameSettingsControls");