[FFmpeg-cvslog] r18015 - trunk/libavcodec/aac.c

alexc subversion
Mon Mar 16 17:11:28 CET 2009


Author: alexc
Date: Mon Mar 16 17:11:27 2009
New Revision: 18015

Log:
AAC: IEEE-754 type punning for 16-bit floating point rounding.

Modified:
   trunk/libavcodec/aac.c

Modified: trunk/libavcodec/aac.c
==============================================================================
--- trunk/libavcodec/aac.c	Mon Mar 16 14:23:29 2009	(r18014)
+++ trunk/libavcodec/aac.c	Mon Mar 16 17:11:27 2009	(r18015)
@@ -93,6 +93,8 @@
 #include <math.h>
 #include <string.h>
 
+union float754 { float f; uint32_t i; };
+
 static VLC vlc_scalefactors;
 static VLC vlc_spectral[11];
 
@@ -930,24 +932,24 @@ static int decode_spectrum_and_dequant(A
 }
 
 static av_always_inline float flt16_round(float pf) {
-    int exp;
-    pf = frexpf(pf, &exp);
-    pf = ldexpf(roundf(ldexpf(pf, 8)), exp-8);
-    return pf;
+    union float754 tmp;
+    tmp.f = pf;
+    tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U;
+    return tmp.f;
 }
 
 static av_always_inline float flt16_even(float pf) {
-    int exp;
-    pf = frexpf(pf, &exp);
-    pf = ldexpf(rintf(ldexpf(pf, 8)), exp-8);
-    return pf;
+    union float754 tmp;
+    tmp.f = pf;
+    tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U>>16)) & 0xFFFF0000U;
+    return tmp.f;
 }
 
 static av_always_inline float flt16_trunc(float pf) {
-    int exp;
-    pf = frexpf(pf, &exp);
-    pf = ldexpf(truncf(ldexpf(pf, 8)), exp-8);
-    return pf;
+    union float754 pun;
+    pun.f = pf;
+    pun.i &= 0xFFFF0000U;
+    return pun.f;
 }
 
 static void predict(AACContext * ac, PredictorState * ps, float* coef, int output_enable) {




More information about the ffmpeg-cvslog mailing list