diff options
author | D G Turner | 2012-08-04 18:38:12 +0100 |
---|---|---|
committer | D G Turner | 2012-08-04 18:38:12 +0100 |
commit | 9c47fdae293e05888d3b4ec45fd4b374d1022c0b (patch) | |
tree | bdb4a3a93598938bd702ba1a8be17a500b61d808 /audio/decoders | |
parent | b79221729bd06a737bf140bf7cb5c0ff2a578681 (diff) | |
download | scummvm-rg350-9c47fdae293e05888d3b4ec45fd4b374d1022c0b.tar.gz scummvm-rg350-9c47fdae293e05888d3b4ec45fd4b374d1022c0b.tar.bz2 scummvm-rg350-9c47fdae293e05888d3b4ec45fd4b374d1022c0b.zip |
AUDIO: Fix Oki ADPCM to work with Mono streams using odd sized buffers.
Diffstat (limited to 'audio/decoders')
-rw-r--r-- | audio/decoders/adpcm.cpp | 16 | ||||
-rw-r--r-- | audio/decoders/adpcm_intern.h | 4 |
2 files changed, 15 insertions, 5 deletions
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp index 5c96d5245a..e7297423f6 100644 --- a/audio/decoders/adpcm.cpp +++ b/audio/decoders/adpcm.cpp @@ -71,13 +71,19 @@ int Oki_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) { int samples; byte data; - assert(numSamples % 2 == 0); + for (samples = 0; samples < numSamples && !_stream->eos() && (_stream->pos() < _endpos); samples++) { + if (_decodedSampleCount == 0) { + data = _stream->readByte(); + _decodedSamples[0] = decodeOKI((data >> 4) & 0x0f); + _decodedSamples[1] = decodeOKI((data >> 0) & 0x0f); + _decodedSampleCount = 2; + } - for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { - data = _stream->readByte(); - buffer[samples] = decodeOKI((data >> 4) & 0x0f); - buffer[samples + 1] = decodeOKI(data & 0x0f); + // (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2 + buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)]; + _decodedSampleCount--; } + return samples; } diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h index 537ae023ef..423c4af267 100644 --- a/audio/decoders/adpcm_intern.h +++ b/audio/decoders/adpcm_intern.h @@ -89,6 +89,10 @@ public: protected: int16 decodeOKI(byte); + +private: + uint8 _decodedSampleCount; + int16 _decodedSamples[2]; }; class Ima_ADPCMStream : public ADPCMStream { |