aboutsummaryrefslogtreecommitdiff
path: root/sound
diff options
context:
space:
mode:
Diffstat (limited to 'sound')
-rw-r--r--sound/wave.cpp32
-rw-r--r--sound/wave.h16
2 files changed, 25 insertions, 23 deletions
diff --git a/sound/wave.cpp b/sound/wave.cpp
index 72a3992401..80bf6d42d4 100644
--- a/sound/wave.cpp
+++ b/sound/wave.cpp
@@ -162,35 +162,31 @@ bool loadWAVFromStream(Common::SeekableReadStream &stream, int &size, int &rate,
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;
diff --git a/sound/wave.h b/sound/wave.h
index 37b390c934..6b035bd722 100644
--- a/sound/wave.h
+++ b/sound/wave.h
@@ -38,8 +38,8 @@ class AudioStream;
* 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 @@ extern bool loadWAVFromStream(
/**
* 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