From 1f068c59001407c200650fb13881ca534f5b38e8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 29 Mar 2026 20:44:29 -0400 Subject: [PATCH] fix audio stuck muted after minimize Two fixes: - unmute on window refocus event - force Miles audio engine reset with system settings (no change) after we come back from being minimized --- .../Source/Win32Device/Common/Win32GameEngine.cpp | 8 ++++++-- Generals/Code/Main/WinMain.cpp | 10 +++++++--- .../Source/Win32Device/Common/Win32GameEngine.cpp | 8 ++++---- GeneralsMD/Code/Main/WinMain.cpp | 4 ++++ 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp index 9c1850bc2a9..42a932f0fb6 100644 --- a/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp +++ b/Generals/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp @@ -85,8 +85,6 @@ void Win32GameEngine::reset() //------------------------------------------------------------------------------------------------- void Win32GameEngine::update() { - - // call the engine normal update GameEngine::update(); @@ -112,6 +110,12 @@ void Win32GameEngine::update() break; // keep running. } } + + // The MilesAudioManager seems to go into a coma sometimes when the window is minimized + // and not regain focus properly when we come back. We're going to force it to wake up after we come back from being minimized. + AudioAffect aa = (AudioAffect)0x10; // AudioAffect_SystemSetting: forces m_volumeHasChanged without changing channel volumes + if (TheAudio) + TheAudio->setVolume(TheAudio->getVolume(aa), aa); } // allow windows to perform regular windows maintenance stuff like msgs diff --git a/Generals/Code/Main/WinMain.cpp b/Generals/Code/Main/WinMain.cpp index 3882edb212f..f6dc2b39399 100644 --- a/Generals/Code/Main/WinMain.cpp +++ b/Generals/Code/Main/WinMain.cpp @@ -451,6 +451,9 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, //restore mouse cursor to our custom version. if (TheWin32Mouse) TheWin32Mouse->setCursor(TheWin32Mouse->getMouseCursor()); + + if (TheAudio) + TheAudio->unmuteAudio(AudioManager::MuteAudioReason_WindowFocus); } } return 0; @@ -468,12 +471,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message, } else { - if (TheAudio) - TheAudio->unmuteAudio(AudioManager::MuteAudioReason_WindowFocus); - // Cursor can only be captured after one of the activation events. if (TheMouse) TheMouse->refreshCursorCapture(); + + // Unmute audio when the window is activated. + if (TheAudio) + TheAudio->unmuteAudio(AudioManager::MuteAudioReason_WindowFocus); } break; } diff --git a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp index acf52caa121..7ce6b6c267a 100644 --- a/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp +++ b/GeneralsMD/Code/GameEngineDevice/Source/Win32Device/Common/Win32GameEngine.cpp @@ -119,10 +119,10 @@ void Win32GameEngine::update() } } - // When we are alt-tabbed out... the MilesAudioManager seems to go into a coma sometimes - // and not regain focus properly when we come back. This seems to wake it up nicely. - AudioAffect aa = (AudioAffect)0x10; - TheAudio->setVolume(TheAudio->getVolume( aa ), aa ); + // When we are alt-tabbed out... the MilesAudioManager seems to go into a coma sometimes + // and not regain focus properly when we come back. This seems to wake it up nicely. + AudioAffect aa = (AudioAffect)0x10; + TheAudio->setVolume(TheAudio->getVolume( aa ), aa ); } diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp index b5bc5cd5f0b..40c20d9150f 100644 --- a/GeneralsMD/Code/Main/WinMain.cpp +++ b/GeneralsMD/Code/Main/WinMain.cpp @@ -474,6 +474,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, //restore mouse cursor to our custom version. if (TheWin32Mouse) TheWin32Mouse->setCursor(TheWin32Mouse->getMouseCursor()); + + // Unmute audio when the window is activated. + if (TheAudio) + TheAudio->unmuteAudio(AudioManager::MuteAudioReason_WindowFocus); } } return 0;