Added Qt GUI sound mute function. This function is accessible either via hot key or checkbox on sound config window. Mute state is a config parameter and will persist between application boots. Fixes issue #591

This commit is contained in:
harry 2023-01-11 20:47:11 -05:00
parent e06d1cd506
commit 739c01f051
8 changed files with 69 additions and 21 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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();

View File

@ -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);

View File

@ -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);

View File

@ -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};

View File

@ -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 */

View File

@ -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;
}