diff options
| author | D G Turner | 2012-08-04 14:41:17 +0100 | 
|---|---|---|
| committer | D G Turner | 2012-08-04 18:36:13 +0100 | 
| commit | b79221729bd06a737bf140bf7cb5c0ff2a578681 (patch) | |
| tree | f8614767eb6264119c7a65c641c0c96ca1def1a2 | |
| parent | 52a1a6e60b418f9f0bcca9b12ef631f6f8176786 (diff) | |
| download | scummvm-rg350-b79221729bd06a737bf140bf7cb5c0ff2a578681.tar.gz scummvm-rg350-b79221729bd06a737bf140bf7cb5c0ff2a578681.tar.bz2 scummvm-rg350-b79221729bd06a737bf140bf7cb5c0ff2a578681.zip  | |
AUDIO: Fix DVI ADPCM to work with Mono streams using odd sized buffers.
| -rw-r--r-- | audio/decoders/adpcm.cpp | 16 | ||||
| -rw-r--r-- | audio/decoders/adpcm_intern.h | 6 | 
2 files changed, 16 insertions, 6 deletions
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp index 535652a0b3..5c96d5245a 100644 --- a/audio/decoders/adpcm.cpp +++ b/audio/decoders/adpcm.cpp @@ -117,13 +117,19 @@ int DVI_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] = decodeIMA((data >> 4) & 0x0f, 0); +			_decodedSamples[1] = decodeIMA((data >> 0) & 0x0f, _channels == 2 ? 1 : 0); +			_decodedSampleCount = 2; +		} -	for (samples = 0; samples < numSamples && !_stream->eos() && _stream->pos() < _endpos; samples += 2) { -		data = _stream->readByte(); -		buffer[samples] = decodeIMA((data >> 4) & 0x0f); -		buffer[samples + 1] = decodeIMA(data & 0x0f, _channels == 2 ? 1 : 0); +		// (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 31747aabaf..537ae023ef 100644 --- a/audio/decoders/adpcm_intern.h +++ b/audio/decoders/adpcm_intern.h @@ -108,9 +108,13 @@ public:  class DVI_ADPCMStream : public Ima_ADPCMStream {  public:  	DVI_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, int rate, int channels, uint32 blockAlign) -		: Ima_ADPCMStream(stream, disposeAfterUse, size, rate, channels, blockAlign) {} +		: Ima_ADPCMStream(stream, disposeAfterUse, size, rate, channels, blockAlign) { _decodedSampleCount = 0; }  	virtual int readBuffer(int16 *buffer, const int numSamples); + +private: +	uint8 _decodedSampleCount; +	int16 _decodedSamples[2];  };  class Apple_ADPCMStream : public Ima_ADPCMStream {  | 
