From 3d04b69cbd3ab86b480eab124404c086b03cbbbc Mon Sep 17 00:00:00 2001 From: Travis Howell Date: Sat, 13 Dec 2003 01:54:17 +0000 Subject: Don't switch voice file in simon2mac unless needed. svn-id: r11608 --- simon/sound.cpp | 35 ++++++++++++++++++++--------------- simon/sound.h | 1 + 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/simon/sound.cpp b/simon/sound.cpp index c8258ab08a..0512ddbc2a 100644 --- a/simon/sound.cpp +++ b/simon/sound.cpp @@ -242,6 +242,7 @@ SimonSound::SimonSound(const byte game, const GameSpecificSettings *gss, const C _ambient_paused = false; _filenums = 0; + _last_voice_file = 0; _offsets = 0; _voice_handle = 0; @@ -396,21 +397,25 @@ void SimonSound::readVoiceFile(const char *filename, const Common::String &gameD void SimonSound::playVoice(uint sound) { if (_game == GAME_SIMON2MAC && _filenums) { - stopAll(); - - char filename[16]; - sprintf(filename, "voices%d.dat", _filenums[sound]); - File *file = new File(); - file->open(filename, _gameDataPath); - if (file->isOpen() == false) { - warning("playVoice: Can't load voice file %s", filename); - return; - } - // FIXME freeing voice at this point causes frequent game crashes - // Maybe related to sound effects and speech using same sound format ? - // In any case, this means we currently leak. - // delete _voice; - _voice = new WavSound(_mixer, file, _offsets); + if (_last_voice_file != _filenums[sound]) { + warning("Loading voice file %d", _filenums[sound]); + stopAll(); + + char filename[16]; + _last_voice_file = _filenums[sound]; + sprintf(filename, "voices%d.dat", _filenums[sound]); + File *file = new File(); + file->open(filename, _gameDataPath); + if (file->isOpen() == false) { + warning("playVoice: Can't load voice file %s", filename); + return; + } + // FIXME freeing voice at this point causes frequent game crashes + // Maybe related to sound effects and speech using same sound format ? + // In any case, this means we currently leak. + // delete _voice; + _voice = new WavSound(_mixer, file, _offsets); + } } if (!_voice) diff --git a/simon/sound.h b/simon/sound.h index c7da0bfdf0..a6217540a5 100644 --- a/simon/sound.h +++ b/simon/sound.h @@ -46,6 +46,7 @@ private: uint16 *_filenums; uint32 *_offsets; + uint16 _last_voice_file; public: PlayingSoundHandle _voice_handle; -- cgit v1.2.3