Clear MB sound buffer from old save-state to new one

This commit is contained in:
tomcw 2023-01-21 21:45:20 +00:00
parent 0606716072
commit 775f568a7c
3 changed files with 14 additions and 12 deletions

View File

@ -758,15 +758,6 @@ void MockingboardCard::InitializeIO(LPBYTE pCxRomPeripheral)
break;
}
#endif // NO_DIRECT_X
//
// TODO-TC: move to class MockingboardCardManager
//
// Sound buffer may have been stopped by MB_InitializeForLoadingSnapshot().
// NB. DSZeroVoiceBuffer() also zeros the sound buffer, so it's better than directly calling IDirectSoundBuffer::Play():
// - without zeroing, then the previous sound buffer can be heard for a fraction of a second
// - eg. when doing Mockingboard playback, then loading a save-state which is also doing Mockingboard playback
// DSZeroVoiceBuffer(&MockingboardVoice, g_dwDSBufferSize);
}
//-----------------------------------------------------------------------------

View File

@ -56,8 +56,10 @@ void MockingboardCardManager::InitializeForLoadingSnapshot(void)
if (g_bDisableDirectSound || g_bDisableDirectSoundMockingboard)
return;
if (MockingboardVoice.lpDSBvoice);
DSVoiceStop(&MockingboardVoice); // Reason: 'MB voice is playing' then loading a save-state where 'no MB present' (GH#609)
if (!MockingboardVoice.lpDSBvoice)
return;
DSVoiceStop(&MockingboardVoice); // Reason: 'MB voice is playing' then loading a save-state where 'no MB present' (GH#609)
}
void MockingboardCardManager::MuteControl(bool mute)
@ -216,6 +218,15 @@ void MockingboardCardManager::UpdateSoundBuffer(void)
return;
}
if (!MockingboardVoice.bActive)
{
// Sound buffer may have been stopped by MB_InitializeForLoadingSnapshot().
// NB. DSZeroVoiceBuffer() also zeros the sound buffer, so it's better than directly calling IDirectSoundBuffer::Play():
// - without zeroing, then the previous sound buffer can be heard for a fraction of a second
// - eg. when doing Mockingboard playback, then loading a save-state which is also doing Mockingboard playback
DSZeroVoiceBuffer(&MockingboardVoice, g_dwDSBufferSize); // ... and Play()
}
UINT numSamples = GenerateAllSoundData();
if (numSamples)
MixAllAndCopyToRingBuffer(numSamples);

View File

@ -14,7 +14,7 @@ public:
m_userVolume = 0;
// NB. Cmd line has already been processed
LogFileOutput("MockingboardCardManager::ctor() g_bDisableDirectSound=%d, g_bDisableDirectSoundMockingboard=%d\n", g_bDisableDirectSound, g_bDisableDirectSoundMockingboard);
LogFileOutput("MBCardMgr::ctor() g_bDisableDirectSound=%d, g_bDisableDirectSoundMockingboard=%d\n", g_bDisableDirectSound, g_bDisableDirectSoundMockingboard);
}
~MockingboardCardManager(void)
{}