aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTorbjörn Andersson2010-05-15 08:38:19 +0000
committerTorbjörn Andersson2010-05-15 08:38:19 +0000
commit2da9fa5a6edd962acca228706a2f2d4465827015 (patch)
treed42d6520fd30005c60b4f0e70f3fa984e82743c9
parent86bfccb842cc17f3eb0845b238c92f778ccf890a (diff)
downloadscummvm-rg350-2da9fa5a6edd962acca228706a2f2d4465827015.tar.gz
scummvm-rg350-2da9fa5a6edd962acca228706a2f2d4465827015.tar.bz2
scummvm-rg350-2da9fa5a6edd962acca228706a2f2d4465827015.zip
Rewrote playMovieSound() to keep it from hogging memory in the resource
manager. Perhaps this will finally fix the mysterious bug #2976008 ("BS2: Game lockup in British Museum"). svn-id: r49036
-rw-r--r--engines/sword2/sound.cpp35
1 files changed, 30 insertions, 5 deletions
diff --git a/engines/sword2/sound.cpp b/engines/sword2/sound.cpp
index 5e67ce9adf..e36c946eba 100644
--- a/engines/sword2/sound.cpp
+++ b/engines/sword2/sound.cpp
@@ -217,13 +217,38 @@ void Sound::playMovieSound(int32 res, int type) {
assert(_vm->_resman->fetchType(data) == WAV_FILE);
- // In PSX version we have nothing to skip here, as data starts right away
- if (!Sword2Engine::isPsx()) {
- data += ResHeader::size();
- len -= ResHeader::size();
+ // We want to close the resource right away, so to be safe we make a
+ // private copy of the sound;
+ byte *soundData = (byte *)malloc(len);
+
+ if (soundData) {
+ memcpy(soundData, data, len);
+
+ Common::MemoryReadStream *stream = new Common::MemoryReadStream(soundData, len, DisposeAfterUse::YES);
+
+ // In PSX version we have nothing to skip here, as data starts
+ // right away.
+ if (!Sword2Engine::isPsx()) {
+ stream->seek(ResHeader::size());
+ }
+
+ Audio::RewindableAudioStream *input = 0;
+
+ if (Sword2Engine::isPsx()) {
+ input = Audio::makeVagStream(stream);
+ } else {
+ input = Audio::makeWAVStream(stream, DisposeAfterUse::YES);
+ }
+
+ _vm->_mixer->playStream(
+ Audio::Mixer::kMusicSoundType, handle, input,
+ -1, Audio::Mixer::kMaxChannelVolume, 0,
+ DisposeAfterUse::YES, false, isReverseStereo());
+ } else {
+ warning("Sound::playMovieSound: Could not allocate %d bytes\n", len);
}
- _vm->_sound->playFx(handle, data, len, Audio::Mixer::kMaxChannelVolume, 0, false, Audio::Mixer::kMusicSoundType);
+ _vm->_resman->closeResource(res);
}
void Sound::stopMovieSounds() {