audio: Fix resampler overflowing input buffer.

This usually manifests as a clicking sound, because it often produces
a value outside the range -1.0f to 1.0f based on whatever random data
is past the buffer, which later stages of audio conversion will clamp
to a maximum value for the audio format. Since this tends to be a single
bad sample generated at the end of the resampled buffer, it sounds like
a repeating click in streamed data.

I'd like a more efficient means to clamp this value to not overflow the
buffer, but this puts out the immediate fire.
This commit is contained in:
Ryan C. Gordon 2023-08-12 00:52:11 -04:00
parent f290c85b22
commit 91cd5478be
No known key found for this signature in database
GPG Key ID: FA148B892AB48044

View File

@ -81,7 +81,11 @@ static void ResampleAudio(const int chans, const int inrate, const int outrate,
int i, j, chan;
for (i = 0; i < outframes; i++) {
const int srcindex = (int)((Sint64)i * inrate / outrate);
int srcindex = (int)((Sint64)i * inrate / outrate);
if (srcindex >= inframes) { // !!! FIXME: can we clamp this without an if statement on each iteration?
srcindex = inframes - 1;
}
/* Calculating the following way avoids subtraction or modulo of large
* floats which have low result precision.
* interpolation1