Mercurial > libavcodec.hg
comparison aac.c @ 9179:4172c9ef331a libavcodec
AAC: IEEE-754 type punning for 16-bit floating point rounding.
author | alexc |
---|---|
date | Mon, 16 Mar 2009 16:11:27 +0000 |
parents | 1c478e02676a |
children | 3fc2f6c6b684 |
comparison
equal
deleted
inserted
replaced
9178:c1e6aaea75f2 | 9179:4172c9ef331a |
---|---|
90 | 90 |
91 #include <assert.h> | 91 #include <assert.h> |
92 #include <errno.h> | 92 #include <errno.h> |
93 #include <math.h> | 93 #include <math.h> |
94 #include <string.h> | 94 #include <string.h> |
95 | |
96 union float754 { float f; uint32_t i; }; | |
95 | 97 |
96 static VLC vlc_scalefactors; | 98 static VLC vlc_scalefactors; |
97 static VLC vlc_spectral[11]; | 99 static VLC vlc_spectral[11]; |
98 | 100 |
99 | 101 |
928 } | 930 } |
929 return 0; | 931 return 0; |
930 } | 932 } |
931 | 933 |
932 static av_always_inline float flt16_round(float pf) { | 934 static av_always_inline float flt16_round(float pf) { |
933 int exp; | 935 union float754 tmp; |
934 pf = frexpf(pf, &exp); | 936 tmp.f = pf; |
935 pf = ldexpf(roundf(ldexpf(pf, 8)), exp-8); | 937 tmp.i = (tmp.i + 0x00008000U) & 0xFFFF0000U; |
936 return pf; | 938 return tmp.f; |
937 } | 939 } |
938 | 940 |
939 static av_always_inline float flt16_even(float pf) { | 941 static av_always_inline float flt16_even(float pf) { |
940 int exp; | 942 union float754 tmp; |
941 pf = frexpf(pf, &exp); | 943 tmp.f = pf; |
942 pf = ldexpf(rintf(ldexpf(pf, 8)), exp-8); | 944 tmp.i = (tmp.i + 0x00007FFFU + (tmp.i & 0x00010000U>>16)) & 0xFFFF0000U; |
943 return pf; | 945 return tmp.f; |
944 } | 946 } |
945 | 947 |
946 static av_always_inline float flt16_trunc(float pf) { | 948 static av_always_inline float flt16_trunc(float pf) { |
947 int exp; | 949 union float754 pun; |
948 pf = frexpf(pf, &exp); | 950 pun.f = pf; |
949 pf = ldexpf(truncf(ldexpf(pf, 8)), exp-8); | 951 pun.i &= 0xFFFF0000U; |
950 return pf; | 952 return pun.f; |
951 } | 953 } |
952 | 954 |
953 static void predict(AACContext * ac, PredictorState * ps, float* coef, int output_enable) { | 955 static void predict(AACContext * ac, PredictorState * ps, float* coef, int output_enable) { |
954 const float a = 0.953125; // 61.0/64 | 956 const float a = 0.953125; // 61.0/64 |
955 const float alpha = 0.90625; // 29.0/32 | 957 const float alpha = 0.90625; // 29.0/32 |