[Scummvm-cvs-logs] SF.net SVN: scummvm:[36085] scummvm/trunk

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Jan 27 01:42:44 CET 2009


Revision: 36085
          http://scummvm.svn.sourceforge.net/scummvm/?rev=36085&view=rev
Author:   fingolfin
Date:     2009-01-27 00:42:43 +0000 (Tue, 27 Jan 2009)

Log Message:
-----------
Extended makeWAVStream by a 'disposeAfterUse' param; changed makeWAVStream to directly return the AudioStream created by makeADPCMStream

Modified Paths:
--------------
    scummvm/trunk/engines/agos/animation.cpp
    scummvm/trunk/engines/agos/sound.cpp
    scummvm/trunk/sound/wave.cpp
    scummvm/trunk/sound/wave.h

Modified: scummvm/trunk/engines/agos/animation.cpp
===================================================================
--- scummvm/trunk/engines/agos/animation.cpp	2009-01-27 00:41:41 UTC (rev 36084)
+++ scummvm/trunk/engines/agos/animation.cpp	2009-01-27 00:42:43 UTC (rev 36085)
@@ -301,7 +301,7 @@
 		}
 
 		Common::MemoryReadStream stream(buffer, size);
-		_bgSoundStream = Audio::makeWAVStream(stream);
+		_bgSoundStream = Audio::makeWAVStream(&stream, false);
 		free(buffer);
 	} else {
 		_bgSoundStream = Audio::AudioStream::openStreamFile(baseName);

Modified: scummvm/trunk/engines/agos/sound.cpp
===================================================================
--- scummvm/trunk/engines/agos/sound.cpp	2009-01-27 00:41:41 UTC (rev 36084)
+++ scummvm/trunk/engines/agos/sound.cpp	2009-01-27 00:42:43 UTC (rev 36085)
@@ -247,7 +247,7 @@
 		return NULL;
 
 	_file->seek(_offsets[sound], SEEK_SET);
-	return Audio::makeWAVStream(*_file);
+	return Audio::makeWAVStream(_file, false);
 }
 
 void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
@@ -263,6 +263,7 @@
 
 	int size, rate;
 	byte *buffer = Audio::loadVOCFromStream(*_file, size, rate);
+	// TODO: Use makeVOCStream
 	assert(buffer);
 	_mixer->playRaw(type, handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE);
 }
@@ -741,6 +742,7 @@
 	uint16 compType;
 	int blockAlign, rate;
 
+	// FIXME: How about using makeWAVStream() here?
 	int size = READ_LE_UINT32(soundData + 4);
 	Common::MemoryReadStream stream(soundData, size);
 	if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign))

Modified: scummvm/trunk/sound/wave.cpp
===================================================================
--- scummvm/trunk/sound/wave.cpp	2009-01-27 00:41:41 UTC (rev 36084)
+++ scummvm/trunk/sound/wave.cpp	2009-01-27 00:42:43 UTC (rev 36085)
@@ -162,35 +162,31 @@
 	return true;
 }
 
-AudioStream *makeWAVStream(Common::SeekableReadStream &stream) {
+AudioStream *makeWAVStream(Common::SeekableReadStream *stream, bool disposeAfterUse) {
 	int size, rate;
 	byte *data, flags;
 	uint16 type;
 	int blockAlign;
 
-	if (!loadWAVFromStream(stream, size, rate, flags, &type, &blockAlign))
+	if (!loadWAVFromStream(*stream, size, rate, flags, &type, &blockAlign)) {
+		if (disposeAfterUse)
+			delete stream;
 		return 0;
+	}
 
 	if (type == 17) { // MS IMA ADPCM
-		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-		data = (byte *)malloc(size * 4);
-		assert(data);
-		size = sndStream->readBuffer((int16*)data, size * 2);
-		size *= 2; // 16bits.
-		delete sndStream;
+		return Audio::makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
 	} else if (type == 2) { // MS ADPCM
-		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
-		data = (byte *)malloc(size * 4);
-		assert(data);
-		size = sndStream->readBuffer((int16*)data, size * 2);
-		size *= 2; // 16bits.
-		delete sndStream;
-	} else {
-		data = (byte *)malloc(size);
-		assert(data);
-		stream.read(data, size);
+		return Audio::makeADPCMStream(stream, disposeAfterUse, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
 	}
 
+	// Plain data. Just read everything at once.
+	// TODO: More elegant would be to wrap the stream.
+	data = (byte *)malloc(size);
+	assert(data);
+	stream->read(data, size);
+	delete stream;
+
 	// Since we allocated our own buffer for the data, we must set the autofree flag.
 	flags |= Audio::Mixer::FLAG_AUTOFREE;
 

Modified: scummvm/trunk/sound/wave.h
===================================================================
--- scummvm/trunk/sound/wave.h	2009-01-27 00:41:41 UTC (rev 36084)
+++ scummvm/trunk/sound/wave.h	2009-01-27 00:42:43 UTC (rev 36085)
@@ -38,8 +38,8 @@
  * Try to load a WAVE from the given seekable stream. Returns true if
  * successful. In that case, the stream's seek position will be set to the
  * start of the audio data, and size, rate and flags contain information
- * necessary for playback. Currently this function only supports uncompressed
- * raw PCM data as well as IMA ADPCM.
+ * necessary for playback. Currently this function supports uncompressed
+ * raw PCM data, MS IMA ADPCM and MS ADPCM (uses makeADPCMStream internally).
  */
 extern bool loadWAVFromStream(
 	Common::SeekableReadStream &stream,
@@ -51,12 +51,18 @@
 
 /**
  * Try to load a WAVE from the given seekable stream and create an AudioStream
- * from that data. Currently this function only supports uncompressed raw PCM
- * data as well as IMA ADPCM.
+ * from that data. Currently this function supports uncompressed
+ * raw PCM data, MS IMA ADPCM and MS ADPCM (uses makeADPCMStream internally).
  *
  * This function uses loadWAVFromStream() internally.
+ *
+ * @param stream			the SeekableReadStream from which to read the WAVE data
+ * @param disposeAfterUse	whether to delete the stream after use
+ * @return	a new AudioStream, or NULL, if an error occured
  */
-AudioStream *makeWAVStream(Common::SeekableReadStream &stream);
+AudioStream *makeWAVStream(
+	Common::SeekableReadStream *stream,
+	bool disposeAfterUse = false);
 
 } // End of namespace Audio
 


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