diff --git a/src/drivers/Qt/ConsoleSoundConf.cpp b/src/drivers/Qt/ConsoleSoundConf.cpp index 709ed3c7..93a71539 100644 --- a/src/drivers/Qt/ConsoleSoundConf.cpp +++ b/src/drivers/Qt/ConsoleSoundConf.cpp @@ -54,16 +54,21 @@ ConsoleSndConfDialog_t::ConsoleSndConfDialog_t(QWidget *parent) // Enable Sound Select enaChkbox = new QCheckBox(tr("Enable Sound")); + // Speaker Mute Select + muteChkbox = new QCheckBox(tr("Mute Speaker Output")); // Enable Low Pass Filter Select enaLowPass = new QCheckBox(tr("Enable Low Pass Filter")); setCheckBoxFromProperty(enaChkbox, "SDL.Sound"); + setCheckBoxFromProperty(muteChkbox, "SDL.Sound.Mute"); setCheckBoxFromProperty(enaLowPass, "SDL.Sound.LowPass"); connect(enaChkbox, SIGNAL(stateChanged(int)), this, SLOT(enaSoundStateChange(int))); + connect(muteChkbox, SIGNAL(stateChanged(int)), this, SLOT(enaSpeakerMuteChange(int))); connect(enaLowPass, SIGNAL(stateChanged(int)), this, SLOT(enaSoundLowPassChange(int))); vbox1->addWidget(enaChkbox); + vbox1->addWidget(muteChkbox); vbox1->addWidget(enaLowPass); // Audio Quality Select @@ -330,6 +335,11 @@ void ConsoleSndConfDialog_t::periodicUpdate(void) sprintf( stmp, "Sink Starve Count: %u", nes_shm->sndBuf.starveCounter ); starveLbl->setText( tr(stmp) ); + + if ( FCEUD_SoundIsMuted() != muteChkbox->isChecked() ) + { + muteChkbox->setChecked( FCEUD_SoundIsMuted() ); + } } //---------------------------------------------------- void ConsoleSndConfDialog_t::setSliderEnables(void) @@ -536,6 +546,11 @@ void ConsoleSndConfDialog_t::enaSoundStateChange(int value) } } //---------------------------------------------------- +void ConsoleSndConfDialog_t::enaSpeakerMuteChange(int value) +{ + FCEUD_MuteSoundOutput( value ? true : false ); +} +//---------------------------------------------------- void ConsoleSndConfDialog_t::enaSoundLowPassChange(int value) { if (value) diff --git a/src/drivers/Qt/ConsoleSoundConf.h b/src/drivers/Qt/ConsoleSoundConf.h index 2f8cf6b2..b637c08f 100644 --- a/src/drivers/Qt/ConsoleSoundConf.h +++ b/src/drivers/Qt/ConsoleSoundConf.h @@ -31,6 +31,7 @@ protected: int sndQuality; QCheckBox *enaChkbox; + QCheckBox *muteChkbox; QCheckBox *enaLowPass; QCheckBox *swapDutyChkbox; QCheckBox *useGlobalFocus; @@ -68,6 +69,7 @@ private slots: void noiseChanged(int value); void pcmChanged(int value); void enaSoundStateChange(int value); + void enaSpeakerMuteChange(int value); void enaSoundLowPassChange(int value); void swapDutyCallback(int value); void useGlobalFocusChanged(int value); diff --git a/src/drivers/Qt/ConsoleWindow.cpp b/src/drivers/Qt/ConsoleWindow.cpp index b4b92ead..cf0bf77e 100644 --- a/src/drivers/Qt/ConsoleWindow.cpp +++ b/src/drivers/Qt/ConsoleWindow.cpp @@ -450,11 +450,11 @@ void consoleWin_t::winActiveChanged(void) { if ( hdl->isActive() ) { - FCEUD_MuteSoundOutput(false); + FCEUD_MuteSoundWindow(false); } else { - FCEUD_MuteSoundOutput(true); + FCEUD_MuteSoundWindow(true); } } } @@ -850,6 +850,7 @@ void consoleWin_t::initHotKeys(void) Hotkeys[HK_FRAME_ADVANCE].getShortcut()->setEnabled(false); Hotkeys[HK_TURBO ].getShortcut()->setEnabled(false); + connect( Hotkeys[ HK_VOLUME_MUTE ].getShortcut(), SIGNAL(activated()), this, SLOT(muteSoundVolume(void)) ); connect( Hotkeys[ HK_VOLUME_DOWN ].getShortcut(), SIGNAL(activated()), this, SLOT(decrSoundVolume(void)) ); connect( Hotkeys[ HK_VOLUME_UP ].getShortcut(), SIGNAL(activated()), this, SLOT(incrSoundVolume(void)) ); @@ -3704,6 +3705,13 @@ void consoleWin_t::setCustomAutoFire(void) } } +void consoleWin_t::muteSoundVolume(void) +{ + FCEU_WRAPPER_LOCK(); + FCEUD_SoundToggle(); + FCEU_WRAPPER_UNLOCK(); +} + void consoleWin_t::incrSoundVolume(void) { FCEU_WRAPPER_LOCK(); diff --git a/src/drivers/Qt/ConsoleWindow.h b/src/drivers/Qt/ConsoleWindow.h index 20460591..eda9fd34 100644 --- a/src/drivers/Qt/ConsoleWindow.h +++ b/src/drivers/Qt/ConsoleWindow.h @@ -405,6 +405,7 @@ class consoleWin_t : public QMainWindow void stopMovie(void); void playMovieFromBeginning(void); void setCustomAutoFire(void); + void muteSoundVolume(void); void incrSoundVolume(void); void decrSoundVolume(void); void toggleLagCounterDisplay(void); diff --git a/src/drivers/Qt/config.cpp b/src/drivers/Qt/config.cpp index 3f5490cf..6ac560c5 100644 --- a/src/drivers/Qt/config.cpp +++ b/src/drivers/Qt/config.cpp @@ -295,11 +295,14 @@ int getHotKeyConfig( int i, const char **nameOut, const char **keySeqOut, const case HK_SELECT_STATE_PREV: name = "SelectStatePrev"; keySeq = ""; title = "Select Previous State Slot"; group = "State"; break; + case HK_VOLUME_MUTE: + name = "VolumeMute"; keySeq = ""; title = "Sound Volume Mute"; group = "Sound"; + break; case HK_VOLUME_DOWN: - name = "VolumeDown"; keySeq = ""; + name = "VolumeDown"; keySeq = ""; title = "Sound Volume Down"; group = "Sound"; break; case HK_VOLUME_UP: - name = "VolumeUp"; keySeq = ""; + name = "VolumeUp"; keySeq = ""; title = "Sound Volume Up"; group = "Sound"; break; case HK_FKB_ENABLE: name = "FKB_Enable"; keySeq = "ScrollLock"; title = "Toggle Family Keyboard Enable"; @@ -489,6 +492,7 @@ InitConfig() // sound options config->addOption('s', "sound", "SDL.Sound", 1); + config->addOption("soundMute", "SDL.Sound.Mute", 0); config->addOption("volume", "SDL.Sound.Volume", 255); config->addOption("trianglevol", "SDL.Sound.TriangleVolume", 255); config->addOption("square1vol", "SDL.Sound.Square1Volume", 255); diff --git a/src/drivers/Qt/config.h b/src/drivers/Qt/config.h index 5b2beb92..54a6e5d8 100644 --- a/src/drivers/Qt/config.h +++ b/src/drivers/Qt/config.h @@ -56,7 +56,7 @@ enum HOTKEY { HK_CHEAT_MENU, HK_TOGGLE_ALL_CHEATS, HK_LOAD_LUA, HK_MUTE_CAPTURE, HK_FA_LAG_SKIP, - HK_VOLUME_DOWN, HK_VOLUME_UP, + HK_VOLUME_MUTE, HK_VOLUME_DOWN, HK_VOLUME_UP, HK_FKB_ENABLE, HK_MAX}; diff --git a/src/drivers/Qt/dface.h b/src/drivers/Qt/dface.h index 1459ddc8..9ffd876b 100644 --- a/src/drivers/Qt/dface.h +++ b/src/drivers/Qt/dface.h @@ -13,7 +13,9 @@ void WriteSound(int32 *Buffer, int Count); int KillSound(void); uint32 GetMaxSound(void); uint32 GetWriteSound(void); +bool FCEUD_SoundIsMuted(void); void FCEUD_MuteSoundOutput(bool value); +void FCEUD_MuteSoundWindow(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 dfe79aa8..f1a80bf5 100644 --- a/src/drivers/Qt/sdl-sound.cpp +++ b/src/drivers/Qt/sdl-sound.cpp @@ -47,10 +47,10 @@ 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 bool windowSoundMute = false; static bool fillInit = 1; -static int s_mute = 0; +static bool s_mute = false; extern int EmulationPaused; extern double frmRateAdjRatio; @@ -99,7 +99,7 @@ fillaudio(void *udata, noiseGateActive = 1; return; } - mute = EmulationPaused || muteSoundOutput; + mute = EmulationPaused || windowSoundMute || s_mute; if ( mute || noiseGateActive ) { @@ -207,6 +207,7 @@ InitSound() } // load configuration variables + g_config->getOption("SDL.Sound.Mute", &s_mute); g_config->getOption("SDL.Sound.Rate", &soundrate); g_config->getOption("SDL.Sound.BufSize", &soundbufsize); g_config->getOption("SDL.Sound.Volume", &soundvolume); @@ -524,7 +525,9 @@ FCEUD_SoundVolumeAdjust(int n) break; } - s_mute = 0; + s_mute = false; + g_config->setOption("SDL.Sound.Mute", s_mute); + FCEUI_SetSoundVolume(soundvolume); g_config->setOption("SDL.Sound.Volume", soundvolume); @@ -537,21 +540,34 @@ FCEUD_SoundVolumeAdjust(int n) void FCEUD_SoundToggle(void) { - if(s_mute) { - int soundvolume; - g_config->getOption("SDL.SoundVolume", &soundvolume); + FCEUD_MuteSoundOutput( !s_mute ); +} - s_mute = 0; - FCEUI_SetSoundVolume(soundvolume); - FCEU_DispMessage("Sound mute off.",0); - } else { - s_mute = 1; - FCEUI_SetSoundVolume(0); - FCEU_DispMessage("Sound mute on.",0); - } +bool FCEUD_SoundIsMuted(void) +{ + return s_mute; } void FCEUD_MuteSoundOutput( bool value ) { - muteSoundOutput = value; + if (value != s_mute) + { + g_config->setOption("SDL.Sound.Mute", value); + + if (value) + { + FCEU_DispMessage("Sound mute on.",0); + } + else + { + FCEU_DispMessage("Sound mute off.",0); + } + } + s_mute = value; +} + +// This function is used by the GUI to mute sound when main window is not in focus. +void FCEUD_MuteSoundWindow( bool value ) +{ + windowSoundMute = value; }