aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/adpcm.cpp18
-rw-r--r--sound/adpcm.h22
-rw-r--r--sound/wave.cpp4
-rw-r--r--sound/wave.h8
4 files changed, 42 insertions, 10 deletions
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
// <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 @@ 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
diff --git a/sound/adpcm.h b/sound/adpcm.h
index 772dd63d34..db008609ec 100644
--- a/sound/adpcm.h
+++ b/sound/adpcm.h
@@ -40,7 +40,27 @@ enum typesADPCM {
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
diff --git a/sound/wave.cpp b/sound/wave.cpp
index 6c74db2ab3..249518aafc 100644
--- a/sound/wave.cpp
+++ b/sound/wave.cpp
@@ -172,14 +172,14 @@ AudioStream *makeWAVStream(Common::SeekableReadStream &stream) {
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);
diff --git a/sound/wave.h b/sound/wave.h
index 5387865bcf..37b390c934 100644
--- a/sound/wave.h
+++ b/sound/wave.h
@@ -41,7 +41,13 @@ class AudioStream;
* 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