From 7207d920bc2f4e01a653e0fada30698c870b9e8b Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Thu, 11 Nov 2010 13:23:26 +0000 Subject: VIDEO: Cleanup AVI audio in preparation for DK3 svn-id: r54200 --- graphics/video/avi_decoder.cpp | 50 ++++++++++++++++++++++++++---------------- graphics/video/avi_decoder.h | 21 +++++------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/graphics/video/avi_decoder.cpp b/graphics/video/avi_decoder.cpp index 713d57eb1e..40cb424ffc 100644 --- a/graphics/video/avi_decoder.cpp +++ b/graphics/video/avi_decoder.cpp @@ -30,11 +30,13 @@ #include "sound/audiostream.h" #include "sound/mixer.h" -#include "sound/decoders/raw.h" #include "graphics/video/avi_decoder.h" -// Codecs +// Audio Codecs +#include "sound/decoders/raw.h" + +// Video Codecs #include "graphics/video/codecs/cinepak.h" #include "graphics/video/codecs/indeo3.h" #include "graphics/video/codecs/msvideo1.h" @@ -342,20 +344,7 @@ Surface *AviDecoder::decodeNextFrame() { } else if (getStreamType(nextTag) == 'wb') { // Audio Chunk uint32 chunkSize = _fileStream->readUint32LE(); - byte *data = (byte *)malloc(chunkSize); - _fileStream->read(data, chunkSize); - - byte flags = 0; - if (_audsHeader.sampleSize == 2) - flags |= Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN; - else - flags |= Audio::FLAG_UNSIGNED; - - if (_wvInfo.channels == 2) - flags |= Audio::FLAG_STEREO; - - if (_audStream) - _audStream->queueBuffer(data, chunkSize, DisposeAfterUse::YES, flags); + queueAudioBuffer(chunkSize); _fileStream->skip(chunkSize & 1); // Alignment } else if (getStreamType(nextTag) == 'dc' || getStreamType(nextTag) == 'id' || getStreamType(nextTag) == 'AM' || getStreamType(nextTag) == '32') { @@ -433,14 +422,37 @@ PixelFormat AviDecoder::getPixelFormat() const { } Audio::QueuingAudioStream *AviDecoder::createAudioStream() { - if (_wvInfo.tag == AVI_WAVE_FORMAT_PCM) + if (_wvInfo.tag == kWaveFormatPCM) return Audio::makeQueuingAudioStream(AUDIO_RATE, _wvInfo.channels == 2); - else if (_wvInfo.tag == 98) + else if (_wvInfo.tag == kWaveFormatDK3) warning("Unsupported DK3 IMA ADPCM sound"); - else if (_wvInfo.tag != 0) // No sound + else if (_wvInfo.tag != kWaveFormatNone) // No sound warning("Unsupported AVI audio format %d", _wvInfo.tag); return NULL; } +void AviDecoder::queueAudioBuffer(uint32 chunkSize) { + // Return if we haven't created the queue (unsupported audio format) + if (!_audStream) { + _fileStream->skip(chunkSize); + return; + } + + Common::SeekableReadStream *stream = _fileStream->readStream(chunkSize); + + if (_wvInfo.tag == kWaveFormatPCM) { + byte flags = 0; + if (_audsHeader.sampleSize == 2) + flags |= Audio::FLAG_16BITS | Audio::FLAG_LITTLE_ENDIAN; + else + flags |= Audio::FLAG_UNSIGNED; + + if (_wvInfo.channels == 2) + flags |= Audio::FLAG_STEREO; + + _audStream->queueAudioStream(Audio::makeRawStream(stream, AUDIO_RATE, flags, DisposeAfterUse::YES), DisposeAfterUse::YES); + } +} + } // End of namespace Graphics diff --git a/graphics/video/avi_decoder.h b/graphics/video/avi_decoder.h index 557add9e25..507917f0e8 100644 --- a/graphics/video/avi_decoder.h +++ b/graphics/video/avi_decoder.h @@ -114,21 +114,11 @@ enum IndexFlags { AVIIF_INDEX = 0x10 }; -enum WaveFormats { - AVI_WAVE_INVALIDFORMAT = 0, - AVI_WAVE_FORMAT_PCM = 1, - AVI_WAVE_FORMAT_1M08 = 1, - AVI_WAVE_FORMAT_1S08 = 2, - AVI_WAVE_FORMAT_1M16 = 4, - AVI_WAVE_FORMAT_1S16 = 8, - AVI_WAVE_FORMAT_2M08 = 16, - AVI_WAVE_FORMAT_2S08 = 32, - AVI_WAVE_FORMAT_2M16 = 64, - AVI_WAVE_FORMAT_2S16 = 128, - AVI_WAVE_FORMAT_4M08 = 256, - AVI_WAVE_FORMAT_4S08 = 512, - AVI_WAVE_FORMAT_4M16 = 1024, - AVI_WAVE_FORMAT_4S16 = 2048 +// Audio Codecs +enum { + kWaveFormatNone = 0, + kWaveFormatPCM = 1, + kWaveFormatDK3 = 98 }; struct AVIHeader { @@ -222,6 +212,7 @@ private: Audio::SoundHandle *_audHandle; Audio::QueuingAudioStream *_audStream; Audio::QueuingAudioStream *createAudioStream(); + void queueAudioBuffer(uint32 chunkSize); }; } // End of namespace Graphics -- cgit v1.2.3