shithub: aacdec

Download patch

ref: 2164315135ce7240b6bbca893cd9911bd792d9ed
parent: 9c136163859aeccbfaff07e0553eefbf73cca7f6
author: menno <menno>
date: Thu Nov 6 09:08:58 EST 2003

Small accuracy fixes

--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: decoder.c,v 1.80 2003/11/05 09:32:04 menno Exp $
+** $Id: decoder.c,v 1.81 2003/11/06 14:08:58 menno Exp $
 **/
 
 #include "common.h"
@@ -38,6 +38,9 @@
 #include "output.h"
 #ifdef SBR_DEC
 #include "sbr_dec.h"
+#endif
+#ifdef SSR_DEC
+#include "ssr.h"
 #endif
 
 #ifdef ANALYSIS
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: mdct.c,v 1.32 2003/11/04 21:43:30 menno Exp $
+** $Id: mdct.c,v 1.33 2003/11/06 14:08:58 menno Exp $
 **/
 
 /*
@@ -61,35 +61,9 @@
     3: cos(2 * PI * (1/8) / N)
     4: sin(2 * PI * (1/8) / N)
  */
-#ifndef FIXED_POINT
-#ifdef _MSC_VER
-#pragma warning(disable:4305)
-#pragma warning(disable:4244)
-#endif
+#ifdef FIXED_POINT
 real_t const_tab[][5] =
 {
-    { COEF_CONST(0.0312500000), COEF_CONST(0.9999952938), COEF_CONST(0.0030679568),
-        COEF_CONST(0.9999999265), COEF_CONST(0.0003834952) }, /* 2048 */
-    { COEF_CONST(0.0322748612), COEF_CONST(0.9999946356), COEF_CONST(0.0032724866),
-        COEF_CONST(0.9999999404), COEF_CONST(0.0004090615) }, /* 1920 */
-    { COEF_CONST(0.0441941738), COEF_CONST(0.9999811649), COEF_CONST(0.0061358847),
-        COEF_CONST(0.9999997020), COEF_CONST(0.0007669903) }, /* 1024 */
-    { COEF_CONST(0.0456435465), COEF_CONST(0.9999786019), COEF_CONST(0.0065449383),
-        COEF_CONST(0.9999996424), COEF_CONST(0.0008181230) }, /* 960 */
-    { COEF_CONST(0.0883883476), COEF_CONST(0.9996988177), COEF_CONST(0.0245412290),
-        COEF_CONST(0.9999952912), COEF_CONST(0.0030679568) }, /* 256 */
-    { COEF_CONST(0.0912870929), COEF_CONST(0.9996573329), COEF_CONST(0.0261769500),
-        COEF_CONST(0.9999946356), COEF_CONST(0.0032724866) }  /* 240 */
-#ifdef SSR_DEC
-   ,{ COEF_CONST(0.062500000), COEF_CONST(0.999924702), COEF_CONST(0.012271538),
-        COEF_CONST(0.999998823), COEF_CONST(0.00153398) }, /* 512 */
-    { COEF_CONST(0.176776695), COEF_CONST(0.995184727), COEF_CONST(0.09801714),
-        COEF_CONST(0.999924702), COEF_CONST(0.012271538) }  /* 64 */
-#endif
-};
-#else
-real_t const_tab[][5] =
-{
     { COEF_CONST(1), COEF_CONST(0.9999952938), COEF_CONST(0.0030679568),
         COEF_CONST(0.9999999265), COEF_CONST(0.0003834952) }, /* 2048 */
     { COEF_CONST(/* sqrt(1024/960) */ 1.03279556), COEF_CONST(0.9999946356), COEF_CONST(0.0032724866),
@@ -134,8 +108,11 @@
 
 mdct_info *faad_mdct_init(uint16_t N)
 {
-    uint16_t k, N_idx;
+    uint16_t k;
+#ifdef FIXED_POINT
+    uint16_t N_idx;
     real_t cangle, sangle, c, s, cold;
+#endif
 	real_t scale;
 
     mdct_info *mdct = (mdct_info*)malloc(sizeof(mdct_info));
@@ -145,6 +122,7 @@
     mdct->N = N;
     mdct->sincos = (complex_t*)malloc(N/4*sizeof(complex_t));
 
+#ifdef FIXED_POINT
     N_idx = map_N_to_idx(N);
 
     scale = const_tab[N_idx][0];
@@ -152,6 +130,9 @@
     sangle = const_tab[N_idx][2];
     c = const_tab[N_idx][3];
     s = const_tab[N_idx][4];
+#else
+    scale = (real_t)sqrt(2.0 / (real_t)N);
+#endif
 
     /* (co)sine table build using recurrence relations */
     /* this can also be done using static table lookup or */
@@ -158,7 +139,7 @@
     /* some form of interpolation */
     for (k = 0; k < N/4; k++)
     {
-#if 1
+#ifdef FIXED_POINT
         RE(mdct->sincos[k]) = -1*MUL_C_C(c,scale);
         IM(mdct->sincos[k]) = -1*MUL_C_C(s,scale);
 
@@ -167,8 +148,8 @@
         s = MUL_C_C(s,cangle) + MUL_C_C(cold,sangle);
 #else
         /* no recurrence, just sines */
-        RE(mdct->sincos[k]) = -scale*cos(2.0*M_PI*(k+1./8.) / (float)N);
-        IM(mdct->sincos[k]) = -scale*sin(2.0*M_PI*(k+1./8.) / (float)N);
+        RE(mdct->sincos[k]) = -scale*(real_t)(cos(2.0*M_PI*(k+1./8.) / (real_t)N));
+        IM(mdct->sincos[k]) = -scale*(real_t)(sin(2.0*M_PI*(k+1./8.) / (real_t)N));
 #endif
     }
 
@@ -221,6 +202,7 @@
 
         RE(Z1[k]) = MUL_R_C(RE(x), RE(sincos[k])) - MUL_R_C(IM(x), IM(sincos[k]));
         IM(Z1[k]) = MUL_R_C(IM(x), RE(sincos[k])) + MUL_R_C(RE(x), IM(sincos[k]));
+#ifdef FIXED_POINT
 #if (REAL_BITS == 16)
         if (abs(RE(Z1[k])) > REAL_CONST(16383.5))
         {
@@ -237,6 +219,7 @@
             IM(Z1[k]) *= 2;
         }
 #endif
+#endif
     }
 
     /* reordering */
@@ -251,19 +234,6 @@
         X_out[N2 + N4 +     2*k] = -IM(Z1[         k]);
         X_out[N2 + N4 + 1 + 2*k] =  RE(Z1[N4 - 1 - k]);
     }
-
-#if 0
-    {
-        float max_fp = 0;
-        for (k = 0; k < N; k++)
-        {
-            if (fabs(X_out[k]/(float)(REAL_PRECISION)) > max_fp)
-                max_fp = fabs(X_out[k]/(float)(REAL_PRECISION));
-        }
-        if (max_fp > 32767>>1)
-            printf("m: %f\n", max_fp);
-    }
-#endif
 }
 
 #ifdef LTP_DEC
--- a/libfaad/output.c
+++ b/libfaad/output.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: output.c,v 1.25 2003/11/04 21:43:30 menno Exp $
+** $Id: output.c,v 1.26 2003/11/06 14:08:58 menno Exp $
 **/
 
 #include "common.h"
@@ -34,14 +34,6 @@
 #ifndef FIXED_POINT
 
 
-
-#define ftol(A,B) {tmp = *(int32_t*) & A - 0x4B7F8000; \
-                   B = (int16_t)((tmp==(int16_t)tmp) ? tmp : (tmp>>31)^0x7FFF);}
-
-#define ROUND(x) ((x >= 0) ? (int32_t)floor((x) + 0.5) : (int32_t)ceil((x) + 0.5))
-
-#define ROUND32(x) ROUND(x)
-
 #define FLOAT_SCALE (1.0f/(1<<15))
 
 #define DM_MUL ((real_t)1.0/((real_t)1.0+(real_t)sqrt(2.0)))
@@ -87,37 +79,66 @@
         case FAAD_FMT_16BIT:
             for(i = 0; i < frame_len; i++)
             {
-                int32_t tmp;
-                real_t ftemp;
-                //real_t inp = input[internal_channel][i];
                 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
-
-                ftemp = inp + 0xff8000;
-                ftol(ftemp, short_sample_buffer[(i*channels)+ch]);
+                if (inp >= 0.0f)
+                {
+                    inp += 0.5f;
+                    if (inp >= 32768.0f)
+                    {
+                        inp = 32767.0f;
+                    }
+                } else {
+                    inp += -0.5f;
+                    if (inp <= -32769.0f)
+                    {
+                        inp = -32768.0f;
+                    }
+                }
+                short_sample_buffer[(i*channels)+ch] = (int16_t)inp;
             }
             break;
         case FAAD_FMT_24BIT:
             for(i = 0; i < frame_len; i++)
             {
-                //real_t inp = input[internal_channel][i];
                 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
-                if (inp > (1<<15)-1)
-                    inp = (1<<15)-1;
-                else if (inp < -(1<<15))
-                    inp = -(1<<15);
-                int_sample_buffer[(i*channels)+ch] = ROUND(inp*(1<<8));
+                inp *= 256.0f;
+                if (inp >= 0.0f)
+                {
+                    inp += 0.5f;
+                    if (inp >= 8388608.0f)
+                    {
+                        inp = 8388607.0f;
+                    }
+                } else {
+                    inp += -0.5f;
+                    if (inp <= -8388609.0f)
+                    {
+                        inp = -8388608.0f;
+                    }
+                }
+                int_sample_buffer[(i*channels)+ch] = (int32_t)inp;
             }
             break;
         case FAAD_FMT_32BIT:
             for(i = 0; i < frame_len; i++)
             {
-                //real_t inp = input[internal_channel][i];
                 real_t inp = get_sample(input, ch, i, hDecoder->downMatrix, hDecoder->internal_channel);
-                if (inp > (1<<15)-1)
-                    inp = (1<<15)-1;
-                else if (inp < -(1<<15))
-                    inp = -(1<<15);
-                int_sample_buffer[(i*channels)+ch] = ROUND32(inp*(1<<16));
+                inp *= 65536.0f;
+                if (inp >= 0.0f)
+                {
+                    inp += 0.5f;
+                    if (inp >= 2147483648.0f)
+                    {
+                        inp = 2147483647.0f;
+                    }
+                } else {
+                    inp += -0.5f;
+                    if (inp <= -2147483649.0f)
+                    {
+                        inp = -2147483648.0f;
+                    }
+                }
+                int_sample_buffer[(i*channels)+ch] = (int32_t)inp;
             }
             break;
         case FAAD_FMT_FLOAT:
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -22,7 +22,7 @@
 ** Commercial non-GPL licensing of this software is possible.
 ** For more info contact Ahead Software through [email protected].
 **
-** $Id: specrec.c,v 1.31 2003/11/04 21:43:30 menno Exp $
+** $Id: specrec.c,v 1.32 2003/11/06 14:08:58 menno Exp $
 **/
 
 /*
@@ -556,13 +556,13 @@
 #else
 static real_t pow2_table[] =
 {
-    COEF_CONST(0.59460355750136),
-    COEF_CONST(0.70710678118655),
-    COEF_CONST(0.84089641525371),
+    COEF_CONST(0.59460355750136053335874998528024), /* 2^-0.75 */
+    COEF_CONST(0.70710678118654752440084436210485), /* 2^-0.5 */
+    COEF_CONST(0.84089641525371454303112547623321), /* 2^-0.25 */
     COEF_CONST(1.0),
-    COEF_CONST(1.18920711500272),
-    COEF_CONST(1.41421356237310),
-    COEF_CONST(1.68179283050743)
+    COEF_CONST(1.1892071150027210667174999705605), /* 2^0.25 */
+    COEF_CONST(1.4142135623730950488016887242097), /* 2^0.5 */
+    COEF_CONST(1.6817928305074290860622509524664) /* 2^0.75 */
 };
 #endif