Clamp floating-point sample data to +-1.0 for OpenAL

Fixes horrendously amplified horns being loud as fuck
(yes, Vorbis can encode samples louder than 0 dB!)
This commit is contained in:
GenericHeroGuy 2025-12-02 23:41:54 +01:00
parent 6749b54968
commit a8e14a6adb

View file

@ -790,6 +790,14 @@ static ALuint LoadDataIntoBuffer(void *input, size_t size)
size = pos;
samplerate = info.samplerate;
sf_close(snd);
// SFC_SET_NORM_FLOAT apparently doesn't work, so gotta do this ourselves
if (sample_format == Float)
{
float *norm = (float *)data;
for (pos = 0; pos < size / sizeof(float); pos++)
norm[pos] = CLAMP(norm[pos], -1.0f, 1.0f);
}
}
}