mirror of
https://github.com/libretro/scummvm.git
synced 2025-01-31 07:53:36 +00:00
Extended makeWAVStream by a 'disposeAfterUse' param; changed makeWAVStream to directly return the AudioStream created by makeADPCMStream
svn-id: r36085
This commit is contained in:
parent
c08cc29b96
commit
8e447d1ee9
@ -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);
|
||||
|
@ -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))
|
||||
|
@ -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;
|
||||
|
||||
|
16
sound/wave.h
16
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
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user