From d4f4b3c3045a88512a1bef7637ea3e0629b9e8b1 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Wed, 8 Jan 2025 07:34:15 +0300 Subject: [PATCH 1/2] Fix default audio device switch for PulseAudio backend (#7731) --- apps/openmw/mwsound/openal_output.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index 3c3d6fb26e..aa68997d0e 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -417,19 +417,15 @@ namespace MWSound { { const std::lock_guard openLock(mOutput.mReopenMutex); - auto defaultName = getDeviceName(nullptr); + std::basic_string_view defaultName = getDeviceName(nullptr); if (mCurrentName != defaultName) { Log(Debug::Info) << "Default audio device changed"; - ALCboolean reopened - = alcReopenDeviceSOFT(mOutput.mDevice, nullptr, mOutput.mContextAttributes.data()); + ALCboolean reopened = alcReopenDeviceSOFT( + mOutput.mDevice, defaultName.data(), mOutput.mContextAttributes.data()); if (reopened == AL_FALSE) - { - mCurrentName = defaultName; Log(Debug::Warning) << "Failed to switch to new audio device"; - } - else - mCurrentName = getDeviceName(mOutput.mDevice); + mCurrentName = defaultName; } } mCondVar.wait_for(lock, std::chrono::seconds(2)); From dd44b2668c02de1f65044edd042a8c3bdab83365 Mon Sep 17 00:00:00 2001 From: Alexei Kotov Date: Thu, 9 Jan 2025 03:31:09 +0300 Subject: [PATCH 2/2] Be prepared if someone feels like breaking getDeviceName --- apps/openmw/mwsound/openal_output.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/openmw/mwsound/openal_output.cpp b/apps/openmw/mwsound/openal_output.cpp index aa68997d0e..f829ea458a 100644 --- a/apps/openmw/mwsound/openal_output.cpp +++ b/apps/openmw/mwsound/openal_output.cpp @@ -420,12 +420,12 @@ namespace MWSound std::basic_string_view defaultName = getDeviceName(nullptr); if (mCurrentName != defaultName) { - Log(Debug::Info) << "Default audio device changed"; + mCurrentName = defaultName; + Log(Debug::Info) << "Default audio device changed to \"" << mCurrentName << "\""; ALCboolean reopened = alcReopenDeviceSOFT( - mOutput.mDevice, defaultName.data(), mOutput.mContextAttributes.data()); + mOutput.mDevice, mCurrentName.data(), mOutput.mContextAttributes.data()); if (reopened == AL_FALSE) Log(Debug::Warning) << "Failed to switch to new audio device"; - mCurrentName = defaultName; } } mCondVar.wait_for(lock, std::chrono::seconds(2));