aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/agos/sound.cpp2
-rw-r--r--engines/saga/sndres.cpp2
-rw-r--r--engines/scumm/he/sound_he.cpp2
-rw-r--r--sound/adpcm.cpp18
-rw-r--r--sound/adpcm.h22
-rw-r--r--sound/wave.cpp4
-rw-r--r--sound/wave.h8
7 files changed, 45 insertions, 13 deletions
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp
index e198fe8d66..2da81d2d28 100644
--- a/engines/agos/sound.cpp
+++ b/engines/agos/sound.cpp
@@ -741,7 +741,7 @@ void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint soun
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.
diff --git a/engines/saga/sndres.cpp b/engines/saga/sndres.cpp
index a7a186ac1a..9b42443582 100644
--- a/engines/saga/sndres.cpp
+++ b/engines/saga/sndres.cpp
@@ -246,7 +246,7 @@ bool SndRes::load(ResourceContext *context, uint32 resourceId, SoundBuffer &buff
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) {
diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp
index b074f644e0..da830515e2 100644
--- a/engines/scumm/he/sound_he.cpp
+++ b/engines/scumm/he/sound_he.cpp
@@ -569,7 +569,7 @@ void SoundHE::playHESound(int soundID, int heOffset, int heChannel, int heFlags)
}
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);
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