summaryrefslogtreecommitdiffstats
path: root/libaf
diff options
context:
space:
mode:
authorRudolf Polzer <divverent@alientrap.org>2011-05-03 22:11:53 +0200
committerUoti Urpala <uau@mplayer2.org>2011-05-04 17:25:11 +0300
commit0fff1380b18f4f695d0481fd0cb0e19e1991140a (patch)
tree0b7b5c0e3279e678c67dfb1c377c926cb67dd9d8 /libaf
parent24d0d48c4a658ed863b2e0246d1362ca3c4b3d19 (diff)
downloadmpv-0fff1380b18f4f695d0481fd0cb0e19e1991140a.tar.bz2
mpv-0fff1380b18f4f695d0481fd0cb0e19e1991140a.tar.xz
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.
Diffstat (limited to 'libaf')
-rw-r--r--libaf/af_format.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/libaf/af_format.c b/libaf/af_format.c
index 3b9b907882..729b964726 100644
--- a/libaf/af_format.c
+++ b/libaf/af_format.c
@@ -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;
}
}