[Scummvm-git-logs] scummvm master -> e53e1e70d4affdd6620f9d3ea8ff5c2bca9dbe90
digitall
noreply at scummvm.org
Thu Mar 31 01:11:01 UTC 2022
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:
e53e1e70d4 LASTEXPRESS: Fix Engine Specific ADPCM to work using odd sized buffers
Commit: e53e1e70d4affdd6620f9d3ea8ff5c2bca9dbe90
https://github.com/scummvm/scummvm/commit/e53e1e70d4affdd6620f9d3ea8ff5c2bca9dbe90
Author: D G Turner (digitall at scummvm.org)
Date: 2022-03-31T02:09:57+01:00
Commit Message:
LASTEXPRESS: Fix Engine Specific ADPCM to work using odd sized buffers
Changed paths:
engines/lastexpress/data/snd.cpp
diff --git a/engines/lastexpress/data/snd.cpp b/engines/lastexpress/data/snd.cpp
index 5a594a5a740..7d48e563669 100644
--- a/engines/lastexpress/data/snd.cpp
+++ b/engines/lastexpress/data/snd.cpp
@@ -350,6 +350,7 @@ class LastExpress_ADPCMStream : public Audio::ADPCMStream {
public:
LastExpress_ADPCMStream(Common::SeekableReadStream *stream, DisposeAfterUse::Flag disposeAfterUse, uint32 size, uint32 blockSize, uint32 volume, bool looped) :
Audio::ADPCMStream(stream, disposeAfterUse, size, 44100, 1, blockSize) {
+ _decodedSampleCount = 0;
_currentVolume = 0;
_nextVolume = volume;
_smoothChangeTarget = volume;
@@ -369,12 +370,6 @@ public:
int readBuffer(int16 *buffer, const int numSamples) override {
int samples = 0;
- // Temporary data
- int step = 0;
- int sample = 0;
- byte idx = 0;
-
- assert(numSamples % 2 == 0);
while (_running && samples < numSamples) {
if (Audio::ADPCMStream::endOfData()) {
@@ -403,21 +398,32 @@ public:
_currentVolume = _nextVolume;
}
- for (; samples < numSamples && _blockPos[0] < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples += 2) {
- byte data = _stream->readByte();
- _blockPos[0]++;
-
- // First nibble
- idx = data >> 4;
- step = stepTable[idx + _status.ima_ch[0].stepIndex / 4];
- sample = CLIP<int>(imaTable[idx + _status.ima_ch[0].stepIndex / 4] + _status.ima_ch[0].last, -32767, 32767);
- buffer[samples] = (sample * _currentVolume) >> 4;
-
- // Second nibble
- idx = data & 0xF;
- _status.ima_ch[0].stepIndex = stepTable[idx + step / 4];
- _status.ima_ch[0].last = CLIP(imaTable[idx + step / 4] + sample, -32767, 32767);
- buffer[samples + 1] = (_status.ima_ch[0].last * _currentVolume) >> 4;
+ for (; samples < numSamples && _blockPos[0] < _blockAlign && !_stream->eos() && _stream->pos() < _endpos; samples++) {
+ if (_decodedSampleCount == 0) {
+ int step, sample;
+ byte idx;
+
+ byte data = _stream->readByte();
+ _blockPos[0]++;
+
+ // First nibble
+ idx = data >> 4;
+ step = stepTable[idx + _status.ima_ch[0].stepIndex / 4];
+ sample = CLIP<int>(imaTable[idx + _status.ima_ch[0].stepIndex / 4] + _status.ima_ch[0].last, -32767, 32767);
+ _decodedSamples[0] = (sample * _currentVolume) >> 4;
+
+ // Second nibble
+ idx = data & 0xF;
+ _status.ima_ch[0].stepIndex = stepTable[idx + step / 4];
+ _status.ima_ch[0].last = CLIP(imaTable[idx + step / 4] + sample, -32767, 32767);
+ _decodedSamples[1] = (_status.ima_ch[0].last * _currentVolume) >> 4;
+
+ _decodedSampleCount = 2;
+ }
+
+ // (1 - (count - 1)) ensures that _decodedSamples acts as a FIFO of depth 2
+ buffer[samples] = _decodedSamples[1 - (_decodedSampleCount - 1)];
+ _decodedSampleCount--;
}
}
@@ -428,6 +434,9 @@ public:
void setVolumeSmoothly(uint32 newVolume) { _smoothChangeTarget = newVolume; }
private:
+ uint8 _decodedSampleCount;
+ int16 _decodedSamples[2];
+
uint32 _currentVolume;
uint32 _nextVolume;
uint32 _smoothChangeTarget;
More information about the Scummvm-git-logs
mailing list