aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax Horn2009-01-27 00:42:43 +0000
committerMax Horn2009-01-27 00:42:43 +0000
commit8e447d1ee93d3238d35a665c5ec63671ed890210 (patch)
treefc980ae05de56de256385cc2d2311f88897eccac
parentc08cc29b965f31dd7c233714d0a052ab357c4bc5 (diff)
downloadscummvm-rg350-8e447d1ee93d3238d35a665c5ec63671ed890210.tar.gz
scummvm-rg350-8e447d1ee93d3238d35a665c5ec63671ed890210.tar.bz2
scummvm-rg350-8e447d1ee93d3238d35a665c5ec63671ed890210.zip
Extended makeWAVStream by a 'disposeAfterUse' param; changed makeWAVStream to directly return the AudioStream created by makeADPCMStream
svn-id: r36085
-rw-r--r--engines/agos/animation.cpp2
-rw-r--r--engines/agos/sound.cpp4
-rw-r--r--sound/wave.cpp32
-rw-r--r--sound/wave.h16
4 files changed, 29 insertions, 25 deletions
diff --git a/engines/agos/animation.cpp b/engines/agos/animation.cpp
index ec51f8479b..9ba8320098 100644
--- a/engines/agos/animation.cpp
+++ b/engines/agos/animation.cpp
@@ -301,7 +301,7 @@ void MoviePlayerDXA::startSound() {
}
Common::MemoryReadStream stream(buffer, size);
- _bgSoundStream = Audio::makeWAVStream(stream);
+ _bgSoundStream = Audio::makeWAVStream(&stream, false);
free(buffer);
} else {
_bgSoundStream = Audio::AudioStream::openStreamFile(baseName);
diff --git a/engines/agos/sound.cpp b/engines/agos/sound.cpp
index 5558e9025a..3aa3bd1865 100644
--- a/engines/agos/sound.cpp
+++ b/engines/agos/sound.cpp
@@ -247,7 +247,7 @@ Audio::AudioStream *WavSound::makeAudioStream(uint sound) {
return NULL;
_file->seek(_offsets[sound], SEEK_SET);
- return Audio::makeWAVStream(*_file);
+ return Audio::makeWAVStream(_file, false);
}
void WavSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType type, Audio::SoundHandle *handle, byte flags, int vol) {
@@ -263,6 +263,7 @@ void VocSound::playSound(uint sound, uint loopSound, Audio::Mixer::SoundType typ
int size, rate;
byte *buffer = Audio::loadVOCFromStream(*_file, size, rate);
+ // TODO: Use makeVOCStream
assert(buffer);
_mixer->playRaw(type, handle, buffer, size, rate, flags | Audio::Mixer::FLAG_AUTOFREE);
}
@@ -741,6 +742,7 @@ void Sound::playSoundData(Audio::SoundHandle *handle, byte *soundData, uint soun
uint16 compType;
int blockAlign, rate;
+ // FIXME: How about using makeWAVStream() here?
int size = READ_LE_UINT32(soundData + 4);
Common::MemoryReadStream stream(soundData, size);
if (!Audio::loadWAVFromStream(stream, size, rate, flags, &compType, &blockAlign))
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