[Scummvm-cvs-logs] scummvm master -> 9382dab811428af7a3329deebc3449c6ab8b83c8
eriktorbjorn
eriktorbjorn at telia.com
Wed Jul 6 20:54:20 CEST 2016
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
9382dab811 AUDIO: Fix audio corruption in MS ADPCM decoder
Commit: 9382dab811428af7a3329deebc3449c6ab8b83c8
https://github.com/scummvm/scummvm/commit/9382dab811428af7a3329deebc3449c6ab8b83c8
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2016-07-06T20:51:28+02:00
Commit Message:
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.
Changed paths:
audio/decoders/adpcm.cpp
audio/decoders/adpcm_intern.h
diff --git a/audio/decoders/adpcm.cpp b/audio/decoders/adpcm.cpp
index fd97d5d..ffb61a4 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 3a2af91..f4a708c 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];
};
More information about the Scummvm-git-logs
mailing list