shithub: aacdec

Download patch

ref: 1328d84e8b10421e3db2e0c778f359532b0a9cc4
parent: 6d726c2e024ac310553c8483f0db44a762d6a461
author: menno <menno>
date: Fri May 24 13:26:12 EDT 2002

My latest changes
- bugfix in filtbank.c
- start work for fixed point operation

--- 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.10 2002/05/01 19:25:19 menno Exp $
+** $Id: common.h,v 1.11 2002/05/24 17:26:11 menno Exp $
 **/
 
 #ifndef __COMMON_H__
@@ -117,6 +117,8 @@
 
   typedef float real_t;
 
+  #define MUL(A,B) ((A)*(B))
+
   #ifdef __ICL /* only Intel C compiler has fmath ??? */
 
     #include <mathf.h>
@@ -161,6 +163,8 @@
 
   typedef double real_t;
   #include <math.h>
+
+  #define MUL(A,B) ((A)*(B))
 
 #endif
 
--- 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.4 2002/03/16 13:38:37 menno Exp $
+** $Id: drc.c,v 1.5 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -65,11 +65,12 @@
            modification avoids problems with reduced DAC SNR (if signal is
            attenuated) or clipping (if signal is boosted)
          */
-        factor *= (real_t)exp(LN05 * ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0));
+        factor = MUL(factor,
+            (real_t)exp(LN05 * ((DRC_REF_LEVEL - drc->prog_ref_level)/24.0)));
 
         /* Apply gain factor */
         for (i = bottom; i < top; i++)
-            spec[i] *= factor;
+            spec[i] = MUL(spec[i], factor);
 
         bottom = top;
     }
--- 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.7 2002/04/07 21:26:04 menno Exp $
+** $Id: filtbank.c,v 1.8 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -123,14 +123,14 @@
 
     for (i = vlen/16-1; i >= 0 ; --i)
     {
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
-        *dest++ = *src1++ * *src2++; *dest++ = *src1++ * *src2++;
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
+        *dest++ = MUL(*src1++, *src2++); *dest++ = MUL(*src1++, *src2++);
     }
 }
 
@@ -142,14 +142,14 @@
 
     for (i = vlen/16-1; i >= 0 ; --i)
     {
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
-        *dest++ = *src1++ * *src2--; *dest++ = *src1++ * *src2--;
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
+        *dest++ = MUL(*src1++, *src2--); *dest++ = MUL(*src1++, *src2--);
     }
 }
 
@@ -309,6 +309,8 @@
         vzero(obuf_temp+2*nlong-1, 2*nlong);
 
 		fp = obuf_temp;
+        vcopy(time_buff+nflat_ls, fp, nshort);
+
         for (win = 8-1; win >= 0; --win)
         {
             /* inverse transform */
@@ -330,9 +332,7 @@
             window_short_prev_ptr = window_short;
         }
 
-        vadd(o_buf + 448, obuf_temp, o_buf + 448, nlong - 448);
         vcopy(obuf_temp, o_buf + 448, nlong*2-nflat_ls);
-        
         vzero(o_buf+2*nlong-1, nflat_ls);
 
         free(obuf_temp);
--- 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.3 2002/03/16 13:38:37 menno Exp $
+** $Id: ic_predict.c,v 1.4 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -70,7 +70,7 @@
         /* only needed for the actual predicted value, k1 is always needed */
         k2 = KOR[1]/VAR[1]*B;
 
-        predictedvalue = k1*r[0] + k2*r[1];
+        predictedvalue = MUL(k1, r[0]) + MUL(k2, r[1]);
         flt_round_inf(&predictedvalue);
 
         *output = input + predictedvalue;
@@ -80,17 +80,17 @@
 
     /* calculate new state data */
     e0 = *output;
-    e1 = e0 - k1 * r[0];
+    e1 = e0 - MUL(k1, r[0]);
 
     dr1 = k1 * e0;
 
-    VAR[0] = ALPHA * VAR[0] + (0.5f)*(r[0]*r[0] + e0*e0);
-    KOR[0] = ALPHA * KOR[0] + r[0]*e0;
-    VAR[1] = ALPHA * VAR[1] + (0.5f)*(r[1]*r[1] + e1*e1);
-    KOR[1] = ALPHA * KOR[1] + r[1]*e1;
+    VAR[0] = MUL(ALPHA, VAR[0]) + (0.5f) * (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));
+    KOR[1] = MUL(ALPHA, KOR[1]) + MUL(r[1], e1);
 
-    r[1] = A * (r[0]-dr1);
-    r[0] = A * e0;
+    r[1] = MUL(A, (r[0]-dr1));
+    r[0] = MUL(A, e0);
 }
 
 static void reset_pred_state(pred_state *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.4 2002/03/16 13:38:37 menno Exp $
+** $Id: is.c,v 1.5 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -48,9 +48,9 @@
                     ics->pred.prediction_used[sfb] = 0;
                     icsr->pred.prediction_used[sfb] = 0;
 
-                    scale = is_intensity(icsr, g, sfb) *
-                        invert_intensity(ics, g, sfb) *
-                        (real_t)exp(LN05 * (0.25*icsr->scale_factors[g][sfb]));
+                    scale = MUL(is_intensity(icsr, g, sfb),
+                        MUL(invert_intensity(ics, g, sfb),
+                        (real_t)exp(LN05 * (0.25*icsr->scale_factors[g][sfb]))));
 
                     /* Scale from left to right channel,
                        do not touch left channel */
@@ -57,7 +57,7 @@
                     for (i = icsr->swb_offset[sfb]; i < icsr->swb_offset[sfb+1]; i++)
                     {
                         k = (group*128)+i;
-                        r_spec[k] = l_spec[k] * scale;
+                        r_spec[k] = MUL(l_spec[k], scale);
                     }
                 }
             }
--- 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.4 2002/03/16 13:38:37 menno Exp $
+** $Id: lt_predict.c,v 1.5 2002/05/24 17:26:12 menno Exp $
 **/
 
 
@@ -59,8 +59,8 @@
             {
                 /* The extra lookback M (N/2 for LD, 0 for LTP) is handled
                    in the buffer updating */
-                x_est[i] = codebook[ltp->coef] *
-                    lt_pred_stat[num_samples + i - ltp->lag];
+                x_est[i] = MUL(codebook[ltp->coef],
+                    lt_pred_stat[num_samples + i - ltp->lag]);
             }
 
             filter_bank_ltp(fb, ics->window_sequence, win_shape, win_shape_prev,
--- 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.9 2002/04/23 21:08:26 menno Exp $
+** $Id: mdct.c,v 1.10 2002/05/24 17:26:12 menno Exp $
 **/
 
 /*
@@ -106,8 +106,8 @@
         uint16_t n = k << 1;
         real_t x0 = X_in[         n];
         real_t x1 = X_in[N2 - 1 - n];
-        Z1[k].re  = x1 * sincos[k].cos - x0 * sincos[k].sin;
-        Z1[k].im  = x0 * sincos[k].cos + x1 * sincos[k].sin;
+        Z1[k].re  = MUL(fac, MUL(x1, sincos[k].cos) - MUL(x0, sincos[k].sin));
+        Z1[k].im  = MUL(fac, MUL(x0, sincos[k].cos) + MUL(x1, sincos[k].sin));
     }
 
     /* complex IFFT */
@@ -118,8 +118,8 @@
     {
         real_t zr = Z2[k].re;
         real_t zi = Z2[k].im;
-        Z2[k].re  = fac * (zr * sincos[k].cos - zi * sincos[k].sin);
-        Z2[k].im  = fac * (zi * sincos[k].cos + zr * sincos[k].sin);
+        Z2[k].re  = MUL(zr, sincos[k].cos) - MUL(zi, sincos[k].sin);
+        Z2[k].im  = MUL(zi, sincos[k].cos) + MUL(zr, sincos[k].sin);
     }
 
     /* reordering */
@@ -159,14 +159,14 @@
         real_t zr     =  X_in[N - N4 - 1 - n] + X_in[N - N4 +     n];
         real_t zi     =  X_in[    N4 +     n] - X_in[    N4 - 1 - n];
 
-        Z1[k     ].re = -zr * sincos[k     ].cos - zi * sincos[k     ].sin;
-        Z1[k     ].im = -zi * sincos[k     ].cos + zr * sincos[k     ].sin;
+        Z1[k     ].re = -MUL(zr, sincos[k     ].cos) - MUL(zi, sincos[k     ].sin);
+        Z1[k     ].im = -MUL(zi, sincos[k     ].cos) + MUL(zr, sincos[k     ].sin);
 
         zr            =  X_in[    N2 - 1 - n] - X_in[             n];
         zi            =  X_in[    N2 +     n] + X_in[N -      1 - n];
 
-        Z1[k + N8].re = -zr * sincos[k + N8].cos - zi * sincos[k + N8].sin;
-        Z1[k + N8].im = -zi * sincos[k + N8].cos + zr * sincos[k + N8].sin;
+        Z1[k + N8].re = -MUL(zr, sincos[k + N8].cos) - MUL(zi, sincos[k + N8].sin);
+        Z1[k + N8].im = -MUL(zi, sincos[k + N8].cos) + MUL(zr, sincos[k + N8].sin);
     }
 
     /* complex FFT */
@@ -176,8 +176,8 @@
     for (k = 0; k < N4; k++)
     {
         uint16_t n = k << 1;
-        real_t zr = 2.0 * (Z2[k].re * sincos[k].cos + Z2[k].im * sincos[k].sin);
-        real_t zi = 2.0 * (Z2[k].im * sincos[k].cos - Z2[k].re * sincos[k].sin);
+        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));
 
         X_out[         n] = -zr;
         X_out[N2 - 1 - n] =  zi;
--- 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.5 2002/03/16 13:38:36 menno Exp $
+** $Id: pns.c,v 1.6 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -69,11 +69,11 @@
        scale = 1.0f/(size * (real_t)sqrt(MEAN_NRG));
     */
     scale = 1.0f/(real_t)sqrt(size * MEAN_NRG);
-    scale *= (real_t)exp(LN2 * 0.25 * scale_factor);
+    scale = MUL(scale, (real_t)exp(LN2 * 0.25 * scale_factor));
 
     /* Scale random vector to desired target energy */
     for (i = 0; i < size; i++)
-        spec[i] *= scale;
+        spec[i] = MUL(spec[i], scale);
 }
 
 void pns_decode(ic_stream *ics, real_t *spec)
--- 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.6 2002/03/16 13:38:36 menno Exp $
+** $Id: specrec.c,v 1.7 2002/05/24 17:26:12 menno Exp $
 **/
 
 /*
@@ -255,13 +255,13 @@
         if (q < IQ_TABLE_SIZE)
             return iq_table[q];
         else
-            return iq_table[q>>3]*16;
+            return MUL(iq_table[q>>3], 16);
     } else if (q < 0) {
         q = -q;
         if (q < IQ_TABLE_SIZE)
             return -iq_table[q];
         else
-          return -iq_table[q>>3]*16;
+          return -MUL(iq_table[q>>3], 16);
     } else {
         return 0.0f;
     }
@@ -321,10 +321,10 @@
             /* minimum size of a sf band is 4 and always a multiple of 4 */
             for ( ; k < top; k+=4)
             {
-                *fp++ *= scale;
-                *fp++ *= scale;
-                *fp++ *= scale;
-                *fp++ *= scale;
+                *fp = MUL(*fp, scale); fp++;
+                *fp = MUL(*fp, scale); fp++;
+                *fp = MUL(*fp, scale); fp++;
+                *fp = MUL(*fp, scale); fp++;
             }
         }
         groups += ics->window_group_length[g];
--- 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.9 2002/05/14 13:40:31 menno Exp $
+** $Id: tns.c,v 1.10 2002/05/24 17:26:12 menno Exp $
 **/
 
 #include "common.h"
@@ -160,7 +160,7 @@
     for (m = 1; m <= order; m++)
     {
         for (i = 1; i < m; i++) /* loop only while i<m */
-            b[i] = a[i] + tmp2[m-1] * a[m-i];
+            b[i] = a[i] + MUL(tmp2[m-1], a[m-i]);
 
         for (i = 1; i < m; i++) /* loop only while i<m */
             a[i] = b[i];
@@ -193,7 +193,7 @@
         y = *spectrum;
 
         for (j = 0; j < order; j++)
-            y -= lpc[j+1] * state[j];
+            y -= MUL(lpc[j+1], state[j]);
 
         for (j = order-1; j > 0; j--)
             state[j] = state[j-1];
@@ -228,7 +228,7 @@
         y = *spectrum;
 
         for (j = 0; j < order; j++)
-            y += lpc[j+1] * state[j];
+            y += MUL(lpc[j+1], state[j]);
 
         for (j = order-1; j > 0; j--)
             state[j] = state[j-1];