[Scummvm-cvs-logs] SF.net SVN: scummvm:[49036] scummvm/trunk/engines/sword2/sound.cpp

eriktorbjorn at users.sourceforge.net eriktorbjorn at users.sourceforge.net
Sat May 15 10:38:19 CEST 2010


Revision: 49036
          http://scummvm.svn.sourceforge.net/scummvm/?rev=49036&view=rev
Author:   eriktorbjorn
Date:     2010-05-15 08:38:19 +0000 (Sat, 15 May 2010)

Log Message:
-----------
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").

Modified Paths:
--------------
    scummvm/trunk/engines/sword2/sound.cpp

Modified: scummvm/trunk/engines/sword2/sound.cpp
===================================================================
--- scummvm/trunk/engines/sword2/sound.cpp	2010-05-15 00:42:56 UTC (rev 49035)
+++ scummvm/trunk/engines/sword2/sound.cpp	2010-05-15 08:38:19 UTC (rev 49036)
@@ -217,13 +217,38 @@
 
 	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() {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list