mirror of
https://github.com/mpv-player/mpv
synced 2024-09-01 04:16:39 +02:00
audio: clamp sample values in float->int format conversions
Make af_format clamp float sample values to the range [-1, 1] before conversion to integer types. Before any out-of-range values wrapped around and caused nasty artifacts. This filter is used for all automatic format conversions; thus any decoder that outputs floats with possible out-of-range values would have been affected by the bad conversion if its output needed to be converted to integers for AO.
This commit is contained in:
parent
24d0d48c4a
commit
0fff1380b1
@ -478,19 +478,19 @@ static void float2int(float* in, void* out, int len, int bps)
|
||||
switch(bps){
|
||||
case(1):
|
||||
for(i=0;i<len;i++)
|
||||
((int8_t*)out)[i] = lrintf(127.0 * in[i]);
|
||||
((int8_t*)out)[i] = lrintf(127.0 * clamp(in[i], -1.0f, +1.0f));
|
||||
break;
|
||||
case(2):
|
||||
for(i=0;i<len;i++)
|
||||
((int16_t*)out)[i] = lrintf(32767.0 * in[i]);
|
||||
((int16_t*)out)[i] = lrintf(32767.0 * clamp(in[i], -1.0f, +1.0f));
|
||||
break;
|
||||
case(3):
|
||||
for(i=0;i<len;i++)
|
||||
store24bit(out, i, lrintf(2147483647.0 * in[i]));
|
||||
store24bit(out, i, lrintf(2147483647.0 * clamp(in[i], -1.0f, +1.0f)));
|
||||
break;
|
||||
case(4):
|
||||
for(i=0;i<len;i++)
|
||||
((int32_t*)out)[i] = lrintf(2147483647.0 * in[i]);
|
||||
((int32_t*)out)[i] = lrintf(2147483647.0 * clamp(in[i], -1.0f, +1.0f));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user