[Scummvm-git-logs] scummvm master -> d725cae79eb47300b07ae509f7e11c4b0002e3c3
eriktorbjorn
eriktorbjorn at telia.com
Fri Jan 29 13:43:13 UTC 2021
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:
d725cae79e SCUMM: Fix audio distortion in Loom for PC-Engine
Commit: d725cae79eb47300b07ae509f7e11c4b0002e3c3
https://github.com/scummvm/scummvm/commit/d725cae79eb47300b07ae509f7e11c4b0002e3c3
Author: Torbjörn Andersson (eriktorbjorn at users.sourceforge.net)
Date: 2021-01-29T14:42:17+01:00
Commit Message:
SCUMM: Fix audio distortion in Loom for PC-Engine
There are two buffers when generating audio. The output buffer that
readBuffer() fills, and the sample buffer where new samples are
generated. The sample buffer is the larger of the two.
When readBuffer() is called, samples are copied from the sample buffer
to the output buffer. Usually it will copy some samples to the output
buffer, generate new ones to the sample buffer, and copy the remaining
ones needed to the output buffer.
At the end, the remaining samples in the sample buffer are moved to the
beginning of the buffer. It works out so that samples are always copied
from the beginning of the sample buffer to somewhere in the output
buffer.
But here's where things went wrong: If the sample buffer was not full,
but still contained enough samples to fill the output buffer, it would
still copy the last samples in the sample buffer. It should copy the
samples from right after the ones that had already been copied to the
output buffer.
I spent far too long beating my head against this bug, and I don't know
how well I've explained it here. But the audio corruption appears to be
gone now...
Foo
Changed paths:
engines/scumm/players/player_pce.cpp
diff --git a/engines/scumm/players/player_pce.cpp b/engines/scumm/players/player_pce.cpp
index 31210025ca..8efa3c6510 100644
--- a/engines/scumm/players/player_pce.cpp
+++ b/engines/scumm/players/player_pce.cpp
@@ -511,6 +511,7 @@ void Player_PCE::updateSound() {
int Player_PCE::readBuffer(int16 *buffer, const int numSamples) {
int sampleCopyCnt;
int samplesLeft = numSamples;
+ int16 *sampleBufferPtr = _sampleBuffer;
Common::StackLock lock(_mutex);
@@ -518,10 +519,11 @@ int Player_PCE::readBuffer(int16 *buffer, const int numSamples) {
// copy samples to output buffer
sampleCopyCnt = (samplesLeft < _sampleBufferCnt) ? samplesLeft : _sampleBufferCnt;
if (sampleCopyCnt > 0) {
- memcpy(buffer, _sampleBuffer, sampleCopyCnt * sizeof(int16));
+ memcpy(buffer, sampleBufferPtr, sampleCopyCnt * sizeof(int16));
buffer += sampleCopyCnt;
samplesLeft -= sampleCopyCnt;
_sampleBufferCnt -= sampleCopyCnt;
+ sampleBufferPtr += sampleCopyCnt;
}
if (samplesLeft == 0)
@@ -531,12 +533,13 @@ int Player_PCE::readBuffer(int16 *buffer, const int numSamples) {
updateSound();
_psg->update(_sampleBuffer, _samplesPerPeriod / 2);
_sampleBufferCnt = _samplesPerPeriod;
+ sampleBufferPtr = _sampleBuffer;
}
// copy remaining samples to the front of the buffer
if (_sampleBufferCnt > 0) {
- memmove(&_sampleBuffer[0],
- &_sampleBuffer[_samplesPerPeriod - _sampleBufferCnt],
+ memmove(_sampleBuffer,
+ sampleBufferPtr,
_sampleBufferCnt * sizeof(int16));
}
More information about the Scummvm-git-logs
mailing list