From bf3a02fe9bdd120611052cc706fa0667e4a37c56 Mon Sep 17 00:00:00 2001 From: mjbudd77 Date: Tue, 31 Aug 2021 17:18:46 -0400 Subject: [PATCH] Implemented sound use global focus in a different way so that it will mute physical audio without also muting avi/wav recording audio. --- src/drivers/Qt/ConsoleWindow.cpp | 8 ++------ src/drivers/Qt/dface.h | 1 + src/drivers/Qt/sdl-sound.cpp | 13 +++++++++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index 11ca2388..3a2fada0 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -423,18 +423,14 @@ void consoleWin_t::winActiveChanged(void) { if ( !soundUseGlobalFocus ) { - fceuWrapperLock(); if ( hdl->isActive() ) { - int vol; - g_config->getOption("SDL.Sound.Volume", &vol); - FCEUI_SetSoundVolume(vol); + FCEUD_MuteSoundOutput(false); } else { - FCEUI_SetSoundVolume(0); + FCEUD_MuteSoundOutput(true); } - fceuWrapperUnLock(); } } } diff --git a/src/drivers/Qt/dface.h b/src/drivers/Qt/dface.h index f33e146f..1459ddc8 100644 --- a/src/drivers/Qt/dface.h +++ b/src/drivers/Qt/dface.h @@ -13,6 +13,7 @@ void WriteSound(int32 *Buffer, int Count); int KillSound(void); uint32 GetMaxSound(void); uint32 GetWriteSound(void); +void FCEUD_MuteSoundOutput(bool value); void SilenceSound(int s); /* DOS and SDL */ diff --git a/src/drivers/Qt/sdl-sound.cpp b/src/drivers/Qt/sdl-sound.cpp index 9665d002..b2056164 100644 --- a/src/drivers/Qt/sdl-sound.cpp +++ b/src/drivers/Qt/sdl-sound.cpp @@ -46,6 +46,7 @@ static unsigned int s_SampleRate = 44100; static double noiseGate = 0.0; static double noiseGateRate = 0.010; static bool noiseGateActive = true; +static bool muteSoundOutput = false; static int s_mute = 0; @@ -63,17 +64,20 @@ fillaudio(void *udata, { char bufStarveDetected = 0; static int16_t sample = 0; + char mute; //unsigned int starve_lp = nes_shm->sndBuf.starveCounter; int16 *tmps = (int16*)stream; len >>= 1; - if ( EmulationPaused || noiseGateActive ) + mute = EmulationPaused || muteSoundOutput; + + if ( mute || noiseGateActive ) { // This noise gate helps avoid abrupt snaps in audio // when pausing emulation. while (len) { - if (EmulationPaused) + if (mute) { noiseGate -= noiseGateRate; @@ -506,3 +510,8 @@ FCEUD_SoundToggle(void) FCEU_DispMessage("Sound mute on.",0); } } + +void FCEUD_MuteSoundOutput( bool value ) +{ + muteSoundOutput = value; +}