diff options
-rw-r--r-- | engines/sci/console.cpp | 4 | ||||
-rw-r--r-- | engines/sci/sound/music.cpp | 20 | ||||
-rw-r--r-- | engines/sci/sound/music.h | 2 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.cpp | 46 | ||||
-rw-r--r-- | engines/sci/sound/soundcmd.h | 1 |
5 files changed, 38 insertions, 35 deletions
diff --git a/engines/sci/console.cpp b/engines/sci/console.cpp index e238f9e5b2..1ab8e2fbb1 100644 --- a/engines/sci/console.cpp +++ b/engines/sci/console.cpp @@ -197,7 +197,7 @@ void Console::preEnter() { if (_vm->_gamestate) _vm->_gamestate->_sound.sfx_suspend(true); #endif - _vm->_mixer->pauseAll(true); + _vm->getEngineState()->_soundCmd->pauseAll(true); } void Console::postEnter() { @@ -205,7 +205,7 @@ void Console::postEnter() { if (_vm->_gamestate) _vm->_gamestate->_sound.sfx_suspend(false); #endif - _vm->_mixer->pauseAll(false); + _vm->getEngineState()->_soundCmd->pauseAll(false); if (!_videoFile.empty()) { _vm->_gamestate->_gui->hideCursor(); diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp index d96fdcbe70..c3141e67ef 100644 --- a/engines/sci/sound/music.cpp +++ b/engines/sci/sound/music.cpp @@ -91,12 +91,21 @@ void SciMusic::init() { } void SciMusic::clearPlayList() { - _mutex.lock(); + Common::StackLock lock(_mutex); + while (!_playList.empty()) { soundStop(_playList[0]); soundKill(_playList[0]); } - _mutex.unlock(); +} + +void SciMusic::pauseAll(bool pause) { + Common::StackLock lock(_mutex); + + const MusicList::iterator end = _playList.end(); + for (MusicList::iterator i = _playList.begin(); i != end; ++i) { + soundToggle(*i, pause); + } } void SciMusic::miditimerCallback(void *p) { @@ -326,6 +335,13 @@ void SciMusic::soundResume(MusicEntry *pSnd) { soundPlay(pSnd); } +void SciMusic::soundToggle(MusicEntry *pSnd, bool pause) { + if (pause) + soundPause(pSnd); + else + soundResume(pSnd); +} + uint16 SciMusic::soundGetMasterVolume() { return _masterVolume; } diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h index 2c3f2d96a6..02b79b04b5 100644 --- a/engines/sci/sound/music.h +++ b/engines/sci/sound/music.h @@ -139,6 +139,7 @@ public: void init(); void onTimer(); void clearPlayList(); + void pauseAll(bool pause); // sound and midi functions void soundInitSnd(MusicEntry *pSnd); @@ -147,6 +148,7 @@ public: void soundKill(MusicEntry *pSnd); void soundPause(MusicEntry *pSnd); void soundResume(MusicEntry *pSnd); + void soundToggle(MusicEntry *pSnd, bool pause); void soundSetVolume(MusicEntry *pSnd, byte volume); void soundSetPriority(MusicEntry *pSnd, byte prio); uint16 soundGetMasterVolume(); diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp index 79e8670578..f5fb5b4e4f 100644 --- a/engines/sci/sound/soundcmd.cpp +++ b/engines/sci/sound/soundcmd.cpp @@ -530,51 +530,29 @@ void SoundCommandParser::cmdPauseSound(reg_t obj, int16 value) { changeSoundStatus(obj, value ? SOUND_STATUS_SUSPENDED : SOUND_STATUS_PLAYING); #else - MusicEntry *musicSlot = NULL; - MusicList::iterator slotLoop = NULL; - MusicList::iterator listEnd = NULL; - - if (!obj.segment) { + if (!obj.segment) { // pause the whole playlist // Pausing/Resuming the whole playlist was introduced // in the SCI1 late sound scheme if (_soundVersion <= SCI_VERSION_1_EARLY) return; - _music->_mutex.lock(); - slotLoop = _music->getPlayListStart(); - listEnd = _music->getPlayListEnd(); - musicSlot = *slotLoop; - _music->_mutex.unlock(); - } else { - _music->_mutex.lock(); - musicSlot = _music->getSlot(obj); - _music->_mutex.unlock(); + + _music->pauseAll(value); + } else { // pause a playlist slot + Common::StackLock lock(_music->_mutex); + MusicEntry *musicSlot = _music->getSlot(obj); if (!musicSlot) { warning("cmdPauseSound: Slot not found (%04x:%04x)", PRINT_REG(obj)); return; } - } - do { if (_soundVersion <= SCI_VERSION_0_LATE) { + // Always pause the sound in SCI0 games. It's resumed in cmdResumeSound() PUT_SEL32V(_segMan, musicSlot->soundObj, state, kSoundPaused); _music->soundPause(musicSlot); } else { - if (value) - _music->soundPause(musicSlot); - else - _music->soundResume(musicSlot); - } - - if (slotLoop) { - if (slotLoop == listEnd) { - break; - } else { - _music->_mutex.lock(); - musicSlot = *(slotLoop++); - _music->_mutex.unlock(); - } + _music->soundToggle(musicSlot, value); } - } while (slotLoop); + } #endif } @@ -1100,4 +1078,10 @@ void SoundCommandParser::setMasterVolume(int vol) { #endif } +void SoundCommandParser::pauseAll(bool pause) { +#ifndef USE_OLD_MUSIC_FUNCTIONS + _music->pauseAll(pause); +#endif +} + } // End of namespace Sci diff --git a/engines/sci/sound/soundcmd.h b/engines/sci/sound/soundcmd.h index d7b0b87609..fc80b6b3fa 100644 --- a/engines/sci/sound/soundcmd.h +++ b/engines/sci/sound/soundcmd.h @@ -63,6 +63,7 @@ public: void reconstructPlayList(int savegame_version); void printPlayList(Console *con); void setMasterVolume(int vol); + void pauseAll(bool pause); #ifndef USE_OLD_MUSIC_FUNCTIONS /** |