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

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Fri Nov 16 11:05:18 CET 2007


Revision: 29517
          http://scummvm.svn.sourceforge.net/scummvm/?rev=29517&view=rev
Author:   fingolfin
Date:     2007-11-16 02:05:18 -0800 (Fri, 16 Nov 2007)

Log Message:
-----------
Changed Audio::makeADPCMStream so that the stream passed to it can automatically be disposed

Modified Paths:
--------------
    scummvm/trunk/engines/agos/sound.cpp
    scummvm/trunk/engines/saga/sndres.cpp
    scummvm/trunk/engines/scumm/he/sound_he.cpp
    scummvm/trunk/sound/adpcm.cpp
    scummvm/trunk/sound/adpcm.h
    scummvm/trunk/sound/wave.cpp
    scummvm/trunk/sound/wave.h

Modified: scummvm/trunk/engines/agos/sound.cpp
===================================================================
--- scummvm/trunk/engines/agos/sound.cpp	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/engines/agos/sound.cpp	2007-11-16 10:05:18 UTC (rev 29517)
@@ -741,7 +741,7 @@
 		flags |= Audio::Mixer::FLAG_LOOP;
 
 	if (compType == 2) {
-		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
+		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
 		buffer = (byte *)malloc(size * 4);
 		size = sndStream->readBuffer((int16*)buffer, size * 2);
 		size *= 2; // 16bits.

Modified: scummvm/trunk/engines/saga/sndres.cpp
===================================================================
--- scummvm/trunk/engines/saga/sndres.cpp	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/engines/saga/sndres.cpp	2007-11-16 10:05:18 UTC (rev 29517)
@@ -246,7 +246,7 @@
 			buffer.buffer = NULL;
 			free(soundResource);
 		} else {
-			voxStream = Audio::makeADPCMStream(&readS, soundResourceLength, Audio::kADPCMOki);
+			voxStream = Audio::makeADPCMStream(&readS, false, soundResourceLength, Audio::kADPCMOki);
 			buffer.buffer = (byte *)malloc(buffer.size);
 			voxSize = voxStream->readBuffer((int16*)buffer.buffer, soundResourceLength * 2);
 			if (voxSize != soundResourceLength * 2) {

Modified: scummvm/trunk/engines/scumm/he/sound_he.cpp
===================================================================
--- scummvm/trunk/engines/scumm/he/sound_he.cpp	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/engines/scumm/he/sound_he.cpp	2007-11-16 10:05:18 UTC (rev 29517)
@@ -569,7 +569,7 @@
 		}
 
 		if (compType == 17) {
-			Audio::AudioStream *voxStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
+			Audio::AudioStream *voxStream = Audio::makeADPCMStream(&stream, false, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
 
 			sound = (char *)malloc(size * 4);
 			size = voxStream->readBuffer((int16*)sound, size * 2);

Modified: scummvm/trunk/sound/adpcm.cpp
===================================================================
--- scummvm/trunk/sound/adpcm.cpp	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/sound/adpcm.cpp	2007-11-16 10:05:18 UTC (rev 29517)
@@ -37,6 +37,7 @@
 class ADPCMInputStream : public AudioStream {
 private:
 	Common::SeekableReadStream *_stream;
+	bool _disposeAfterUse;
 	uint32 _endpos;
 	int _channels;
 	typesADPCM _type;
@@ -69,8 +70,8 @@
 	int16 decodeMS(ADPCMChannelStatus *c, byte);
 
 public:
-	ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels = 2, uint32 blockAlign = 0);
-	~ADPCMInputStream() {}
+	ADPCMInputStream(Common::SeekableReadStream *stream, bool disposeAfterUse, uint32 size, typesADPCM type, int rate, int channels = 2, uint32 blockAlign = 0);
+	~ADPCMInputStream();
 
 	int readBuffer(int16 *buffer, const int numSamples);
 	int readBufferOKI(int16 *buffer, const int numSamples);
@@ -90,8 +91,8 @@
 // In addition, also MS IMA ADPCM is supported. See
 //   <http://wiki.multimedia.cx/index.php?title=Microsoft_IMA_ADPCM>.
 
-ADPCMInputStream::ADPCMInputStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign)
-	: _stream(stream), _channels(channels), _type(type), _blockAlign(blockAlign), _rate(rate) {
+ADPCMInputStream::ADPCMInputStream(Common::SeekableReadStream *stream, bool disposeAfterUse, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign)
+	: _stream(stream), _disposeAfterUse(disposeAfterUse), _channels(channels), _type(type), _blockAlign(blockAlign), _rate(rate) {
 
 	_status.last = 0;
 	_status.stepIndex = 0;
@@ -106,6 +107,11 @@
 		error("ADPCMInputStream(): blockAlign isn't specifiled for MS ADPCM");
 }
 
+ADPCMInputStream::~ADPCMInputStream() {
+	if (_disposeAfterUse)
+		delete _stream;
+}
+
 int ADPCMInputStream::readBuffer(int16 *buffer, const int numSamples) {
 	switch (_type) {
 	case kADPCMOki:
@@ -355,8 +361,8 @@
 	return samp;
 }
 
-AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign) {
-	return new ADPCMInputStream(stream, size, type, rate, channels, blockAlign);
+AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, bool disposeAfterUse, uint32 size, typesADPCM type, int rate, int channels, uint32 blockAlign) {
+	return new ADPCMInputStream(stream, disposeAfterUse, size, type, rate, channels, blockAlign);
 }
 
 } // End of namespace Audio

Modified: scummvm/trunk/sound/adpcm.h
===================================================================
--- scummvm/trunk/sound/adpcm.h	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/sound/adpcm.h	2007-11-16 10:05:18 UTC (rev 29517)
@@ -40,7 +40,27 @@
 	kADPCMMS
 };
 
-AudioStream *makeADPCMStream(Common::SeekableReadStream *stream, uint32 size, typesADPCM type, int rate = 22050, int channels = 2, uint32 blockAlign = 0);
+/**
+ * Takes an input stream containing ADPCM compressed sound data and creates
+ * an AudioStream from that.
+ *
+ * @param stream			the SeekableReadStream from which to read the ADPCM data
+ * @param disposeAfterUse	whether to delete the stream after use
+ * @param size				how many bytes to read from the stream (0 = all)
+ * @param type				the compression type used
+ * @param rate				the sampling rate (default = 22050)
+ * @param channels			the number of channels (default = 2)
+ * @param blockAlign		block alignment ??? (default = 0)
+ * @return	a new AudioStream, or NULL, if an error occured
+ */
+AudioStream *makeADPCMStream(
+	Common::SeekableReadStream *stream,
+	bool disposeAfterUse,
+	uint32 size,
+	typesADPCM type,
+	int rate = 22050,
+	int channels = 2,
+	uint32 blockAlign = 0);
 
 } // End of namespace Audio
 

Modified: scummvm/trunk/sound/wave.cpp
===================================================================
--- scummvm/trunk/sound/wave.cpp	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/sound/wave.cpp	2007-11-16 10:05:18 UTC (rev 29517)
@@ -172,14 +172,14 @@
 		return 0;
 
 	if (type == 17) { // MS IMA ADPCM
-		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMSIma, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
+		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;
 	} else if (type == 2) { // MS ADPCM
-		Audio::AudioStream *sndStream = Audio::makeADPCMStream(&stream, size, Audio::kADPCMMS, rate, (flags & Audio::Mixer::FLAG_STEREO) ? 2 : 1, blockAlign);
+		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);

Modified: scummvm/trunk/sound/wave.h
===================================================================
--- scummvm/trunk/sound/wave.h	2007-11-16 08:59:18 UTC (rev 29516)
+++ scummvm/trunk/sound/wave.h	2007-11-16 10:05:18 UTC (rev 29517)
@@ -41,7 +41,13 @@
  * necessary for playback. Currently this function only supports uncompressed
  * raw PCM data as well as IMA ADPCM.
  */
-extern bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate, byte &flags, uint16 *wavType = 0, int *blockAlign = 0);
+extern bool loadWAVFromStream(
+	Common::SeekableReadStream &stream,
+	int &size,
+	int &rate,
+	byte &flags,
+	uint16 *wavType = 0,
+	int *blockAlign = 0);
 
 /**
  * Try to load a WAVE from the given seekable stream and create an AudioStream


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