shithub: aacdec

Download patch

ref: 7a97eaed2b106ff43f6f3fea945c6aa1225196f9
parent: c51b2bc5fb16770c4e6703c43e33a44135418249
author: menno <menno>
date: Sat Aug 17 08:27:33 EDT 2002

More preparations for fixed point

--- a/libfaad/cfft.c
+++ b/libfaad/cfft.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: cfft.c,v 1.3 2002/08/17 11:46:48 menno Exp $
+** $Id: cfft.c,v 1.4 2002/08/17 12:27:33 menno Exp $
 **/
 
 /*
@@ -76,8 +76,8 @@
 static void passf3(uint16_t ido, uint16_t l1, real_t *cc, real_t *ch,
                    real_t *wa1, real_t *wa2, int8_t isign)
 {
-    static real_t taur = -0.5;
-    static real_t taui = 0.866025403784439;
+    static real_t taur = REAL_CONST(-0.5);
+    static real_t taui = REAL_CONST(0.866025403784439);
     uint16_t i, k, ac, ah;
     real_t ci2, ci3, di2, di3, cr2, cr3, dr2, dr3, ti2, tr2;
 
@@ -200,10 +200,10 @@
                    real_t *wa1, real_t *wa2, real_t *wa3, real_t *wa4,
                    int8_t isign)
 {
-    static real_t tr11 = 0.309016994374947;
-    static real_t ti11 = 0.951056516295154;
-    static real_t tr12 = -0.809016994374947;
-    static real_t ti12 = 0.587785252292473;
+    static real_t tr11 = REAL_CONST(0.309016994374947);
+    static real_t ti11 = REAL_CONST(0.951056516295154);
+    static real_t tr12 = REAL_CONST(-0.809016994374947);
+    static real_t ti12 = REAL_CONST(0.587785252292473);
     uint16_t i, k, ac, ah;
     real_t ci2, ci3, ci4, ci5, di3, di4, di5, di2, cr2, cr3, cr5, cr4,
         ti2, ti3, ti4, ti5, dr3, dr4, dr5, dr2, tr2, tr3, tr4, tr5;
@@ -610,7 +610,7 @@
 
     ifac[0] = n;
     ifac[1] = nf;
-    argh = 2*M_PI / (real_t)n;
+    argh = REAL_CONST(2*M_PI / (real_t)n); /* <-- TODO */
     i = 1;
     l1 = 1;
 
@@ -637,8 +637,8 @@
                 i += 2;
                 fi += 1;
                 arg = MUL(fi,argld);
-                wa[i-1] = cos(arg);
-                wa[i] = sin(arg);
+                wa[i-1] = REAL_CONST(cos(arg));
+                wa[i] = REAL_CONST(sin(arg));
             }
 
             if (ip > 5)
--- a/libfaad/common.h
+++ b/libfaad/common.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: common.h,v 1.15 2002/08/13 19:16:07 menno Exp $
+** $Id: common.h,v 1.16 2002/08/17 12:27:33 menno Exp $
 **/
 
 #ifndef __COMMON_H__
@@ -130,6 +130,7 @@
   typedef float real_t;
 
   #define MUL(A,B) ((A)*(B))
+  #define REAL_CONST(A) ((real_t)A)
 
   #ifdef __ICL /* only Intel C compiler has fmath ??? */
 
@@ -177,6 +178,7 @@
   #include <math.h>
 
   #define MUL(A,B) ((A)*(B))
+  #define REAL_CONST(A) (A)
 
 #endif
 
--- a/libfaad/decoder.c
+++ b/libfaad/decoder.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: decoder.c,v 1.19 2002/08/17 10:03:12 menno Exp $
+** $Id: decoder.c,v 1.20 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include <stdlib.h>
@@ -83,7 +83,7 @@
 #endif
     }
 
-    hDecoder->drc = drc_init(1.0f, 1.0f);
+    hDecoder->drc = drc_init(REAL_CONST(1.0), REAL_CONST(1.0));
 #if IQ_TABLE_SIZE && POW_TABLE_SIZE
     build_tables(hDecoder->iq_table, hDecoder->pow2_table);
 #elif !POW_TABLE_SIZE
--- a/libfaad/drc.c
+++ b/libfaad/drc.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: drc.c,v 1.6 2002/08/17 10:03:12 menno Exp $
+** $Id: drc.c,v 1.7 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -61,9 +61,9 @@
 
         /* Decode DRC gain factor */
         if (drc->dyn_rng_sgn[bd])  /* compress */
-            factor = (real_t)exp(LN2 * (-drc->ctrl1 * drc->dyn_rng_ctl[bd]/24.0));
+            factor = REAL_CONST(exp(LN2 * (-drc->ctrl1 * drc->dyn_rng_ctl[bd]/24.0)));
         else /* boost */
-            factor = (real_t)exp(LN2 * (drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0));
+            factor = REAL_CONST(exp(LN2 * (drc->ctrl2 * drc->dyn_rng_ctl[bd]/24.0)));
 
         /* Level alignment between different programs (if desired) */
         /* If program reference normalization is done in the digital domain,
@@ -74,7 +74,7 @@
            attenuated) or clipping (if signal is boosted)
          */
         factor = MUL(factor,
-            (real_t)exp(LN05 * ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0)));
+            REAL_CONST(exp(LN05 * ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0))));
 
         /* Apply gain factor */
         for (i = bottom; i < top; i++)
--- a/libfaad/drc.h
+++ b/libfaad/drc.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: drc.h,v 1.3 2002/08/17 10:03:13 menno Exp $
+** $Id: drc.h,v 1.4 2002/08/17 12:27:33 menno Exp $
 **/
 
 #ifndef __DRC_H__
@@ -26,7 +26,7 @@
 extern "C" {
 #endif
 
-#define DRC_REF_LEVEL 20*4 /* -20 dB */
+#define DRC_REF_LEVEL 20.0*4.0 /* -20 dB */
 
 drc_info *drc_init(real_t cut, real_t boost);
 void drc_end(drc_info *drc);
--- a/libfaad/filtbank.c
+++ b/libfaad/filtbank.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: filtbank.c,v 1.13 2002/08/17 11:15:31 menno Exp $
+** $Id: filtbank.c,v 1.14 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -50,9 +50,9 @@
 
     /* calculate the sine windows */
     for (i = 0; i < frame_len; i++)
-        fb->long_window[0][i] = (real_t)sin(M_PI / (2.0 * (real_t)frame_len) * ((real_t)i + 0.5));
+        fb->long_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * (real_t)frame_len) * ((real_t)i + 0.5)));
     for (i = 0; i < nshort; i++)
-        fb->short_window[0][i] = (real_t)sin(M_PI / (2.0 * (real_t)nshort) * ((real_t)i + 0.5));
+        fb->short_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * (real_t)nshort) * ((real_t)i + 0.5)));
 
 #ifdef LD_DEC
     /* LD */
@@ -63,13 +63,13 @@
 
     /* calculate the sine windows */
     for (i = 0; i < frame_len_ld; i++)
-        fb->ld_window[0][i] = (real_t)sin(M_PI / (2.0 * frame_len_ld) * (i + 0.5));
+        fb->ld_window[0][i] = REAL_CONST(sin(M_PI / (2.0 * frame_len_ld) * (i + 0.5)));
 
     /* low overlap window */
     for (i = 0; i < 3*(frame_len_ld>>3); i++)
         fb->ld_window[1][i] = 0.0;
     for (; i < 5*(frame_len_ld>>3); i++)
-        fb->ld_window[1][i] = (real_t)sin((i-3*(frame_len_ld>>3)+0.5) * M_PI / (real_t)(frame_len_ld>>1));
+        fb->ld_window[1][i] = REAL_CONST(sin((i-3*(frame_len_ld>>3)+0.5) * M_PI / (real_t)(frame_len_ld>>1)));
     for (; i < frame_len_ld; i++)
         fb->ld_window[1][i] = 1.0;
 #endif
--- a/libfaad/ic_predict.c
+++ b/libfaad/ic_predict.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ic_predict.c,v 1.7 2002/08/17 11:15:31 menno Exp $
+** $Id: ic_predict.c,v 1.8 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -63,8 +63,8 @@
     KOR = state->KOR; /* correlations */
     VAR = state->VAR; /* variances */
 
-    if (VAR[0] == 0.0)
-        k1 = 0.0;
+    if (VAR[0] == REAL_CONST(0.0))
+        k1 = REAL_CONST(0.0);
     else
         k1 = KOR[0]/VAR[0]*B;
 
@@ -71,8 +71,8 @@
     if (pred)
     {
         /* only needed for the actual predicted value, k1 is always needed */
-        if (VAR[1] == 0.0)
-            k2 = 0.0;
+        if (VAR[1] == REAL_CONST(0.0))
+            k2 = REAL_CONST(0.0);
         else
             k2 = KOR[1]/VAR[1]*B;
 
@@ -88,11 +88,11 @@
     e0 = *output;
     e1 = e0 - MUL(k1, r[0]);
 
-    dr1 = k1 * e0;
+    dr1 = MUL(k1, e0);
 
-    VAR[0] = MUL(ALPHA, VAR[0]) + (0.5f) * (MUL(r[0], r[0]) + MUL(e0, e0));
+    VAR[0] = MUL(ALPHA, VAR[0]) + MUL(REAL_CONST(0.5), (MUL(r[0], r[0]) + MUL(e0, e0)));
     KOR[0] = MUL(ALPHA, KOR[0]) + MUL(r[0], e0);
-    VAR[1] = MUL(ALPHA, VAR[1]) + (0.5f) * (MUL(r[1], r[1]) + MUL(e1, e1));
+    VAR[1] = MUL(ALPHA, VAR[1]) + MUL(REAL_CONST(0.5), (MUL(r[1], r[1]) + MUL(e1, e1)));
     KOR[1] = MUL(ALPHA, KOR[1]) + MUL(r[1], e1);
 
     r[1] = MUL(A, (r[0]-dr1));
@@ -101,12 +101,12 @@
 
 static void reset_pred_state(pred_state *state)
 {
-    state->r[0]   = 0.0f;
-    state->r[1]   = 0.0f;
-    state->KOR[0] = 0.0f;
-    state->KOR[1] = 0.0f;
-    state->VAR[0] = 1.0f;
-    state->VAR[1] = 1.0f;
+    state->r[0]   = REAL_CONST(0.0);
+    state->r[1]   = REAL_CONST(0.0);
+    state->KOR[0] = REAL_CONST(0.0);
+    state->KOR[1] = REAL_CONST(0.0);
+    state->VAR[0] = REAL_CONST(1.0);
+    state->VAR[1] = REAL_CONST(1.0);
 }
 
 void pns_reset_pred_state(ic_stream *ics, pred_state *state)
--- a/libfaad/ic_predict.h
+++ b/libfaad/ic_predict.h
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: ic_predict.h,v 1.4 2002/06/13 11:03:27 menno Exp $
+** $Id: ic_predict.h,v 1.5 2002/08/17 12:27:33 menno Exp $
 **/
 
 #ifdef MAIN_DEC
@@ -28,9 +28,9 @@
 extern "C" {
 #endif
 
-#define ALPHA      0.90625f
-#define A          0.953125f
-#define B          0.953125f
+#define ALPHA      REAL_CONST(0.90625)
+#define A          REAL_CONST(0.953125)
+#define B          REAL_CONST(0.953125)
 
 
 /* used to save the state */
--- a/libfaad/is.c
+++ b/libfaad/is.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: is.c,v 1.6 2002/06/13 11:03:27 menno Exp $
+** $Id: is.c,v 1.7 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -52,7 +52,7 @@
 
                     scale = MUL(is_intensity(icsr, g, sfb),
                         MUL(invert_intensity(ics, g, sfb),
-                        (real_t)exp(LN05 * (0.25*icsr->scale_factors[g][sfb]))));
+                        REAL_CONST(exp(LN05 * (0.25*icsr->scale_factors[g][sfb])))));
 
                     /* Scale from left to right channel,
                        do not touch left channel */
--- a/libfaad/libfaad.vcproj
+++ b/libfaad/libfaad.vcproj
@@ -246,9 +246,6 @@
 				RelativePath=".\common.h">
 			</File>
 			<File
-				RelativePath=".\fftw\config.h">
-			</File>
-			<File
 				RelativePath=".\data.h">
 			</File>
 			<File
@@ -262,9 +259,6 @@
 			</File>
 			<File
 				RelativePath=".\error.h">
-			</File>
-			<File
-				RelativePath=".\fftw\f77_func.h">
 			</File>
 			<File
 				RelativePath=".\filtbank.h">
--- a/libfaad/lt_predict.c
+++ b/libfaad/lt_predict.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: lt_predict.c,v 1.6 2002/06/13 11:03:27 menno Exp $
+** $Id: lt_predict.c,v 1.7 2002/08/17 12:27:33 menno Exp $
 **/
 
 
@@ -32,8 +32,14 @@
 
 static real_t codebook[8] =
 {
-    0.570829f, 0.696616f, 0.813004f, 0.911304f, 0.984900f, 1.067894f,
-    1.194601f, 1.369533f
+    REAL_CONST(0.570829),
+    REAL_CONST(0.696616),
+    REAL_CONST(0.813004),
+    REAL_CONST(0.911304),
+    REAL_CONST(0.984900),
+    REAL_CONST(1.067894),
+    REAL_CONST(1.194601),
+    REAL_CONST(1.369533)
 };
 
 void lt_prediction(ic_stream *ics, ltp_info *ltp, real_t *spec,
--- a/libfaad/mdct.c
+++ b/libfaad/mdct.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: mdct.c,v 1.14 2002/08/17 11:15:31 menno Exp $
+** $Id: mdct.c,v 1.15 2002/08/17 12:27:33 menno Exp $
 **/
 
 /*
@@ -73,8 +73,8 @@
     for (k = 0; k < N/4; k++)
     {
         real_t angle = 2.0 * M_PI * ((real_t)k + 1.0/8.0)/(real_t)N;
-        mdct->sincos[k].sin = -sin(angle);
-        mdct->sincos[k].cos = -cos(angle);
+        mdct->sincos[k].sin = REAL_CONST(-sin(angle));
+        mdct->sincos[k].cos = REAL_CONST(-cos(angle));
     }
 
 #ifdef USE_FFTW
@@ -126,7 +126,7 @@
     uint16_t N4 = N >> 2;
     uint16_t N8 = N >> 3;
 
-    real_t fac = 2.0/(real_t)N;
+    real_t fac = REAL_CONST(2.0/(real_t)N);
 
     /* pre-IFFT complex multiplication */
     for (k = 0; k < N4; k++)
@@ -238,11 +238,11 @@
     {
         uint16_t n = k << 1;
 #ifdef USE_FFTW
-        real_t zr = MUL(2.0, MUL(Z2[k].re, sincos[k].cos) + MUL(Z2[k].im, sincos[k].sin));
-        real_t zi = MUL(2.0, MUL(Z2[k].im, sincos[k].cos) - MUL(Z2[k].re, sincos[k].sin));
+        real_t zr = 2 * MUL(Z2[k].re, sincos[k].cos) + MUL(Z2[k].im, sincos[k].sin);
+        real_t zi = 2 * MUL(Z2[k].im, sincos[k].cos) - MUL(Z2[k].re, sincos[k].sin);
 #else
-        real_t zr = MUL(2.0, MUL(Z1[n], sincos[k].cos) + MUL(Z1[n+1], sincos[k].sin));
-        real_t zi = MUL(2.0, MUL(Z1[n+1], sincos[k].cos) - MUL(Z1[n], sincos[k].sin));
+        real_t zr = 2 * MUL(Z1[n], sincos[k].cos) + MUL(Z1[n+1], sincos[k].sin);
+        real_t zi = 2 * MUL(Z1[n+1], sincos[k].cos) - MUL(Z1[n], sincos[k].sin);
 #endif
 
         X_out[         n] = -zr;
--- a/libfaad/pns.c
+++ b/libfaad/pns.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: pns.c,v 1.9 2002/08/17 11:15:32 menno Exp $
+** $Id: pns.c,v 1.10 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -84,10 +84,12 @@
     /* 14496-3 says:
        scale = 1.0f/(size * (real_t)sqrt(MEAN_NRG));
     */
-    scale = sqrt(size * MEAN_NRG);
+    scale = REAL_CONST(sqrt(size * MEAN_NRG));
     if (scale != 0.0)
-        scale = 1.0/scale;
-    scale = MUL(scale, exp(LN2 * 0.25 * scale_factor));
+    {
+        scale = 1.0/scale; /* <-- TODO */
+        scale = MUL(scale, REAL_CONST(exp(LN2 * 0.25 * scale_factor)));
+    }
 
     /* Scale random vector to desired target energy */
     for (i = 0; i < size; i++)
--- a/libfaad/specrec.c
+++ b/libfaad/specrec.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: specrec.c,v 1.8 2002/06/13 11:03:28 menno Exp $
+** $Id: specrec.c,v 1.9 2002/08/17 12:27:33 menno Exp $
 **/
 
 /*
@@ -248,13 +248,13 @@
     /* build pow(x, 4/3) table for inverse quantization */
     for(i = 0; i < IQ_TABLE_SIZE; i++)
     {
-        iq_table[i] = (real_t)exp(log(i) * 4.0/3.0);
+        iq_table[i] = REAL_CONST(exp(log(i) * 4.0/3.0));
     }
 
     /* build pow(2, 0.25*x) table for scalefactors */
     for(i = 0; i < POW_TABLE_SIZE; i++)
     {
-        pow2_table[i] = (real_t)exp(LN2 * 0.25 * (i-100));
+        pow2_table[i] = REAL_CONST(exp(LN2 * 0.25 * (i-100)));
     }
 }
 
@@ -265,15 +265,15 @@
         if (q < IQ_TABLE_SIZE)
             return iq_table[q];
         else
-            return MUL(iq_table[q>>3], 16);
+            return iq_table[q>>3] * 16;
     } else if (q < 0) {
         q = -q;
         if (q < IQ_TABLE_SIZE)
             return -iq_table[q];
         else
-          return -MUL(iq_table[q>>3], 16);
+          return -iq_table[q>>3] * 16;
     } else {
-        return 0.0f;
+        return 0;
     }
 }
 
@@ -302,7 +302,7 @@
     if (scale_factor < POW_TABLE_SIZE)
         return pow2_table[scale_factor];
     else
-        return (real_t)exp(LN2 * 0.25 * (scale_factor - 100));
+        return REAL_CONST(exp(LN2 * 0.25 * (scale_factor - 100)));
 }
 
 void apply_scalefactors(ic_stream *ics, real_t *x_invquant, real_t *pow2_table,
--- a/libfaad/tns.c
+++ b/libfaad/tns.c
@@ -16,7 +16,7 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: tns.c,v 1.12 2002/06/13 11:03:28 menno Exp $
+** $Id: tns.c,v 1.13 2002/08/17 12:27:33 menno Exp $
 **/
 
 #include "common.h"
@@ -150,11 +150,15 @@
 
         /* Inverse quantization */
         if (tmp >= 0)
-            iqfac = ((1 << (coef_res_bits-1)) - 0.5f) / M_PI_2;
-        else
-            iqfac = ((1 << (coef_res_bits-1)) + 0.5f) / M_PI_2;
+        {
+            iqfac = REAL_CONST((1 << (coef_res_bits-1)) -
+                REAL_CONST(0.5)) / REAL_CONST(M_PI_2); /* <-- TODO */
+        } else {
+            iqfac = REAL_CONST((1 << (coef_res_bits-1)) +
+                REAL_CONST(0.5)) / REAL_CONST(M_PI_2); /* <-- TODO */
+        }
 
-        tmp2[i] = (real_t)sin(tmp / iqfac);
+        tmp2[i] = REAL_CONST(sin(tmp / iqfac));
     }
 
     /* Conversion to LPC coefficients */