diff options
-rw-r--r-- | engines/zvision/video/zork_avi_decoder.cpp | 9 | ||||
-rw-r--r-- | engines/zvision/video/zork_avi_decoder.h | 7 | ||||
-rw-r--r-- | video/avi_decoder.cpp | 86 | ||||
-rw-r--r-- | video/avi_decoder.h | 8 |
4 files changed, 57 insertions, 53 deletions
diff --git a/engines/zvision/video/zork_avi_decoder.cpp b/engines/zvision/video/zork_avi_decoder.cpp index 53b0a9a0c5..fb6bdbab91 100644 --- a/engines/zvision/video/zork_avi_decoder.cpp +++ b/engines/zvision/video/zork_avi_decoder.cpp @@ -41,6 +41,15 @@ Video::AVIDecoder::AVIAudioTrack *ZorkAVIDecoder::createAudioTrack(Video::AVIDec return new ZorkAVIAudioTrack(sHeader, wvInfo, _soundType); } +ZorkAVIDecoder::ZorkAVIAudioTrack::ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : + Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType), _queueStream(0), _decoder(waveFormat.channels == 2) { +} + +void ZorkAVIDecoder::ZorkAVIAudioTrack::createAudioStream() { + _queueStream = Audio::makeQueuingAudioStream(_wvInfo.samplesPerSec, _wvInfo.channels == 2); + _audioStream = _queueStream; +} + void ZorkAVIDecoder::ZorkAVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { RawChunkStream::RawChunk chunk = _decoder.readNextChunk(stream); delete stream; diff --git a/engines/zvision/video/zork_avi_decoder.h b/engines/zvision/video/zork_avi_decoder.h index 8e7be710ee..afcdb05676 100644 --- a/engines/zvision/video/zork_avi_decoder.h +++ b/engines/zvision/video/zork_avi_decoder.h @@ -39,15 +39,14 @@ public: private: class ZorkAVIAudioTrack : public Video::AVIDecoder::AVIAudioTrack { public: - ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) : - Video::AVIDecoder::AVIAudioTrack(streamHeader, waveFormat, soundType), - _decoder(waveFormat.channels == 2) { - } + ZorkAVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType); + void createAudioStream(); void queueSound(Common::SeekableReadStream *stream); void resetStream(); private: + Audio::QueuingAudioStream *_queueStream; RawChunkStream _decoder; }; diff --git a/video/avi_decoder.cpp b/video/avi_decoder.cpp index aef5e763e9..52a55f600c 100644 --- a/video/avi_decoder.cpp +++ b/video/avi_decoder.cpp @@ -278,7 +278,9 @@ void AVIDecoder::handleStreamHeader(uint32 size) { if (wvInfo.channels == 2) sHeader.sampleSize /= 2; - addTrack(createAudioTrack(sHeader, wvInfo)); + AVIAudioTrack *track = createAudioTrack(sHeader, wvInfo); + track->createAudioStream(); + addTrack(track); } // Ensure that we're at the end of the chunk @@ -841,40 +843,18 @@ void AVIDecoder::AVIVideoTrack::setDither(const byte *palette) { } AVIDecoder::AVIAudioTrack::AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType) - : _audsHeader(streamHeader), _wvInfo(waveFormat), _soundType(soundType), _curChunk(0) { - createAudioStream(); + : _audsHeader(streamHeader), _wvInfo(waveFormat), _soundType(soundType), _audioStream(0), _packetStream(0), _curChunk(0) { } AVIDecoder::AVIAudioTrack::~AVIAudioTrack() { - delete _queueStream; - delete _packetStream; + delete _audioStream; } void AVIDecoder::AVIAudioTrack::queueSound(Common::SeekableReadStream *stream) { - if (_packetStream) { + if (_packetStream) _packetStream->queuePacket(stream); - } else if (_queueStream) { - 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; - - _queueStream->queueAudioStream(Audio::makeRawStream(stream, _wvInfo.samplesPerSec, flags, DisposeAfterUse::YES), DisposeAfterUse::YES); - } else if (_wvInfo.tag == kWaveFormatMSADPCM) { - _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMS, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); - } else if (_wvInfo.tag == kWaveFormatMSIMAADPCM) { - _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMMSIma, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); - } else if (_wvInfo.tag == kWaveFormatDK3) { - _queueStream->queueAudioStream(Audio::makeADPCMStream(stream, DisposeAfterUse::YES, stream->size(), Audio::kADPCMDK3, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign), DisposeAfterUse::YES); - } - } else { + else delete stream; - } _curChunk++; } @@ -899,8 +879,7 @@ void AVIDecoder::AVIAudioTrack::skipAudio(const Audio::Timestamp &time, const Au } void AVIDecoder::AVIAudioTrack::resetStream() { - delete _queueStream; - delete _packetStream; + delete _audioStream; createAudioStream(); _curChunk = 0; } @@ -910,33 +889,50 @@ bool AVIDecoder::AVIAudioTrack::rewind() { return true; } -Audio::AudioStream *AVIDecoder::AVIAudioTrack::getAudioStream() const { - if (_packetStream) - return _packetStream; - - return _queueStream; -} - void AVIDecoder::AVIAudioTrack::createAudioStream() { - _queueStream = 0; _packetStream = 0; - if (_wvInfo.tag == kWaveFormatPCM || _wvInfo.tag == kWaveFormatMSADPCM || _wvInfo.tag == kWaveFormatMSIMAADPCM || _wvInfo.tag == kWaveFormatDK3) { - // For now, a QueuingAudioStream will be created - } else if (_wvInfo.tag == kWaveFormatMP3) { - // MPEG audio + switch (_wvInfo.tag) { + case 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; + + _packetStream = Audio::makePacketizedRawStream(_wvInfo.samplesPerSec, flags); + break; + } + case kWaveFormatMSADPCM: + _packetStream = Audio::makePacketizedADPCMStream(Audio::kADPCMMS, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign); + break; + case kWaveFormatMSIMAADPCM: + _packetStream = Audio::makePacketizedADPCMStream(Audio::kADPCMMSIma, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign); + break; + case kWaveFormatDK3: + _packetStream = Audio::makePacketizedADPCMStream(Audio::kADPCMDK3, _wvInfo.samplesPerSec, _wvInfo.channels, _wvInfo.blockAlign); + break; + case kWaveFormatMP3: #ifdef USE_MAD _packetStream = Audio::makePacketizedMP3Stream(_wvInfo.channels, _wvInfo.samplesPerSec); #else warning("AVI MP3 stream found, but no libmad support compiled in"); #endif - } else if (_wvInfo.tag != kWaveFormatNone) { - // No supported format + break; + case kWaveFormatNone: + break; + default: warning("Unsupported AVI audio format %d", _wvInfo.tag); + break; } - if (!_packetStream) - _queueStream = Audio::makeQueuingAudioStream(_wvInfo.samplesPerSec, _wvInfo.channels == 2); + if (_packetStream) + _audioStream = _packetStream; + else + _audioStream = Audio::makeNullAudioStream(); } AVIDecoder::TrackStatus::TrackStatus() : track(0), chunkSearchOffset(0) { diff --git a/video/avi_decoder.h b/video/avi_decoder.h index 8b12c23adf..96d9e821ff 100644 --- a/video/avi_decoder.h +++ b/video/avi_decoder.h @@ -32,8 +32,8 @@ #include "audio/mixer.h" namespace Audio { +class AudioStream; class PacketizedAudioStream; -class QueuingAudioStream; } namespace Common { @@ -216,6 +216,7 @@ protected: AVIAudioTrack(const AVIStreamHeader &streamHeader, const PCMWaveFormat &waveFormat, Audio::Mixer::SoundType soundType); ~AVIAudioTrack(); + virtual void createAudioStream(); virtual void queueSound(Common::SeekableReadStream *stream); Audio::Mixer::SoundType getSoundType() const { return _soundType; } void skipAudio(const Audio::Timestamp &time, const Audio::Timestamp &frameTime); @@ -227,7 +228,7 @@ protected: bool rewind(); protected: - Audio::AudioStream *getAudioStream() const; + Audio::AudioStream *getAudioStream() const { return _audioStream; } // Audio Codecs enum { @@ -242,9 +243,8 @@ protected: AVIStreamHeader _audsHeader; PCMWaveFormat _wvInfo; Audio::Mixer::SoundType _soundType; - Audio::QueuingAudioStream *_queueStream; + Audio::AudioStream *_audioStream; Audio::PacketizedAudioStream *_packetStream; - void createAudioStream(); uint32 _curChunk; }; |