From c8ce5b1865c3854eca79843e12493453c7566d0b Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 16 Nov 2007 10:05:18 +0000 Subject: Changed Audio::makeADPCMStream so that the stream passed to it can automatically be disposed svn-id: r29517 --- sound/adpcm.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'sound/adpcm.cpp') diff --git a/sound/adpcm.cpp b/sound/adpcm.cpp index ca1eb79c6f..d1e54de2af 100644 --- a/sound/adpcm.cpp +++ b/sound/adpcm.cpp @@ -37,6 +37,7 @@ namespace Audio { class ADPCMInputStream : public AudioStream { private: Common::SeekableReadStream *_stream; + bool _disposeAfterUse; uint32 _endpos; int _channels; typesADPCM _type; @@ -69,8 +70,8 @@ private: 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 @@ public: // In addition, also MS IMA ADPCM is supported. See // . -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 @@ ADPCMInputStream::ADPCMInputStream(Common::SeekableReadStream *stream, uint32 si 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 @@ int16 ADPCMInputStream::decodeMSIMA(byte code) { 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 -- cgit v1.2.3