diff options
author | Alex Converse <alex.converse@gmail.com> | 2009-03-16 16:11:27 +0000 |
---|---|---|
committer | Alex Converse <alex.converse@gmail.com> | 2009-03-16 16:11:27 +0000 |
commit | 4a39ccb40350a25719b1a43d2bacbd74fbd4f703 (patch) | |
tree | 539548a7adcd5765bf001b99941f38b962f484a3 /libavcodec/aac.c | |
parent | 508fe07ab323d8e11fd06d59700be459623f2a9d (diff) | |
download | ffmpeg-streaming-4a39ccb40350a25719b1a43d2bacbd74fbd4f703.zip ffmpeg-streaming-4a39ccb40350a25719b1a43d2bacbd74fbd4f703.tar.gz |
AAC: IEEE-754 type punning for 16-bit floating point rounding.
Originally committed as revision 18015 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavcodec/aac.c')
-rw-r--r-- | libavcodec/aac.c | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/libavcodec/aac.c b/libavcodec/aac.c index 9a3b3d7..9b230a5 100644 --- a/libavcodec/aac.c +++ b/libavcodec/aac.c @@ -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(AACContext * ac, float coef[1024], GetBit } 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) { |