From ff9dc4ab248e47c15076dd822b635927f7b27161 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Mon, 12 Nov 2012 20:09:29 +1100 Subject: HOPKINS: Bugfix for freeze when looking at the cat when voices are turned on. --- engines/hopkins/sound.cpp | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'engines/hopkins/sound.cpp') diff --git a/engines/hopkins/sound.cpp b/engines/hopkins/sound.cpp index e23c7e525f..9cbfa39f71 100644 --- a/engines/hopkins/sound.cpp +++ b/engines/hopkins/sound.cpp @@ -331,6 +331,11 @@ void SoundManager::DEL_MUSIC() { Music._currentIndex = -1; } +void SoundManager::checkSounds() { + checkMusic(); + checkVoices(); +} + void SoundManager::checkMusic() { if (Music._active && Music._isPlaying) { int mwavIndex = Music._mwavIndexes[Music._currentIndex]; @@ -363,6 +368,20 @@ void SoundManager::checkMusic() { } } +void SoundManager::checkVoices() { + // Check the status of each voice. + bool hasActiveVoice = false; + for (int i = 0; i < VOICE_COUNT; ++i) { + VOICE_STAT(i); + hasActiveVoice |= Voice[i]._status != 0; + } + + if (!hasActiveVoice && SOUND_FLAG) { + SOUND_FLAG = false; + SOUND_NUM = 0; + } +} + void SoundManager::LOAD_MSAMPLE(int mwavIndex, const Common::String &file) { if (!Mwav[mwavIndex]._active) { Common::File f; @@ -578,7 +597,8 @@ void SoundManager::PLAY_WAV(int wavIndex) { int SoundManager::VOICE_STAT(int voiceIndex) { if (Voice[voiceIndex]._status) { - if (Voice[voiceIndex]._audioStream->endOfStream()) + int wavIndex = Voice[voiceIndex]._wavIndex; + if (Swav[wavIndex]._audioStream->endOfStream()) STOP_VOICE(voiceIndex); } @@ -599,7 +619,6 @@ void SoundManager::STOP_VOICE(int voiceIndex) { Voice[voiceIndex].fieldC = 0; Voice[voiceIndex]._status = 0; Voice[voiceIndex].field14 = 0; - Voice[voiceIndex]._audioStream = NULL; } void SoundManager::SDL_LVOICE(size_t filePosition, size_t entryLength) { @@ -691,9 +710,9 @@ void SoundManager::PLAY_SAMPLE_SDL(int voiceIndex, int wavIndex) { DEL_SAMPLE_SDL(wavIndex); Voice[voiceIndex].fieldC = 0; - Voice[voiceIndex]._audioStream = Swav[wavIndex]._audioStream; Voice[voiceIndex]._status = 1; Voice[voiceIndex].field14 = 4; + Voice[voiceIndex]._wavIndex = wavIndex; int volume = (voiceIndex == 2) ? VOICEVOL * 255 / 16 : SOUNDVOL * 255 / 16; -- cgit v1.2.3