aboutsummaryrefslogtreecommitdiff
path: root/audio
diff options
context:
space:
mode:
authorTorbjörn Andersson2016-07-06 20:51:28 +0200
committerTorbjörn Andersson2016-07-06 20:51:28 +0200
commit9382dab811428af7a3329deebc3449c6ab8b83c8 (patch)
tree458678d7ca56a953790a792602e85fffac735422 /audio
parent20ccd3affcbefb6d1bd998c99b57a783266fb879 (diff)
downloadscummvm-rg350-9382dab811428af7a3329deebc3449c6ab8b83c8.tar.gz
scummvm-rg350-9382dab811428af7a3329deebc3449c6ab8b83c8.tar.bz2
scummvm-rg350-9382dab811428af7a3329deebc3449c6ab8b83c8.zip
AUDIO: Fix audio corruption in MS ADPCM decoder
Since _decodedSamples[] is filled with either 2 or 4 samples, we can't use 1 - (count - 1) to "ensure that acts as a FIFO". When we have 4 samples, that index will become negative, putting uninitialized data into the buffer. We could still use a similar trick, but I think it's much clearer to use an index variable like this. We need an addition variable either way.
Diffstat (limited to 'audio')
-rw-r--r--audio/decoders/adpcm.cpp5
-rw-r--r--audio/decoders/adpcm_intern.h2
2 files changed, 5 insertions, 2 deletions
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index fd97d5d109..ffb61a49c0 100644
--- a/audio/decoders/adpcm.cpp
+++ b/audio/decoders/adpcm.cpp
@@ -320,10 +320,11 @@ int MS_ADPCMStream::readBuffer(int16 *buffer, const int numSamples) {
_decodedSamples[_decodedSampleCount++] = decodeMS(&_status.ch[0], (data >> 4) & 0x0f);
_decodedSamples[_decodedSampleCount++] = decodeMS(&_status.ch[_channels - 1], data & 0x0f);
}
+ _decodedSampleIndex = 0;
}
- // (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2
- buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)];
+ // _decodedSamples acts as a FIFO of depth 2 or 4;
+ buffer[samples] = _decodedSamples[_decodedSampleIndex++];
_decodedSampleCount--;
}
diff --git a/audio/decoders/adpcm_intern.h b/audio/decoders/adpcm_intern.h
index 3a2af91c90..f4a708c3fc 100644
--- a/audio/decoders/adpcm_intern.h
+++ b/audio/decoders/adpcm_intern.h
@@ -209,6 +209,7 @@ public:
error("MS_ADPCMStream(): blockAlign isn't specified for MS ADPCM");
memset(&_status, 0, sizeof(_status));
_decodedSampleCount = 0;
+ _decodedSampleIndex = 0;
}
virtual bool endOfData() const { return (_stream->eos() || _stream->pos() >= _endpos) && (_decodedSampleCount == 0); }
@@ -220,6 +221,7 @@ protected:
private:
uint8 _decodedSampleCount;
+ uint8 _decodedSampleIndex;
int16 _decodedSamples[4];
};