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:
parent
f290c85b22
commit
91cd5478be
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user