[MPlayer-cvslog] r33824 - trunk/libaf/af_format.c
iive
subversion at mplayerhq.hu
Thu Jul 7 01:35:39 CEST 2011
Author: iive
Date: Thu Jul 7 01:35:39 2011
New Revision: 33824
Log:
Fix the precision loss in float -> 32bit conversion case, introduced
by my earlier commit. Instead use method proposed by Reimar.
Also, avoid using ldexp, it is slower than multiply with constant.
Modified:
trunk/libaf/af_format.c
Modified: trunk/libaf/af_format.c
==============================================================================
--- trunk/libaf/af_format.c Tue Jul 5 18:50:52 2011 (r33823)
+++ trunk/libaf/af_format.c Thu Jul 7 01:35:39 2011 (r33824)
@@ -489,15 +489,21 @@ static void float2int(float* in, void* o
break;
case(3):
for(i=0;i<len;i++){
- f = ldexp(in[i], 23);
+ f = in[i] * 8388608;
store24bit(out, i, av_clip(lrintf(f), -1*(1<<23), (1<<23)-1) << 8);
}
break;
case(4):
for(i=0;i<len;i++){
- f = ldexp(in[i], 23);
- //The mantissa is only 23 bit, that's all the precision there is.
- ((int32_t*)out)[i] = av_clip(lrintf(f), -1*(1<<23), (1<<23)-1) << 8;
+ f = in[i];
+ if (f <= -1.0)
+ ((int32_t*)out)[i] = INT_MIN;
+ else
+ if (f >= 1.0)//no need to use corrected constant, rounding won't cause overflow
+ ((int32_t*)out)[i] = INT_MAX;
+ else
+ ((int32_t*)out)[i] = lrintf(f*2147483648.0);
+
}
break;
}
More information about the MPlayer-cvslog
mailing list