diff options
author | Matthew Hoops | 2012-07-25 11:22:28 -0400 |
---|---|---|
committer | Matthew Hoops | 2012-07-25 11:22:28 -0400 |
commit | 57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d (patch) | |
tree | 26d5770e1b8507fb0e518aba7a809f2d50b2d812 | |
parent | c0cece8d1335a3397ea980d9a2abc4075656068c (diff) | |
download | scummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.tar.gz scummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.tar.bz2 scummvm-rg350-57a06e383b7c3c950653a99c81c1c7fd7dcd5b1d.zip |
VIDEO: Convert Bink to the new AdvancedVideoDecoder API
-rw-r--r-- | engines/scumm/he/animation_he.cpp | 8 | ||||
-rw-r--r-- | video/bink_decoder.cpp | 1028 | ||||
-rw-r--r-- | video/bink_decoder.h | 420 |
3 files changed, 693 insertions, 763 deletions
diff --git a/engines/scumm/he/animation_he.cpp b/engines/scumm/he/animation_he.cpp index b37a565aab..8329511c14 100644 --- a/engines/scumm/he/animation_he.cpp +++ b/engines/scumm/he/animation_he.cpp @@ -40,10 +40,7 @@ MoviePlayer::MoviePlayer(ScummEngine_v90he *vm, Audio::Mixer *mixer) : _vm(vm) { _video = new Video::BinkDecoder(); else #endif - { _video = new Video::SmackerDecoder(); - ((Video::AdvancedVideoDecoder *)_video)->start(); - } _flags = 0; _wizResNum = 0; @@ -64,11 +61,16 @@ int MoviePlayer::load(const char *filename, int flags, int image) { if (_video->isVideoLoaded()) _video->close(); + // Ensure that Bink will use our PixelFormat + ((Video::AdvancedVideoDecoder *)_video)->setDefaultHighColorFormat(g_system->getScreenFormat()); + if (!_video->loadFile(filename)) { warning("Failed to load video file %s", filename); return -1; } + ((Video::AdvancedVideoDecoder *)_video)->start(); + debug(1, "Playing video %s", filename); if (flags & 2) diff --git a/video/bink_decoder.cpp b/video/bink_decoder.cpp index 538487f067..cac0b356c5 100644 --- a/video/bink_decoder.cpp +++ b/video/bink_decoder.cpp @@ -24,6 +24,7 @@ // based quite heavily on the Bink decoder found in FFmpeg. // Many thanks to Kostya Shishkov for doing the hard work. +#include "audio/audiostream.h" #include "audio/decoders/raw.h" #include "common/util.h" @@ -60,139 +61,108 @@ static const uint32 kDCStartBits = 11; namespace Video { -BinkDecoder::VideoFrame::VideoFrame() : bits(0) { -} - -BinkDecoder::VideoFrame::~VideoFrame() { - delete bits; +BinkDecoder::BinkDecoder() { + _bink = 0; } - -BinkDecoder::AudioTrack::AudioTrack() : bits(0), bands(0), rdft(0), dct(0) { +BinkDecoder::~BinkDecoder() { + close(); } -BinkDecoder::AudioTrack::~AudioTrack() { - delete bits; - - delete[] bands; - - delete rdft; - delete dct; -} +bool BinkDecoder::loadStream(Common::SeekableReadStream *stream) { + close(); + uint32 id = stream->readUint32BE(); + if ((id != kBIKfID) && (id != kBIKgID) && (id != kBIKhID) && (id != kBIKiID)) + return false; -BinkDecoder::BinkDecoder() { - _bink = 0; - _audioTrack = 0; + uint32 fileSize = stream->readUint32LE() + 8; + uint32 frameCount = stream->readUint32LE(); + uint32 largestFrameSize = stream->readUint32LE(); - for (int i = 0; i < 16; i++) - _huffman[i] = 0; + if (largestFrameSize > fileSize) { + warning("Largest frame size greater than file size"); + return false; + } - for (int i = 0; i < kSourceMAX; i++) { - _bundles[i].countLength = 0; + stream->skip(4); - _bundles[i].huffman.index = 0; - for (int j = 0; j < 16; j++) - _bundles[i].huffman.symbols[j] = j; + uint32 width = stream->readUint32LE(); + uint32 height = stream->readUint32LE(); - _bundles[i].data = 0; - _bundles[i].dataEnd = 0; - _bundles[i].curDec = 0; - _bundles[i].curPtr = 0; + uint32 frameRateNum = stream->readUint32LE(); + uint32 frameRateDen = stream->readUint32LE(); + if (frameRateNum == 0 || frameRateDen == 0) { + warning("Invalid frame rate (%d/%d)", frameRateNum, frameRateDen); + return false; } - for (int i = 0; i < 16; i++) { - _colHighHuffman[i].index = 0; - for (int j = 0; j < 16; j++) - _colHighHuffman[i].symbols[j] = j; - } + _bink = stream; - for (int i = 0; i < 4; i++) { - _curPlanes[i] = 0; - _oldPlanes[i] = 0; - } + uint32 videoFlags = _bink->readUint32LE(); - _audioStream = 0; -} + // BIKh and BIKi swap the chroma planes + addTrack(new BinkVideoTrack(width, height, getDefaultHighColorFormat(), frameCount, + Common::Rational(frameRateNum, frameRateDen), (id == kBIKhID || id == kBIKiID), videoFlags & kVideoFlagAlpha, id)); -void BinkDecoder::startAudio() { - if (_audioTrack < _audioTracks.size()) { - const AudioTrack &audio = _audioTracks[_audioTrack]; + uint32 audioTrackCount = _bink->readUint32LE(); - _audioStream = Audio::makeQueuingAudioStream(audio.outSampleRate, audio.outChannels == 2); - g_system->getMixer()->playStream(Audio::Mixer::kPlainSoundType, &_audioHandle, _audioStream, -1, getVolume(), getBalance()); - } // else no audio -} + if (audioTrackCount > 0) { + _audioTracks.reserve(audioTrackCount); -void BinkDecoder::stopAudio() { - if (_audioStream) { - g_system->getMixer()->stopHandle(_audioHandle); - _audioStream = 0; - } -} + _bink->skip(4 * audioTrackCount); -BinkDecoder::~BinkDecoder() { - close(); -} + // Reading audio track properties + for (uint32 i = 0; i < audioTrackCount; i++) { + AudioInfo track; -void BinkDecoder::close() { - reset(); + track.sampleRate = _bink->readUint16LE(); + track.flags = _bink->readUint16LE(); - // Stop audio - stopAudio(); + _audioTracks.push_back(track); - for (int i = 0; i < 4; i++) { - delete[] _curPlanes[i]; _curPlanes[i] = 0; - delete[] _oldPlanes[i]; _oldPlanes[i] = 0; + initAudioTrack(_audioTracks[i]); + } + + _bink->skip(4 * audioTrackCount); } - deinitBundles(); + // Reading video frame properties + _frames.resize(frameCount); + for (uint32 i = 0; i < frameCount; i++) { + _frames[i].offset = _bink->readUint32LE(); + _frames[i].keyFrame = _frames[i].offset & 1; - for (int i = 0; i < 16; i++) { - delete _huffman[i]; - _huffman[i] = 0; - } + _frames[i].offset &= ~1; - delete _bink; _bink = 0; - _surface.free(); + if (i != 0) + _frames[i - 1].size = _frames[i].offset - _frames[i - 1].offset; - _audioTrack = 0; + _frames[i].bits = 0; + } - for (int i = 0; i < kSourceMAX; i++) { - _bundles[i].countLength = 0; + _frames[frameCount - 1].size = _bink->size() - _frames[frameCount - 1].offset; - _bundles[i].huffman.index = 0; - for (int j = 0; j < 16; j++) - _bundles[i].huffman.symbols[j] = j; + return true; +} - _bundles[i].data = 0; - _bundles[i].dataEnd = 0; - _bundles[i].curDec = 0; - _bundles[i].curPtr = 0; - } +void BinkDecoder::close() { + AdvancedVideoDecoder::close(); - for (int i = 0; i < 16; i++) { - _colHighHuffman[i].index = 0; - for (int j = 0; j < 16; j++) - _colHighHuffman[i].symbols[j] = j; - } + delete _bink; + _bink = 0; _audioTracks.clear(); _frames.clear(); } -uint32 BinkDecoder::getTime() const { - if (_audioStream && g_system->getMixer()->isSoundHandleActive(_audioHandle)) - return g_system->getMixer()->getSoundElapsedTime(_audioHandle) + _audioStartOffset; +void BinkDecoder::readNextPacket() { + BinkVideoTrack *videoTrack = (BinkVideoTrack *)getTrack(0); - return g_system->getMillis() - _startTime; -} - -const Graphics::Surface *BinkDecoder::decodeNextFrame() { - if (endOfVideo()) - return 0; + if (videoTrack->endOfTrack()) + return; - VideoFrame &frame = _frames[_curFrame + 1]; + VideoFrame &frame = _frames[videoTrack->getCurFrame() + 1]; if (!_bink->seek(frame.offset)) error("Bad bink seek"); @@ -200,7 +170,7 @@ const Graphics::Surface *BinkDecoder::decodeNextFrame() { uint32 frameSize = frame.size; for (uint32 i = 0; i < _audioTracks.size(); i++) { - AudioTrack &audio = _audioTracks[i]; + AudioInfo &audio = _audioTracks[i]; uint32 audioPacketLength = _bink->readUint32LE(); @@ -210,24 +180,21 @@ const Graphics::Surface *BinkDecoder::decodeNextFrame() { error("Audio packet too big for the frame"); if (audioPacketLength >= 4) { + // Get our track - audio index plus one as the first track is video + BinkAudioTrack *audioTrack = (BinkAudioTrack *)getTrack(i + 1); uint32 audioPacketStart = _bink->pos(); uint32 audioPacketEnd = _bink->pos() + audioPacketLength; - if (i == _audioTrack) { - // Only play one audio track - - // Number of samples in bytes - audio.sampleCount = _bink->readUint32LE() / (2 * audio.channels); + // Number of samples in bytes + audio.sampleCount = _bink->readUint32LE() / (2 * audio.channels); - audio.bits = - new Common::BitStream32LELSB(new Common::SeekableSubReadStream(_bink, - audioPacketStart + 4, audioPacketEnd), true); + audio.bits = new Common::BitStream32LELSB(new Common::SeekableSubReadStream(_bink, + audioPacketStart + 4, audioPacketEnd), true); - audioPacket(audio); + audioTrack->decodePacket(); - delete audio.bits; - audio.bits = 0; - } + delete audio.bits; + audio.bits = 0; _bink->seek(audioPacketEnd); @@ -238,67 +205,125 @@ const Graphics::Surface *BinkDecoder::decodeNextFrame() { uint32 videoPacketStart = _bink->pos(); uint32 videoPacketEnd = _bink->pos() + frameSize; - frame.bits = - new Common::BitStream32LELSB(new Common::SeekableSubReadStream(_bink, - videoPacketStart, videoPacketEnd), true); + frame.bits = new Common::BitStream32LELSB(new Common::SeekableSubReadStream(_bink, + videoPacketStart, videoPacketEnd), true); - videoPacket(frame); + videoTrack->decodePacket(frame); delete frame.bits; frame.bits = 0; +} - _curFrame++; - if (_curFrame == 0) - _startTime = g_system->getMillis(); +BinkDecoder::VideoFrame::VideoFrame() : bits(0) { +} - return &_surface; +BinkDecoder::VideoFrame::~VideoFrame() { + delete bits; } -void BinkDecoder::audioPacket(AudioTrack &audio) { - if (!_audioStream) - return; - int outSize = audio.frameLen * audio.channels; - while (audio.bits->pos() < audio.bits->size()) { - int16 *out = (int16 *)malloc(outSize * 2); - memset(out, 0, outSize * 2); +BinkDecoder::AudioInfo::AudioInfo() : bits(0), bands(0), rdft(0), dct(0) { +} - audioBlock(audio, out); +BinkDecoder::AudioInfo::~AudioInfo() { + delete bits; - byte flags = Audio::FLAG_16BITS; - if (audio.outChannels == 2) - flags |= Audio::FLAG_STEREO; + delete[] bands; -#ifdef SCUMM_LITTLE_ENDIAN - flags |= Audio::FLAG_LITTLE_ENDIAN; -#endif + delete rdft; + delete dct; +} + +BinkDecoder::BinkVideoTrack::BinkVideoTrack(uint32 width, uint32 height, const Graphics::PixelFormat &format, uint32 frameCount, const Common::Rational &frameRate, bool swapPlanes, bool hasAlpha, uint32 id) : + _frameCount(frameCount), _frameRate(frameRate), _swapPlanes(swapPlanes), _hasAlpha(hasAlpha), _id(id) { + _curFrame = -1; + + for (int i = 0; i < 16; i++) + _huffman[i] = 0; + + for (int i = 0; i < kSourceMAX; i++) { + _bundles[i].countLength = 0; + + _bundles[i].huffman.index = 0; + for (int j = 0; j < 16; j++) + _bundles[i].huffman.symbols[j] = j; + + _bundles[i].data = 0; + _bundles[i].dataEnd = 0; + _bundles[i].curDec = 0; + _bundles[i].curPtr = 0; + } + + for (int i = 0; i < 16; i++) { + _colHighHuffman[i].index = 0; + for (int j = 0; j < 16; j++) + _colHighHuffman[i].symbols[j] = j; + } + + _surface.create(width, height, format); + + // Give the planes a bit extra space + width = _surface.w + 32; + height = _surface.h + 32; + + _curPlanes[0] = new byte[ width * height ]; // Y + _curPlanes[1] = new byte[(width >> 1) * (height >> 1)]; // U, 1/4 resolution + _curPlanes[2] = new byte[(width >> 1) * (height >> 1)]; // V, 1/4 resolution + _curPlanes[3] = new byte[ width * height ]; // A + _oldPlanes[0] = new byte[ width * height ]; // Y + _oldPlanes[1] = new byte[(width >> 1) * (height >> 1)]; // U, 1/4 resolution + _oldPlanes[2] = new byte[(width >> 1) * (height >> 1)]; // V, 1/4 resolution + _oldPlanes[3] = new byte[ width * height ]; // A + + // Initialize the video with solid black + memset(_curPlanes[0], 0, width * height ); + memset(_curPlanes[1], 0, (width >> 1) * (height >> 1)); + memset(_curPlanes[2], 0, (width >> 1) * (height >> 1)); + memset(_curPlanes[3], 255, width * height ); + memset(_oldPlanes[0], 0, width * height ); + memset(_oldPlanes[1], 0, (width >> 1) * (height >> 1)); + memset(_oldPlanes[2], 0, (width >> 1) * (height >> 1)); + memset(_oldPlanes[3], 255, width * height ); - _audioStream->queueBuffer((byte *)out, audio.blockSize * 2, DisposeAfterUse::YES, flags); + initBundles(); + initHuffman(); +} - if (audio.bits->pos() & 0x1F) // next data block starts at a 32-byte boundary - audio.bits->skip(32 - (audio.bits->pos() & 0x1F)); +BinkDecoder::BinkVideoTrack::~BinkVideoTrack() { + for (int i = 0; i < 4; i++) { + delete[] _curPlanes[i]; _curPlanes[i] = 0; + delete[] _oldPlanes[i]; _oldPlanes[i] = 0; } + + deinitBundles(); + + for (int i = 0; i < 16; i++) { + delete _huffman[i]; + _huffman[i] = 0; + } + + _surface.free(); } -void BinkDecoder::videoPacket(VideoFrame &video) { - assert(video.bits); +void BinkDecoder::BinkVideoTrack::decodePacket(VideoFrame &frame) { + assert(frame.bits); if (_hasAlpha) { if (_id == kBIKiID) - video.bits->skip(32); + frame.bits->skip(32); - decodePlane(video, 3, false); + decodePlane(frame, 3, false); } if (_id == kBIKiID) - video.bits->skip(32); + frame.bits->skip(32); for (int i = 0; i < 3; i++) { int planeIdx = ((i == 0) || !_swapPlanes) ? i : (i ^ 3); - decodePlane(video, planeIdx, i != 0); + decodePlane(frame, planeIdx, i != 0); - if (video.bits->pos() >= video.bits->size()) + if (frame.bits->pos() >= frame.bits->size()) break; } @@ -311,10 +336,11 @@ void BinkDecoder::videoPacket(VideoFrame &video) { // And swap the planes with the reference planes for (int i = 0; i < 4; i++) SWAP(_curPlanes[i], _oldPlanes[i]); -} -void BinkDecoder::decodePlane(VideoFrame &video, int planeIdx, bool isChroma) { + _curFrame++; +} +void BinkDecoder::BinkVideoTrack::decodePlane(VideoFrame &video, int planeIdx, bool isChroma) { uint32 blockWidth = isChroma ? ((_surface.w + 15) >> 4) : ((_surface.w + 7) >> 3); uint32 blockHeight = isChroma ? ((_surface.h + 15) >> 4) : ((_surface.h + 7) >> 3); uint32 width = isChroma ? (_surface.w >> 1) : _surface.w; @@ -371,48 +397,38 @@ void BinkDecoder::decodePlane(VideoFrame &video, int planeIdx, bool isChroma) { } switch (blockType) { - case kBlockSkip: - blockSkip(ctx); - break; - - case kBlockScaled: - blockScaled(ctx); - break; - - case kBlockMotion: - blockMotion(ctx); - break; - - case kBlockRun: - blockRun(ctx); - break; - - case kBlockResidue: - blockResidue(ctx); - break; - - case kBlockIntra: - blockIntra(ctx); - break; - - case kBlockFill: - blockFill(ctx); - break; - - case kBlockInter: - blockInter(ctx); - break; - - case kBlockPattern: - blockPattern(ctx); - break; - - case kBlockRaw: - blockRaw(ctx); - break; - - default: - error("Unknown block type: %d", blockType); + case kBlockSkip: + blockSkip(ctx); + break; + case kBlockScaled: + blockScaled(ctx); + break; + case kBlockMotion: + blockMotion(ctx); + break; + case kBlockRun: + blockRun(ctx); + break; + case kBlockResidue: + blockResidue(ctx); + break; + case kBlockIntra: + blockIntra(ctx); + break; + case kBlockFill: + blockFill(ctx); + break; + case kBlockInter: + blockInter(ctx); + break; + case kBlockPattern: + blockPattern(ctx); + break; + case kBlockRaw: + blockRaw(ctx); + break; + default: + error("Unknown block type: %d", blockType); } } @@ -424,7 +440,7 @@ void BinkDecoder::decodePlane(VideoFrame &video, int planeIdx, bool isChroma) { } -void BinkDecoder::readBundle(VideoFrame &video, Source source) { +void BinkDecoder::BinkVideoTrack::readBundle(VideoFrame &video, Source source) { if (source == kSourceColors) { for (int i = 0; i < 16; i++) readHuffman(video, _colHighHuffman[i]); @@ -439,12 +455,11 @@ void BinkDecoder::readBundle(VideoFrame &video, Source source) { _bundles[source].curPtr = _bundles[source].data; } -void BinkDecoder::readHuffman(VideoFrame &video, Huffman &huffman) { +void BinkDecoder::BinkVideoTrack::readHuffman(VideoFrame &video, Huffman &huffman) { huffman.index = video.bits->getBits(4); if (huffman.index == 0) { // The first tree always gives raw nibbles - for (int i = 0; i < 16; i++) huffman.symbols[i] = i; @@ -455,7 +470,6 @@ void BinkDecoder::readHuffman(VideoFrame &video, Huffman &huffman) { if (video.bits->getBit()) { // Symbol selection - memset(hasSymbol, 0, 16); uint8 length = video.bits->getBits(3); @@ -493,9 +507,9 @@ void BinkDecoder::readHuffman(VideoFrame &video, Huffman &huffman) { memcpy(huffman.symbols, in, 16); } -void BinkDecoder::mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size) { +void BinkDecoder::BinkVideoTrack::mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size) { const byte *src2 = src + size; - int size2 = size; + int size2 = size; do { if (!video.bits->getBit()) { @@ -510,197 +524,12 @@ void BinkDecoder::mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte * while (size--) *dst++ = *src++; + while (size2--) *dst++ = *src2++; } -bool BinkDecoder::loadStream(Common::SeekableReadStream *stream) { - Graphics::PixelFormat format = g_system->getScreenFormat(); - return loadStream(stream, format); -} - -bool BinkDecoder::loadStream(Common::SeekableReadStream *stream, const Graphics::PixelFormat &format) { - close(); - - _id = stream->readUint32BE(); - if ((_id != kBIKfID) && (_id != kBIKgID) && (_id != kBIKhID) && (_id != kBIKiID)) - return false; - - uint32 fileSize = stream->readUint32LE() + 8; - uint32 frameCount = stream->readUint32LE(); - uint32 largestFrameSize = stream->readUint32LE(); - - if (largestFrameSize > fileSize) { - warning("Largest frame size greater than file size"); - return false; - } - - stream->skip(4); - - uint32 width = stream->readUint32LE(); - uint32 height = stream->readUint32LE(); - - uint32 frameRateNum = stream->readUint32LE(); - uint32 frameRateDen = stream->readUint32LE(); - if (frameRateNum == 0 || frameRateDen == 0) { - warning("Invalid frame rate (%d/%d)", frameRateNum, frameRateDen); - return false; - } - - _frameRate = Common::Rational(frameRateNum, frameRateDen); - _bink = stream; - - _videoFlags = _bink->readUint32LE(); - - uint32 audioTrackCount = _bink->readUint32LE(); - - if (audioTrackCount > 1) { - warning("More than one audio track found. Using the first one"); - - _audioTrack = 0; - } - - if (audioTrackCount > 0) { - _audioTracks.reserve(audioTrackCount); - - _bink->skip(4 * audioTrackCount); - - // Reading audio track properties - for (uint32 i = 0; i < audioTrackCount; i++) { - AudioTrack track; - - track.sampleRate = _bink->readUint16LE(); - track.flags = _bink->readUint16LE(); - - _audioTracks.push_back(track); - - initAudioTrack(_audioTracks[i]); - } - - _bink->skip(4 * audioTrackCount); - } - - // Reading video frame properties - _frames.resize(frameCount); - for (uint32 i = 0; i < frameCount; i++) { - _frames[i].offset = _bink->readUint32LE(); - _frames[i].keyFrame = _frames[i].offset & 1; - - _frames[i].offset &= ~1; - - if (i != 0) - _frames[i - 1].size = _frames[i].offset - _frames[i - 1].offset; - - _frames[i].bits = 0; - } - - _frames[frameCount - 1].size = _bink->size() - _frames[frameCount - 1].offset; - - _hasAlpha = _videoFlags & kVideoFlagAlpha; - _swapPlanes = (_id == kBIKhID) || (_id == kBIKiID); // BIKh and BIKi swap the chroma planes - - _surface.create(width, height, format); - - // Give the planes a bit extra space - width = _surface.w + 32; - height = _surface.h + 32; - - _curPlanes[0] = new byte[ width * height ]; // Y - _curPlanes[1] = new byte[(width >> 1) * (height >> 1)]; // U, 1/4 resolution - _curPlanes[2] = new byte[(width >> 1) * (height >> 1)]; // V, 1/4 resolution - _curPlanes[3] = new byte[ width * height ]; // A - _oldPlanes[0] = new byte[ width * height ]; // Y - _oldPlanes[1] = new byte[(width >> 1) * (height >> 1)]; // U, 1/4 resolution - _oldPlanes[2] = new byte[(width >> 1) * (height >> 1)]; // V, 1/4 resolution - _oldPlanes[3] = new byte[ width * height ]; // A - - // Initialize the video with solid black - memset(_curPlanes[0], 0, width * height ); - memset(_curPlanes[1], 0, (width >> 1) * (height >> 1)); - memset(_curPlanes[2], 0, (width >> 1) * (height >> 1)); - memset(_curPlanes[3], 255, width * height ); - memset(_oldPlanes[0], 0, width * height ); - memset(_oldPlanes[1], 0, (width >> 1) * (height >> 1)); - memset(_oldPlanes[2], 0, (width >> 1) * (height >> 1)); - memset(_oldPlanes[3], 255, width * height ); - - initBundles(); - initHuffman(); - - startAudio(); - _audioStartOffset = 0; - - return true; -} - -void BinkDecoder::initAudioTrack(AudioTrack &audio) { - audio.sampleCount = 0; - audio.bits = 0; - - audio.channels = ((audio.flags & kAudioFlagStereo) != 0) ? 2 : 1; - audio.codec = ((audio.flags & kAudioFlagDCT ) != 0) ? kAudioCodecDCT : kAudioCodecRDFT; - - if (audio.channels > kAudioChannelsMax) - error("Too many audio channels: %d", audio.channels); - - uint32 frameLenBits; - // Calculate frame length - if (audio.sampleRate < 22050) - frameLenBits = 9; - else if(audio.sampleRate < 44100) - frameLenBits = 10; - else - frameLenBits = 11; - - audio.frameLen = 1 << frameLenBits; - - audio.outSampleRate = audio.sampleRate; - audio.outChannels = audio.channels; - - if (audio.codec == kAudioCodecRDFT) { - // RDFT audio already interleaves the samples correctly - - if (audio.channels == 2) - frameLenBits++; - - audio.sampleRate *= audio.channels; - audio.frameLen *= audio.channels; - audio.channels = 1; - } - - audio.overlapLen = audio.frameLen / 16; - audio.blockSize = (audio.frameLen - audio.overlapLen) * audio.channels; - audio.root = 2.0 / sqrt((double)audio.frameLen); - - uint32 sampleRateHalf = (audio.sampleRate + 1) / 2; - - // Calculate number of bands - for (audio.bandCount = 1; audio.bandCount < 25; audio.bandCount++) - if (sampleRateHalf <= binkCriticalFreqs[audio.bandCount - 1]) - break; - - audio.bands = new uint32[audio.bandCount + 1]; - - // Populate bands - audio.bands[0] = 1; - for (uint32 i = 1; i < audio.bandCount; i++) - audio.bands[i] = binkCriticalFreqs[i - 1] * (audio.frameLen / 2) / sampleRateHalf; - audio.bands[audio.bandCount] = audio.frameLen / 2; - - audio.first = true; - - for (uint8 i = 0; i < audio.channels; i++) - audio.coeffsPtr[i] = audio.coeffs + i * audio.frameLen; - - audio.codec = ((audio.flags & kAudioFlagDCT) != 0) ? kAudioCodecDCT : kAudioCodecRDFT; - - if (audio.codec == kAudioCodecRDFT) - audio.rdft = new Common::RDFT(frameLenBits, Common::RDFT::DFT_C2R); - else if (audio.codec == kAudioCodecDCT) - audio.dct = new Common::DCT(frameLenBits, Common::DCT::DCT_III); -} - -void BinkDecoder::initBundles() { +void BinkDecoder::BinkVideoTrack::initBundles() { uint32 bw = (_surface.w + 7) >> 3; uint32 bh = (_surface.h + 7) >> 3; uint32 blocks = bw * bh; @@ -729,21 +558,21 @@ void BinkDecoder::initBundles() { } } -void BinkDecoder::deinitBundles() { +void BinkDecoder::BinkVideoTrack::deinitBundles() { for (int i = 0; i < kSourceMAX; i++) delete[] _bundles[i].data; } -void BinkDecoder::initHuffman() { +void BinkDecoder::BinkVideoTrack::initHuffman() { for (int i = 0; i < 16; i++) _huffman[i] = new Common::Huffman(binkHuffmanLengths[i][15], 16, binkHuffmanCodes[i], binkHuffmanLengths[i]); } -byte BinkDecoder::getHuffmanSymbol(VideoFrame &video, Huffman &huffman) { +byte BinkDecoder::BinkVideoTrack::getHuffmanSymbol(VideoFrame &video, Huffman &huffman) { return huffman.symbols[_huffman[huffman.index]->getSymbol(*video.bits)]; } -int32 BinkDecoder::getBundleValue(Source source) { +int32 BinkDecoder::BinkVideoTrack::getBundleValue(Source source) { if ((source < kSourceXOff) || (source == kSourceRun)) return *_bundles[source].curPtr++; @@ -757,7 +586,7 @@ int32 BinkDecoder::getBundleValue(Source source) { return ret; } -uint32 BinkDecoder::readBundleCount(VideoFrame &video, Bundle &bundle) { +uint32 BinkDecoder::BinkVideoTrack::readBundleCount(VideoFrame &video, Bundle &bundle) { if (!bundle.curDec || (bundle.curDec > bundle.curPtr)) return 0; @@ -768,7 +597,7 @@ uint32 BinkDecoder::readBundleCount(VideoFrame &video, Bundle &bundle) { return n; } -void BinkDecoder::blockSkip(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockSkip(DecodeContext &ctx) { byte *dest = ctx.dest; byte *prev = ctx.prev; @@ -776,7 +605,7 @@ void BinkDecoder::blockSkip(DecodeContext &ctx) { memcpy(dest, prev, 8); } -void BinkDecoder::blockScaledSkip(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledSkip(DecodeContext &ctx) { byte *dest = ctx.dest; byte *prev = ctx.prev; @@ -784,7 +613,7 @@ void BinkDecoder::blockScaledSkip(DecodeContext &ctx) { memcpy(dest, prev, 16); } -void BinkDecoder::blockScaledRun(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledRun(DecodeContext &ctx) { const uint8 *scan = binkPatterns[ctx.video->bits->getBits(4)]; int i = 0; @@ -820,7 +649,7 @@ void BinkDecoder::blockScaledRun(DecodeContext &ctx) { ctx.dest[ctx.coordScaledMap4[*scan]] = getBundleValue(kSourceColors); } -void BinkDecoder::blockScaledIntra(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledIntra(DecodeContext &ctx) { int16 block[64]; memset(block, 0, 64 * sizeof(int16)); @@ -841,7 +670,7 @@ void BinkDecoder::blockScaledIntra(DecodeContext &ctx) { } } -void BinkDecoder::blockScaledFill(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledFill(DecodeContext &ctx) { byte v = getBundleValue(kSourceColors); byte *dest = ctx.dest; @@ -849,7 +678,7 @@ void BinkDecoder::blockScaledFill(DecodeContext &ctx) { memset(dest, v, 16); } -void BinkDecoder::blockScaledPattern(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledPattern(DecodeContext &ctx) { byte col[2]; for (int i = 0; i < 2; i++) @@ -865,7 +694,7 @@ void BinkDecoder::blockScaledPattern(DecodeContext &ctx) { } } -void BinkDecoder::blockScaledRaw(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaledRaw(DecodeContext &ctx) { byte row[8]; byte *dest1 = ctx.dest; @@ -880,32 +709,27 @@ void BinkDecoder::blockScaledRaw(DecodeContext &ctx) { } } -void BinkDecoder::blockScaled(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockScaled(DecodeContext &ctx) { BlockType blockType = (BlockType) getBundleValue(kSourceSubBlockTypes); switch (blockType) { - case kBlockRun: - blockScaledRun(ctx); - break; - - case kBlockIntra: - blockScaledIntra(ctx); - break; - - case kBlockFill: - blockScaledFill(ctx); - break; - - case kBlockPattern: - blockScaledPattern(ctx); - break; - - case kBlockRaw: - blockScaledRaw(ctx); - break; - - default: - error("Invalid 16x16 block type: %d", blockType); + case kBlockRun: + blockScaledRun(ctx); + break; + case kBlockIntra: + blockScaledIntra(ctx); + break; + case kBlockFill: + blockScaledFill(ctx); + break; + case kBlockPattern: + blockScaledPattern(ctx); + break; + case kBlockRaw: + blockScaledRaw(ctx); + break; + default: + error("Invalid 16x16 block type: %d", blockType); } ctx.blockX += 1; @@ -913,7 +737,7 @@ void BinkDecoder::blockScaled(DecodeContext &ctx) { ctx.prev += 8; } -void BinkDecoder::blockMotion(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockMotion(DecodeContext &ctx) { int8 xOff = getBundleValue(kSourceXOff); int8 yOff = getBundleValue(kSourceYOff); @@ -926,7 +750,7 @@ void BinkDecoder::blockMotion(DecodeContext &ctx) { memcpy(dest, prev, 8); } -void BinkDecoder::blockRun(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockRun(DecodeContext &ctx) { const uint8 *scan = binkPatterns[ctx.video->bits->getBits(4)]; int i = 0; @@ -953,7 +777,7 @@ void BinkDecoder::blockRun(DecodeContext &ctx) { ctx.dest[ctx.coordMap[*scan++]] = getBundleValue(kSourceColors); } -void BinkDecoder::blockResidue(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockResidue(DecodeContext &ctx) { blockMotion(ctx); byte v = ctx.video->bits->getBits(7); @@ -970,7 +794,7 @@ void BinkDecoder::blockResidue(DecodeContext &ctx) { dst[j] += src[j]; } -void BinkDecoder::blockIntra(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockIntra(DecodeContext &ctx) { int16 block[64]; memset(block, 0, 64 * sizeof(int16)); @@ -981,7 +805,7 @@ void BinkDecoder::blockIntra(DecodeContext &ctx) { IDCTPut(ctx, block); } -void BinkDecoder::blockFill(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockFill(DecodeContext &ctx) { byte v = getBundleValue(kSourceColors); byte *dest = ctx.dest; @@ -989,7 +813,7 @@ void BinkDecoder::blockFill(DecodeContext &ctx) { memset(dest, v, 8); } -void BinkDecoder::blockInter(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockInter(DecodeContext &ctx) { blockMotion(ctx); int16 block[64]; @@ -1002,7 +826,7 @@ void BinkDecoder::blockInter(DecodeContext &ctx) { IDCTAdd(ctx, block); } -void BinkDecoder::blockPattern(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockPattern(DecodeContext &ctx) { byte col[2]; for (int i = 0; i < 2; i++) @@ -1017,7 +841,7 @@ void BinkDecoder::blockPattern(DecodeContext &ctx) { } } -void BinkDecoder::blockRaw(DecodeContext &ctx) { +void BinkDecoder::BinkVideoTrack::blockRaw(DecodeContext &ctx) { byte *dest = ctx.dest; byte *data = _bundles[kSourceColors].curPtr; for (int i = 0; i < 8; i++, dest += ctx.pitch, data += 8) @@ -1026,7 +850,7 @@ void BinkDecoder::blockRaw(DecodeContext &ctx) { _bundles[kSourceColors].curPtr += 64; } -void BinkDecoder::readRuns(VideoFrame &video, Bundle &bundle) { +void BinkDecoder::BinkVideoTrack::readRuns(VideoFrame &video, Bundle &bundle) { uint32 n = readBundleCount(video, bundle); if (n == 0) return; @@ -1046,7 +870,7 @@ void BinkDecoder::readRuns(VideoFrame &video, Bundle &bundle) { *bundle.curDec++ = getHuffmanSymbol(video, bundle.huffman); } -void BinkDecoder::readMotionValues(VideoFrame &video, Bundle &bundle) { +void BinkDecoder::BinkVideoTrack::readMotionValues(VideoFrame &video, Bundle &bundle) { uint32 n = readBundleCount(video, bundle); if (n == 0) return; @@ -1083,7 +907,7 @@ void BinkDecoder::readMotionValues(VideoFrame &video, Bundle &bundle) { } const uint8 rleLens[4] = { 4, 8, 12, 32 }; -void BinkDecoder::readBlockTypes(VideoFrame &video, Bundle &bundle) { +void BinkDecoder::BinkVideoTrack::readBlockTypes(VideoFrame &video, Bundle &bundle) { uint32 n = readBundleCount(video, bundle); if (n == 0) return; @@ -1120,7 +944,7 @@ void BinkDecoder::readBlockTypes(VideoFrame &video, Bundle &bundle) { } while (bundle.curDec < decEnd); } -void BinkDecoder::readPatterns(VideoFrame &video, Bundle &bundle) { +void BinkDecoder::BinkVideoTrack::readPatterns(VideoFrame &video, Bundle &bundle) { uint32 n = readBundleCount(video, bundle); if (n == 0) return; @@ -1138,7 +962,7 @@ void BinkDecoder::readPatterns(VideoFrame &video, Bundle &bundle) { } -void BinkDecoder::readColors(VideoFrame &video, Bundle &bundle) { +void BinkDecoder::BinkVideoTrack::readColors(VideoFrame &video, Bundle &bundle) { uint32 n = readBundleCount(video, bundle); if (n == 0) return; @@ -1182,7 +1006,7 @@ void BinkDecoder::readColors(VideoFrame &video, Bundle &bundle) { } } -void BinkDecoder::readDCS(VideoFrame &video, Bundle &bundle, int startBits, bool hasSign) { +void BinkDecoder::BinkVideoTrack::readDCS(VideoFrame &video, Bundle &bundle, int startBits, bool hasSign) { uint32 length = readBundleCount(video, bundle); if (length == 0) return; @@ -1228,7 +1052,7 @@ void BinkDecoder::readDCS(VideoFrame &video, Bundle &bundle, int startBits, bool } /** Reads 8x8 block of DCT coefficients. */ -void BinkDecoder::readDCTCoeffs(VideoFrame &video, int16 *block, bool isIntra) { +void BinkDecoder::BinkVideoTrack::readDCTCoeffs(VideoFrame &video, int16 *block, bool isIntra) { int coefCount = 0; int coefIdx[64]; @@ -1326,7 +1150,7 @@ void BinkDecoder::readDCTCoeffs(VideoFrame &video, int16 *block, bool isIntra) { } /** Reads 8x8 block with residue after motion compensation. */ -void BinkDecoder::readResidue(VideoFrame &video, int16 *block, int masksCount) { +void BinkDecoder::BinkVideoTrack::readResidue(VideoFrame &video, int16 *block, int masksCount) { int nzCoeff[64]; int nzCoeffCount = 0; @@ -1417,63 +1241,170 @@ void BinkDecoder::readResidue(VideoFrame &video, int16 *block, int masksCount) { } } -float BinkDecoder::getFloat(AudioTrack &audio) { - int power = audio.bits->getBits(5); +#define A1 2896 /* (1/sqrt(2))<<12 */ +#define A2 2217 +#define A3 3784 +#define A4 -5352 - float f = ldexp((float)audio.bits->getBits(23), power - 23); +#define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ + const int a0 = (src)[s0] + (src)[s4]; \ + const int a1 = (src)[s0] - (src)[s4]; \ + const int a2 = (src)[s2] + (src)[s6]; \ + const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ + const int a4 = (src)[s5] + (src)[s3]; \ + const int a5 = (src)[s5] - (src)[s3]; \ + const int a6 = (src)[s1] + (src)[s7]; \ + const int a7 = (src)[s1] - (src)[s7]; \ + const int b0 = a4 + a6; \ + const int b1 = (A3*(a5 + a7)) >> 11; \ + const int b2 = ((A4*a5) >> 11) - b0 + b1; \ + const int b3 = (A1*(a6 - a4) >> 11) - b2; \ + const int b4 = ((A2*a7) >> 11) + b3 - b1; \ + (dest)[d0] = munge(a0+a2 +b0); \ + (dest)[d1] = munge(a1+a3-a2+b2); \ + (dest)[d2] = munge(a1-a3+a2+b3); \ + (dest)[d3] = munge(a0-a2 -b4); \ + (dest)[d4] = munge(a0-a2 +b4); \ + (dest)[d5] = munge(a1-a3+a2-b3); \ + (dest)[d6] = munge(a1+a3-a2-b2); \ + (dest)[d7] = munge(a0+a2 -b0); \ +} +/* end IDCT_TRANSFORM macro */ - if (audio.bits->getBit()) - f = -f; +#define MUNGE_NONE(x) (x) +#define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) - return f; +#define MUNGE_ROW(x) (((x) + 0x7F)>>8) +#define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src) + +static inline void IDCTCol(int16 *dest, const int16 *src) { + if ((src[8] | src[16] | src[24] | src[32] | src[40] | src[48] | src[56]) == 0) { + dest[ 0] = + dest[ 8] = + dest[16] = + dest[24] = + dest[32] = + dest[40] = + dest[48] = + dest[56] = src[0]; + } else { + IDCT_COL(dest, src); + } +} + +void BinkDecoder::BinkVideoTrack::IDCT(int16 *block) { + int i; + int16 temp[64]; + + for (i = 0; i < 8; i++) + IDCTCol(&temp[i], &block[i]); + for (i = 0; i < 8; i++) { + IDCT_ROW( (&block[8*i]), (&temp[8*i]) ); + } +} + +void BinkDecoder::BinkVideoTrack::IDCTAdd(DecodeContext &ctx, int16 *block) { + int i, j; + + IDCT(block); + byte *dest = ctx.dest; + for (i = 0; i < 8; i++, dest += ctx.pitch, block += 8) + for (j = 0; j < 8; j++) + dest[j] += block[j]; +} + +void BinkDecoder::BinkVideoTrack::IDCTPut(DecodeContext &ctx, int16 *block) { + int i; + int16 temp[64]; + for (i = 0; i < 8; i++) + IDCTCol(&temp[i], &block[i]); + for (i = 0; i < 8; i++) { + IDCT_ROW( (&ctx.dest[i*ctx.pitch]), (&temp[8*i]) ); + } +} + +BinkDecoder::BinkAudioTrack::BinkAudioTrack(BinkDecoder::AudioInfo &audio) : _audioInfo(&audio) { + _audioStream = Audio::makeQueuingAudioStream(_audioInfo->outSampleRate, _audioInfo->outChannels == 2); +} + +BinkDecoder::BinkAudioTrack::~BinkAudioTrack() { + delete _audioStream; +} + +Audio::AudioStream *BinkDecoder::BinkAudioTrack::getAudioStream() const { + return _audioStream; +} + +void BinkDecoder::BinkAudioTrack::decodePacket() { + int outSize = _audioInfo->frameLen * _audioInfo->channels; + + while (_audioInfo->bits->pos() < _audioInfo->bits->size()) { + int16 *out = (int16 *)malloc(outSize * 2); + memset(out, 0, outSize * 2); + + audioBlock(out); + + byte flags = Audio::FLAG_16BITS; + if (_audioInfo->outChannels == 2) + flags |= Audio::FLAG_STEREO; + +#ifdef SCUMM_LITTLE_ENDIAN + flags |= Audio::FLAG_LITTLE_ENDIAN; +#endif + + _audioStream->queueBuffer((byte *)out, _audioInfo->blockSize * 2, DisposeAfterUse::YES, flags); + + if (_audioInfo->bits->pos() & 0x1F) // next data block starts at a 32-byte boundary + _audioInfo->bits->skip(32 - (_audioInfo->bits->pos() & 0x1F)); + } } -void BinkDecoder::audioBlock(AudioTrack &audio, int16 *out) { - if (audio.codec == kAudioCodecDCT) - audioBlockDCT (audio); - else if (audio.codec == kAudioCodecRDFT) - audioBlockRDFT(audio); +void BinkDecoder::BinkAudioTrack::audioBlock(int16 *out) { + if (_audioInfo->codec == kAudioCodecDCT) + audioBlockDCT (); + else if (_audioInfo->codec == kAudioCodecRDFT) + audioBlockRDFT(); - floatToInt16Interleave(out, const_cast<const float **>(audio.coeffsPtr), audio.frameLen, audio.channels); + floatToInt16Interleave(out, const_cast<const float **>(_audioInfo->coeffsPtr), _audioInfo->frameLen, _audioInfo->channels); - if (!audio.first) { - int count = audio.overlapLen * audio.channels; + if (!_audioInfo->first) { + int count = _audioInfo->overlapLen * _audioInfo->channels; int shift = Common::intLog2(count); for (int i = 0; i < count; i++) { - out[i] = (audio.prevCoeffs[i] * (count - i) + out[i] * i) >> shift; + out[i] = (_audioInfo->prevCoeffs[i] * (count - i) + out[i] * i) >> shift; } } - memcpy(audio.prevCoeffs, out + audio.blockSize, audio.overlapLen * audio.channels * sizeof(*out)); + memcpy(_audioInfo->prevCoeffs, out + _audioInfo->blockSize, _audioInfo->overlapLen * _audioInfo->channels * sizeof(*out)); - audio.first = false; + _audioInfo->first = false; } -void BinkDecoder::audioBlockDCT(AudioTrack &audio) { - audio.bits->skip(2); +void BinkDecoder::BinkAudioTrack::audioBlockDCT() { + _audioInfo->bits->skip(2); - for (uint8 i = 0; i < audio.channels; i++) { - float *coeffs = audio.coeffsPtr[i]; + for (uint8 i = 0; i < _audioInfo->channels; i++) { + float *coeffs = _audioInfo->coeffsPtr[i]; - readAudioCoeffs(audio, coeffs); + readAudioCoeffs(coeffs); coeffs[0] /= 0.5; - audio.dct->calc(coeffs); + _audioInfo->dct->calc(coeffs); - for (uint32 j = 0; j < audio.frameLen; j++) - coeffs[j] *= (audio.frameLen / 2.0); + for (uint32 j = 0; j < _audioInfo->frameLen; j++) + coeffs[j] *= (_audioInfo->frameLen / 2.0); } } -void BinkDecoder::audioBlockRDFT(AudioTrack &audio) { - for (uint8 i = 0; i < audio.channels; i++) { - float *coeffs = audio.coeffsPtr[i]; +void BinkDecoder::BinkAudioTrack::audioBlockRDFT() { + for (uint8 i = 0; i < _audioInfo->channels; i++) { + float *coeffs = _audioInfo->coeffsPtr[i]; - readAudioCoeffs(audio, coeffs); + readAudioCoeffs(coeffs); - audio.rdft->calc(coeffs); + _audioInfo->rdft->calc(coeffs); } } @@ -1481,56 +1412,56 @@ static const uint8 rleLengthTab[16] = { 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 32, 64 }; -void BinkDecoder::readAudioCoeffs(AudioTrack &audio, float *coeffs) { - coeffs[0] = getFloat(audio) * audio.root; - coeffs[1] = getFloat(audio) * audio.root; +void BinkDecoder::BinkAudioTrack::readAudioCoeffs(float *coeffs) { + coeffs[0] = getFloat() * _audioInfo->root; + coeffs[1] = getFloat() * _audioInfo->root; float quant[25]; - for (uint32 i = 0; i < audio.bandCount; i++) { - int value = audio.bits->getBits(8); + for (uint32 i = 0; i < _audioInfo->bandCount; i++) { + int value = _audioInfo->bits->getBits(8); // 0.066399999 / log10(M_E) - quant[i] = exp(MIN(value, 95) * 0.15289164787221953823f) * audio.root; + quant[i] = exp(MIN(value, 95) * 0.15289164787221953823f) * _audioInfo->root; } float q = 0.0; // Find band (k) int k; - for (k = 0; audio.bands[k] < 1; k++) + for (k = 0; _audioInfo->bands[k] < 1; k++) q = quant[k]; // Parse coefficients uint32 i = 2; - while (i < audio.frameLen) { + while (i < _audioInfo->frameLen) { uint32 j = 0; - if (audio.bits->getBit()) - j = i + rleLengthTab[audio.bits->getBits(4)] * 8; + if (_audioInfo->bits->getBit()) + j = i + rleLengthTab[_audioInfo->bits->getBits(4)] * 8; else j = i + 8; - j = MIN(j, audio.frameLen); + j = MIN(j, _audioInfo->frameLen); - int width = audio.bits->getBits(4); + int width = _audioInfo->bits->getBits(4); if (width == 0) { memset(coeffs + i, 0, (j - i) * sizeof(*coeffs)); i = j; - while (audio.bands[k] * 2 < i) + while (_audioInfo->bands[k] * 2 < i) q = quant[k++]; } else { while (i < j) { - if (audio.bands[k] * 2 == i) + if (_audioInfo->bands[k] * 2 == i) q = quant[k++]; - int coeff = audio.bits->getBits(width); + int coeff = _audioInfo->bits->getBits(width); if (coeff) { - if (audio.bits->getBit()) + if (_audioInfo->bits->getBit()) coeffs[i] = -q * coeff; else coeffs[i] = q * coeff; @@ -1548,10 +1479,10 @@ void BinkDecoder::readAudioCoeffs(AudioTrack &audio, float *coeffs) { } static inline int floatToInt16One(float src) { - return (int16) CLIP<int>((int) floor(src + 0.5), -32768, 32767); + return (int16)CLIP<int>((int)floor(src + 0.5), -32768, 32767); } -void BinkDecoder::floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels) { +void BinkDecoder::BinkAudioTrack::floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels) { if (channels == 2) { for (uint32 i = 0; i < length; i++) { dst[2 * i ] = floatToInt16One(src[0][i]); @@ -1564,97 +1495,84 @@ void BinkDecoder::floatToInt16Interleave(int16 *dst, const float **src, uint32 l } } -#define A1 2896 /* (1/sqrt(2))<<12 */ -#define A2 2217 -#define A3 3784 -#define A4 -5352 +float BinkDecoder::BinkAudioTrack::getFloat() { + int power = _audioInfo->bits->getBits(5); -#define IDCT_TRANSFORM(dest,s0,s1,s2,s3,s4,s5,s6,s7,d0,d1,d2,d3,d4,d5,d6,d7,munge,src) {\ - const int a0 = (src)[s0] + (src)[s4]; \ - const int a1 = (src)[s0] - (src)[s4]; \ - const int a2 = (src)[s2] + (src)[s6]; \ - const int a3 = (A1*((src)[s2] - (src)[s6])) >> 11; \ - const int a4 = (src)[s5] + (src)[s3]; \ - const int a5 = (src)[s5] - (src)[s3]; \ - const int a6 = (src)[s1] + (src)[s7]; \ - const int a7 = (src)[s1] - (src)[s7]; \ - const int b0 = a4 + a6; \ - const int b1 = (A3*(a5 + a7)) >> 11; \ - const int b2 = ((A4*a5) >> 11) - b0 + b1; \ - const int b3 = (A1*(a6 - a4) >> 11) - b2; \ - const int b4 = ((A2*a7) >> 11) + b3 - b1; \ - (dest)[d0] = munge(a0+a2 +b0); \ - (dest)[d1] = munge(a1+a3-a2+b2); \ - (dest)[d2] = munge(a1-a3+a2+b3); \ - (dest)[d3] = munge(a0-a2 -b4); \ - (dest)[d4] = munge(a0-a2 +b4); \ - (dest)[d5] = munge(a1-a3+a2-b3); \ - (dest)[d6] = munge(a1+a3-a2-b2); \ - (dest)[d7] = munge(a0+a2 -b0); \ + float f = ldexp((float)_audioInfo->bits->getBits(23), power - 23); + + if (_audioInfo->bits->getBit()) + f = -f; + + return f; } -/* end IDCT_TRANSFORM macro */ -#define MUNGE_NONE(x) (x) -#define IDCT_COL(dest,src) IDCT_TRANSFORM(dest,0,8,16,24,32,40,48,56,0,8,16,24,32,40,48,56,MUNGE_NONE,src) +void BinkDecoder::initAudioTrack(AudioInfo &audio) { + audio.sampleCount = 0; + audio.bits = 0; -#define MUNGE_ROW(x) (((x) + 0x7F)>>8) -#define IDCT_ROW(dest,src) IDCT_TRANSFORM(dest,0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7,MUNGE_ROW,src) + audio.channels = ((audio.flags & kAudioFlagStereo) != 0) ? 2 : 1; + audio.codec = ((audio.flags & kAudioFlagDCT ) != 0) ? kAudioCodecDCT : kAudioCodecRDFT; -static inline void IDCTCol(int16 *dest, const int16 *src) -{ - if ((src[8] | src[16] | src[24] | src[32] | src[40] | src[48] | src[56]) == 0) { - dest[ 0] = - dest[ 8] = - dest[16] = - dest[24] = - dest[32] = - dest[40] = - dest[48] = - dest[56] = src[0]; - } else { - IDCT_COL(dest, src); - } -} + if (audio.channels > kAudioChannelsMax) + error("Too many audio channels: %d", audio.channels); -void BinkDecoder::IDCT(int16 *block) { - int i; - int16 temp[64]; + uint32 frameLenBits; + // Calculate frame length + if (audio.sampleRate < 22050) + frameLenBits = 9; + else if(audio.sampleRate < 44100) + frameLenBits = 10; + else + frameLenBits = 11; - for (i = 0; i < 8; i++) - IDCTCol(&temp[i], &block[i]); - for (i = 0; i < 8; i++) { - IDCT_ROW( (&block[8*i]), (&temp[8*i]) ); - } -} + audio.frameLen = 1 << frameLenBits; -void BinkDecoder::IDCTAdd(DecodeContext &ctx, int16 *block) { - int i, j; + audio.outSampleRate = audio.sampleRate; + audio.outChannels = audio.channels; - IDCT(block); - byte *dest = ctx.dest; - for (i = 0; i < 8; i++, dest += ctx.pitch, block += 8) - for (j = 0; j < 8; j++) - dest[j] += block[j]; -} + if (audio.codec == kAudioCodecRDFT) { + // RDFT audio already interleaves the samples correctly -void BinkDecoder::IDCTPut(DecodeContext &ctx, int16 *block) { - int i; - int16 temp[64]; - for (i = 0; i < 8; i++) - IDCTCol(&temp[i], &block[i]); - for (i = 0; i < 8; i++) { - IDCT_ROW( (&ctx.dest[i*ctx.pitch]), (&temp[8*i]) ); + if (audio.channels == 2) + frameLenBits++; + + audio.sampleRate *= audio.channels; + audio.frameLen *= audio.channels; + audio.channels = 1; } -} -void BinkDecoder::updateVolume() { - if (g_system->getMixer()->isSoundHandleActive(_audioHandle)) - g_system->getMixer()->setChannelVolume(_audioHandle, getVolume()); -} + audio.overlapLen = audio.frameLen / 16; + audio.blockSize = (audio.frameLen - audio.overlapLen) * audio.channels; + audio.root = 2.0 / sqrt((double)audio.frameLen); + + uint32 sampleRateHalf = (audio.sampleRate + 1) / 2; + + // Calculate number of bands + for (audio.bandCount = 1; audio.bandCount < 25; audio.bandCount++) + if (sampleRateHalf <= binkCriticalFreqs[audio.bandCount - 1]) + break; + + audio.bands = new uint32[audio.bandCount + 1]; + + // Populate bands + audio.bands[0] = 1; + for (uint32 i = 1; i < audio.bandCount; i++) + audio.bands[i] = binkCriticalFreqs[i - 1] * (audio.frameLen / 2) / sampleRateHalf; + audio.bands[audio.bandCount] = audio.frameLen / 2; + + audio.first = true; + + for (uint8 i = 0; i < audio.channels; i++) + audio.coeffsPtr[i] = audio.coeffs + i * audio.frameLen; + + audio.codec = ((audio.flags & kAudioFlagDCT) != 0) ? kAudioCodecDCT : kAudioCodecRDFT; + + if (audio.codec == kAudioCodecRDFT) + audio.rdft = new Common::RDFT(frameLenBits, Common::RDFT::DFT_C2R); + else if (audio.codec == kAudioCodecDCT) + audio.dct = new Common::DCT(frameLenBits, Common::DCT::DCT_III); -void BinkDecoder::updateBalance() { - if (g_system->getMixer()->isSoundHandleActive(_audioHandle)) - g_system->getMixer()->setChannelBalance(_audioHandle, getBalance()); + addTrack(new BinkAudioTrack(audio)); } } // End of namespace Video diff --git a/video/bink_decoder.h b/video/bink_decoder.h index a5e1b10270..836238ce99 100644 --- a/video/bink_decoder.h +++ b/video/bink_decoder.h @@ -31,22 +31,27 @@ #ifndef VIDEO_BINK_DECODER_H #define VIDEO_BINK_DECODER_H -#include "audio/audiostream.h" -#include "audio/mixer.h" #include "common/array.h" #include "common/rational.h" -#include "graphics/surface.h" - #include "video/video_decoder.h" +namespace Audio { +class AudioStream; +class QueuingAudioStream; +} + namespace Common { - class SeekableReadStream; - class BitStream; - class Huffman; +class SeekableReadStream; +class BitStream; +class Huffman; - class RDFT; - class DCT; +class RDFT; +class DCT; +} + +namespace Graphics { +struct Surface; } namespace Video { @@ -57,92 +62,28 @@ namespace Video { * Video decoder used in engines: * - scumm (he) */ -class BinkDecoder : public FixedRateVideoDecoder { +class BinkDecoder : public AdvancedVideoDecoder { public: BinkDecoder(); ~BinkDecoder(); - // VideoDecoder API bool loadStream(Common::SeekableReadStream *stream); void close(); - bool isVideoLoaded() const { return _bink != 0; } - uint16 getWidth() const { return _surface.w; } - uint16 getHeight() const { return _surface.h; } - Graphics::PixelFormat getPixelFormat() const { return _surface.format; } - uint32 getFrameCount() const { return _frames.size(); } - uint32 getTime() const; - const Graphics::Surface *decodeNextFrame(); - - // FixedRateVideoDecoder - Common::Rational getFrameRate() const { return _frameRate; } - - // Bink specific - bool loadStream(Common::SeekableReadStream *stream, const Graphics::PixelFormat &format); protected: - // VideoDecoder API - void updateVolume(); - void updateBalance(); + void readNextPacket(); +private: static const int kAudioChannelsMax = 2; static const int kAudioBlockSizeMax = (kAudioChannelsMax << 11); - /** IDs for different data types used in Bink video codec. */ - enum Source { - kSourceBlockTypes = 0, ///< 8x8 block types. - kSourceSubBlockTypes , ///< 16x16 block types (a subset of 8x8 block types). - kSourceColors , ///< Pixel values used for different block types. - kSourcePattern , ///< 8-bit values for 2-color pattern fill. - kSourceXOff , ///< X components of motion value. - kSourceYOff , ///< Y components of motion value. - kSourceIntraDC , ///< DC values for intrablocks with DCT. - kSourceInterDC , ///< DC values for interblocks with DCT. - kSourceRun , ///< Run lengths for special fill block. - - kSourceMAX - }; - - /** Bink video block types. */ - enum BlockType { - kBlockSkip = 0, ///< Skipped block. - kBlockScaled , ///< Block has size 16x16. - kBlockMotion , ///< Block is copied from previous frame with some offset. - kBlockRun , ///< Block is composed from runs of colors with custom scan order. - kBlockResidue , ///< Motion block with some difference added. - kBlockIntra , ///< Intra DCT block. - kBlockFill , ///< Block is filled with single color. - kBlockInter , ///< Motion block with DCT applied to the difference. - kBlockPattern , ///< Block is filled with two colors following custom pattern. - kBlockRaw ///< Uncoded 8x8 block. - }; - - /** Data structure for decoding and tranlating Huffman'd data. */ - struct Huffman { - int index; ///< Index of the Huffman codebook to use. - byte symbols[16]; ///< Huffman symbol => Bink symbol tranlation list. - }; - - /** Data structure used for decoding a single Bink data type. */ - struct Bundle { - int countLengths[2]; ///< Lengths of number of entries to decode (in bits). - int countLength; ///< Length of number of entries to decode (in bits) for the current plane. - - Huffman huffman; ///< Huffman codebook. - - byte *data; ///< Buffer for decoded symbols. - byte *dataEnd; ///< Buffer end. - - byte *curDec; ///< Pointer to the data that wasn't yet decoded. - byte *curPtr; ///< Pointer to the data that wasn't yet read. - }; - enum AudioCodec { kAudioCodecDCT, kAudioCodecRDFT }; /** An audio track. */ - struct AudioTrack { + struct AudioInfo { uint16 flags; uint32 sampleRate; @@ -177,8 +118,8 @@ protected: Common::RDFT *rdft; Common::DCT *dct; - AudioTrack(); - ~AudioTrack(); + AudioInfo(); + ~AudioInfo(); }; /** A video frame. */ @@ -194,149 +135,218 @@ protected: ~VideoFrame(); }; - /** A decoder state. */ - struct DecodeContext { - VideoFrame *video; + class BinkVideoTrack : public FixedRateVideoTrack { + public: + BinkVideoTrack(uint32 width, uint32 height, const Graphics::PixelFormat &format, uint32 frameCount, const Common::Rational &frameRate, bool swapPlanes, bool hasAlpha, uint32 id); + ~BinkVideoTrack(); + + uint16 getWidth() const { return _surface.w; } + uint16 getHeight() const { return _surface.h; } + Graphics::PixelFormat getPixelFormat() const { return _surface.format; } + int getCurFrame() const { return _curFrame; } + int getFrameCount() const { return _frameCount; } + const Graphics::Surface *decodeNextFrame() { return &_surface; } + + /** Decode a video packet. */ + void decodePacket(VideoFrame &frame); + + protected: + Common::Rational getFrameRate() const { return _frameRate; } - uint32 planeIdx; + private: + /** A decoder state. */ + struct DecodeContext { + VideoFrame *video; + + uint32 planeIdx; - uint32 blockX; - uint32 blockY; + uint32 blockX; + uint32 blockY; - byte *dest; - byte *prev; + byte *dest; + byte *prev; - byte *destStart, *destEnd; - byte *prevStart, *prevEnd; + byte *destStart, *destEnd; + byte *prevStart, *prevEnd; - uint32 pitch; + uint32 pitch; - int coordMap[64]; - int coordScaledMap1[64]; - int coordScaledMap2[64]; - int coordScaledMap3[64]; - int coordScaledMap4[64]; + int coordMap[64]; + int coordScaledMap1[64]; + int coordScaledMap2[64]; + int coordScaledMap3[64]; + int coordScaledMap4[64]; + }; + + /** IDs for different data types used in Bink video codec. */ + enum Source { + kSourceBlockTypes = 0, ///< 8x8 block types. + kSourceSubBlockTypes , ///< 16x16 block types (a subset of 8x8 block types). + kSourceColors , ///< Pixel values used for different block types. + kSourcePattern , ///< 8-bit values for 2-color pattern fill. + kSourceXOff , ///< X components of motion value. + kSourceYOff , ///< Y components of motion value. + kSourceIntraDC , ///< DC values for intrablocks with DCT. + kSourceInterDC , ///< DC values for interblocks with DCT. + kSourceRun , ///< Run lengths for special fill block. + + kSourceMAX + }; + + /** Bink video block types. */ + enum BlockType { + kBlockSkip = 0, ///< Skipped block. + kBlockScaled , ///< Block has size 16x16. + kBlockMotion , ///< Block is copied from previous frame with some offset. + kBlockRun , ///< Block is composed from runs of colors with custom scan order. + kBlockResidue , ///< Motion block with some difference added. + kBlockIntra , ///< Intra DCT block. + kBlockFill , ///< Block is filled with single color. + kBlockInter , ///< Motion block with DCT applied to the difference. + kBlockPattern , ///< Block is filled with two colors following custom pattern. + kBlockRaw ///< Uncoded 8x8 block. + }; + + /** Data structure for decoding and tranlating Huffman'd data. */ + struct Huffman { + int index; ///< Index of the Huffman codebook to use. + byte symbols[16]; ///< Huffman symbol => Bink symbol tranlation list. + }; + + /** Data structure used for decoding a single Bink data type. */ + struct Bundle { + int countLengths[2]; ///< Lengths of number of entries to decode (in bits). + int countLength; ///< Length of number of entries to decode (in bits) for the current plane. + + Huffman huffman; ///< Huffman codebook. + + byte *data; ///< Buffer for decoded symbols. + byte *dataEnd; ///< Buffer end. + + byte *curDec; ///< Pointer to the data that wasn't yet decoded. + byte *curPtr; ///< Pointer to the data that wasn't yet read. + }; + + int _curFrame; + int _frameCount; + + Graphics::Surface _surface; + + uint32 _id; ///< The BIK FourCC. + + bool _hasAlpha; ///< Do video frames have alpha? + bool _swapPlanes; ///< Are the planes ordered (A)YVU instead of (A)YUV? + + Common::Rational _frameRate; + + Bundle _bundles[kSourceMAX]; ///< Bundles for decoding all data types. + + Common::Huffman *_huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding. + + /** Huffman codebooks to use for decoding high nibbles in color data types. */ + Huffman _colHighHuffman[16]; + /** Value of the last decoded high nibble in color data types. */ + int _colLastVal; + + byte *_curPlanes[4]; ///< The 4 color planes, YUVA, current frame. + byte *_oldPlanes[4]; ///< The 4 color planes, YUVA, last frame. + + /** Initialize the bundles. */ + void initBundles(); + /** Deinitialize the bundles. */ + void deinitBundles(); + + /** Initialize the Huffman decoders. */ + void initHuffman(); + + /** Decode a plane. */ + void decodePlane(VideoFrame &video, int planeIdx, bool isChroma); + + /** Read/Initialize a bundle for decoding a plane. */ + void readBundle(VideoFrame &video, Source source); + + /** Read the symbols for a Huffman code. */ + void readHuffman(VideoFrame &video, Huffman &huffman); + /** Merge two Huffman symbol lists. */ + void mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size); + + /** Read and translate a symbol out of a Huffman code. */ + byte getHuffmanSymbol(VideoFrame &video, Huffman &huffman); + + /** Get a direct value out of a bundle. */ + int32 getBundleValue(Source source); + /** Read a count value out of a bundle. */ + uint32 readBundleCount(VideoFrame &video, Bundle &bundle); + + // Handle the block types + void blockSkip (DecodeContext &ctx); + void blockScaledSkip (DecodeContext &ctx); + void blockScaledRun (DecodeContext &ctx); + void blockScaledIntra (DecodeContext &ctx); + void blockScaledFill (DecodeContext &ctx); + void blockScaledPattern(DecodeContext &ctx); + void blockScaledRaw (DecodeContext &ctx); + void blockScaled (DecodeContext &ctx); + void blockMotion (DecodeContext &ctx); + void blockRun (DecodeContext &ctx); + void blockResidue (DecodeContext &ctx); + void blockIntra (DecodeContext &ctx); + void blockFill (DecodeContext &ctx); + void blockInter (DecodeContext &ctx); + void blockPattern (DecodeContext &ctx); + void blockRaw (DecodeContext &ctx); + + // Read the bundles + void readRuns (VideoFrame &video, Bundle &bundle); + void readMotionValues(VideoFrame &video, Bundle &bundle); + void readBlockTypes (VideoFrame &video, Bundle &bundle); + void readPatterns (VideoFrame &video, Bundle &bundle); + void readColors (VideoFrame &video, Bundle &bundle); + void readDCS (VideoFrame &video, Bundle &bundle, int startBits, bool hasSign); + void readDCTCoeffs (VideoFrame &video, int16 *block, bool isIntra); + void readResidue (VideoFrame &video, int16 *block, int masksCount); + + // Bink video IDCT + void IDCT(int16 *block); + void IDCTPut(DecodeContext &ctx, int16 *block); + void IDCTAdd(DecodeContext &ctx, int16 *block); }; - Common::SeekableReadStream *_bink; + class BinkAudioTrack : public AudioTrack { + public: + BinkAudioTrack(AudioInfo &audio); + ~BinkAudioTrack(); + + /** Decode an audio packet. */ + void decodePacket(); - uint32 _id; ///< The BIK FourCC. + protected: + Audio::AudioStream *getAudioStream() const; - Common::Rational _frameRate; + private: + AudioInfo *_audioInfo; + Audio::QueuingAudioStream *_audioStream; - Graphics::Surface _surface; + float getFloat(); - Audio::SoundHandle _audioHandle; - Audio::QueuingAudioStream *_audioStream; - int32 _audioStartOffset; + /** Decode an audio block. */ + void audioBlock(int16 *out); + /** Decode a DCT'd audio block. */ + void audioBlockDCT(); + /** Decode a RDFT'd audio block. */ + void audioBlockRDFT(); - uint32 _videoFlags; ///< Video frame features. + void readAudioCoeffs(float *coeffs); - bool _hasAlpha; ///< Do video frames have alpha? - bool _swapPlanes; ///< Are the planes ordered (A)YVU instead of (A)YUV? + static void floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels); + }; + + Common::SeekableReadStream *_bink; - Common::Array<AudioTrack> _audioTracks; ///< All audio tracks. + Common::Array<AudioInfo> _audioTracks; ///< All audio tracks. Common::Array<VideoFrame> _frames; ///< All video frames. - uint32 _audioTrack; ///< Audio track to use. - - Common::Huffman *_huffman[16]; ///< The 16 Huffman codebooks used in Bink decoding. - - Bundle _bundles[kSourceMAX]; ///< Bundles for decoding all data types. - - /** Huffman codebooks to use for decoding high nibbles in color data types. */ - Huffman _colHighHuffman[16]; - /** Value of the last decoded high nibble in color data types. */ - int _colLastVal; - - byte *_curPlanes[4]; ///< The 4 color planes, YUVA, current frame. - byte *_oldPlanes[4]; ///< The 4 color planes, YUVA, last frame. - - - /** Initialize the bundles. */ - void initBundles(); - /** Deinitialize the bundles. */ - void deinitBundles(); - - /** Initialize the Huffman decoders. */ - void initHuffman(); - - /** Decode an audio packet. */ - void audioPacket(AudioTrack &audio); - /** Decode a video packet. */ - virtual void videoPacket(VideoFrame &video); - - /** Decode a plane. */ - void decodePlane(VideoFrame &video, int planeIdx, bool isChroma); - - /** Read/Initialize a bundle for decoding a plane. */ - void readBundle(VideoFrame &video, Source source); - - /** Read the symbols for a Huffman code. */ - void readHuffman(VideoFrame &video, Huffman &huffman); - /** Merge two Huffman symbol lists. */ - void mergeHuffmanSymbols(VideoFrame &video, byte *dst, const byte *src, int size); - - /** Read and translate a symbol out of a Huffman code. */ - byte getHuffmanSymbol(VideoFrame &video, Huffman &huffman); - - /** Get a direct value out of a bundle. */ - int32 getBundleValue(Source source); - /** Read a count value out of a bundle. */ - uint32 readBundleCount(VideoFrame &video, Bundle &bundle); - - // Handle the block types - void blockSkip (DecodeContext &ctx); - void blockScaledSkip (DecodeContext &ctx); - void blockScaledRun (DecodeContext &ctx); - void blockScaledIntra (DecodeContext &ctx); - void blockScaledFill (DecodeContext &ctx); - void blockScaledPattern(DecodeContext &ctx); - void blockScaledRaw (DecodeContext &ctx); - void blockScaled (DecodeContext &ctx); - void blockMotion (DecodeContext &ctx); - void blockRun (DecodeContext &ctx); - void blockResidue (DecodeContext &ctx); - void blockIntra (DecodeContext &ctx); - void blockFill (DecodeContext &ctx); - void blockInter (DecodeContext &ctx); - void blockPattern (DecodeContext &ctx); - void blockRaw (DecodeContext &ctx); - - // Read the bundles - void readRuns (VideoFrame &video, Bundle &bundle); - void readMotionValues(VideoFrame &video, Bundle &bundle); - void readBlockTypes (VideoFrame &video, Bundle &bundle); - void readPatterns (VideoFrame &video, Bundle &bundle); - void readColors (VideoFrame &video, Bundle &bundle); - void readDCS (VideoFrame &video, Bundle &bundle, int startBits, bool hasSign); - void readDCTCoeffs (VideoFrame &video, int16 *block, bool isIntra); - void readResidue (VideoFrame &video, int16 *block, int masksCount); - - void initAudioTrack(AudioTrack &audio); - - float getFloat(AudioTrack &audio); - - /** Decode an audio block. */ - void audioBlock (AudioTrack &audio, int16 *out); - /** Decode a DCT'd audio block. */ - void audioBlockDCT (AudioTrack &audio); - /** Decode a RDFT'd audio block. */ - void audioBlockRDFT(AudioTrack &audio); - - void readAudioCoeffs(AudioTrack &audio, float *coeffs); - - void floatToInt16Interleave(int16 *dst, const float **src, uint32 length, uint8 channels); - - // Bink video IDCT - void IDCT(int16 *block); - void IDCTPut(DecodeContext &ctx, int16 *block); - void IDCTAdd(DecodeContext &ctx, int16 *block); - - /** Start playing the audio track */ - void startAudio(); - /** Stop playing the audio track */ - void stopAudio(); + void initAudioTrack(AudioInfo &audio); }; } // End of namespace Video |