SpkrSetEmulationType(): simplify logic and remove unreachable code. (PR #919)

This commit is contained in:
Andrea 2021-01-20 21:30:34 +00:00 committed by GitHub
parent cdf1cb9106
commit baad40f3b8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 26 deletions

View File

@ -139,11 +139,9 @@ void CPageSound::DlgOK(HWND hWnd)
const DWORD dwSpkrVolume = SendDlgItemMessage(hWnd, IDC_SPKR_VOLUME, TBM_GETPOS, 0, 0);
const DWORD dwMBVolume = SendDlgItemMessage(hWnd, IDC_MB_VOLUME, TBM_GETPOS, 0, 0);
if (SpkrSetEmulationType(hWnd, newSoundType))
{
DWORD dwSoundType = (soundtype == SOUND_NONE) ? REG_SOUNDTYPE_NONE : REG_SOUNDTYPE_WAVE;
REGSAVE(TEXT(REGVALUE_SOUND_EMULATION), dwSoundType);
}
SpkrSetEmulationType(newSoundType);
DWORD dwSoundType = (soundtype == SOUND_NONE) ? REG_SOUNDTYPE_NONE : REG_SOUNDTYPE_WAVE;
REGSAVE(TEXT(REGVALUE_SOUND_EMULATION), dwSoundType);
// NB. Volume: 0=Loudest, VOLUME_MAX=Silence
SpkrSetVolume(dwSpkrVolume, VOLUME_MAX);

View File

@ -241,6 +241,18 @@ void SpkrInitialize ()
else
{
g_bSpkrAvailable = Spkr_DSInit();
if (!g_bSpkrAvailable)
{
GetFrame().FrameMessageBox(
TEXT("The emulator is unable to initialize a waveform ")
TEXT("output device. Make sure you have a sound card ")
TEXT("and a driver installed and that Windows is ")
TEXT("correctly configured to use the driver. Also ")
TEXT("ensure that no other program is currently using ")
TEXT("the device."),
TEXT("Configuration"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
}
}
//
@ -280,32 +292,13 @@ void SpkrReset()
//=============================================================================
BOOL SpkrSetEmulationType (HWND window, SoundType_e newtype)
void SpkrSetEmulationType (SoundType_e newtype)
{
SpkrDestroy(); // GH#295: Destroy for all types (even SOUND_NONE)
soundtype = newtype;
if (soundtype != SOUND_NONE)
SpkrInitialize();
if (soundtype != newtype)
switch (newtype) {
case SOUND_WAVE:
MessageBox(window,
TEXT("The emulator is unable to initialize a waveform ")
TEXT("output device. Make sure you have a sound card ")
TEXT("and a driver installed and that windows is ")
TEXT("correctly configured to use the driver. Also ")
TEXT("ensure that no other program is currently using ")
TEXT("the device."),
TEXT("Configuration"),
MB_ICONEXCLAMATION | MB_SETFOREGROUND);
return 0;
}
return 1;
}
//=============================================================================

View File

@ -21,7 +21,7 @@ void SpkrDestroy ();
void SpkrInitialize ();
void SpkrReinitialize ();
void SpkrReset();
BOOL SpkrSetEmulationType (HWND window, SoundType_e newSoundType);
void SpkrSetEmulationType (SoundType_e newSoundType);
void SpkrUpdate (DWORD);
void SpkrUpdate_Timer();
DWORD SpkrGetVolume();