mirror of
https://github.com/outbackdingo/UltraGrid.git
synced 2026-03-21 23:40:26 +00:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user