From cc84534871ef8d609ffd87a8b7ad1219f8ff5935 Mon Sep 17 00:00:00 2001 From: Simei Yin Date: Fri, 18 Aug 2017 04:36:23 +0200 Subject: SLUDGE: Fix load&save sound bug --- engines/sludge/sound.cpp | 58 ++++++++++-------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'engines/sludge/sound.cpp') diff --git a/engines/sludge/sound.cpp b/engines/sludge/sound.cpp index 297d01306c..6820ae14be 100644 --- a/engines/sludge/sound.cpp +++ b/engines/sludge/sound.cpp @@ -93,40 +93,16 @@ void SoundManager::killSoundStuff() { if (!_soundOK) return; - _silenceIKillYou = true; - for (int i = 0; i < MAX_SAMPLES; i ++) { - if (g_sludge->_mixer->isSoundHandleActive(_soundCache[i].handle)) { - g_sludge->_mixer->stopHandle(_soundCache[i].handle); - } - } -#if 0 - for (int i = 0; i < MAX_MODS; i ++) { - if (_modCache[i].playing) { - - if (! alureStopSource(modCache[i].playingOnSource, AL_TRUE)) { - debugOut("Failed to stop source: %s\n", - alureGetErrorString()); - } - - } - - if (_modCache[i].stream != NULL) { - - if (! alureDestroyStream(modCache[i].stream, 0, NULL)) { - debugOut("Failed to destroy stream: %s\n", - alureGetErrorString()); - } + for (int i = 0; i < MAX_SAMPLES; ++i) + freeSound(i); - } - } -#endif - _silenceIKillYou = false; + for (int i = 0; i < MAX_MODS; ++i) + stopMOD(i); } /* * Some setters: */ - void SoundManager::setMusicVolume(int a, int v) { if (!_soundOK) return; @@ -186,15 +162,10 @@ void SoundManager::huntKillSound(int filenum) { return; int gotSlot = findInSoundCache(filenum); - if (gotSlot == -1) return; - - _silenceIKillYou = true; - - if (g_sludge->_mixer->isSoundHandleActive(_soundCache[gotSlot].handle)) { - g_sludge->_mixer->stopHandle(_soundCache[gotSlot].handle); - } + if (gotSlot == -1) + return; - _silenceIKillYou = false; + freeSound(gotSlot); } void SoundManager::freeSound(int a) { @@ -209,6 +180,8 @@ void SoundManager::freeSound(int a) { handleSoundLists(); } + _soundCache[a].inSoundList = false; + _soundCache[a].looping = false; _soundCache[a].fileLoaded = -1; _silenceIKillYou = false; @@ -322,20 +295,12 @@ int SoundManager::makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, return -1; int a = findInSoundCache(f); - if (a != -1) { // if this sound has been loaded before - // still playing - if (g_sludge->_mixer->isSoundHandleActive(_soundCache[a].handle)) { - g_sludge->_mixer->stopHandle(_soundCache[a].handle); // stop it - if (_soundCache[a].inSoundList) { - handleSoundLists(); - } - } - } else { + if (a == -1) { if (f == -2) return -1; a = findEmptySoundSlot(); - freeSound(a); } + freeSound(a); setResourceForFatal(f); uint32 length = g_sludge->_resMan->openFileFromNum(f); @@ -357,6 +322,7 @@ int SoundManager::makeSoundAudioStream(int f, Audio::AudioStream *&audiostream, if (stream) { audiostream = Audio::makeLoopingAudioStream(stream, loopy ? 0 : 1); _soundCache[a].fileLoaded = f; + _soundCache[a].looping = loopy; setResourceForFatal(-1); } else { audiostream = nullptr; -- cgit v1.2.3