audio_utils: float2int: clamp input to valid range

This avoids pops and buzzing caused by integer overflow when the input
sample falls outside of the range [-1.0, 1.0] (I encountered this when
using jack capture).
This commit is contained in:
Martin Piatka
2021-04-06 16:36:17 +02:00
parent f4e509caa9
commit 9d440a15e3

View File

@@ -321,7 +321,10 @@ void float2int(char *out, const char *in, int len)
int items = len / sizeof(int32_t);
while(items-- > 0) {
*outi++ = *inf++ * INT_MAX;
float sample = *inf++;
if(sample > 1.0) sample = 1.0;
if(sample < -1.0) sample = -1.0;
*outi++ = sample * INT_MAX;
}
}