shithub: aacdec

Download patch

ref: 5c797740cb2c9e6dd6a86f3829e1ff0ef029f5e3
parent: 86439f26b27ba6ae1a06704181a2dec722001a38
author: menno <menno>
date: Wed Mar 27 14:09:29 EST 2002

Bugfix for non-meaningful window transitions

--- 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.4 2002/03/16 15:09:59 menno Exp $
+** $Id: common.h,v 1.5 2002/03/27 19:09:29 menno Exp $
 **/
 
 #ifndef __COMMON_H__
@@ -65,7 +65,8 @@
 /* #define USE_DOUBLE_PRECISION */
 
 /* use table lookup twiddle factors in MDCT [more memory, higher speed],
-   otherwise recurrence relations are used [no memory usage, lower speed] */
+   otherwise recurrence relations are used [no memory usage, lower speed,
+   and loss of accuracy] */
 #define USE_TWIDDLE_TABLE
 
 /* Allow decoding of MAIN profile AAC */
--- 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.5 2002/03/16 13:38:37 menno Exp $
+** $Id: filtbank.c,v 1.6 2002/03/27 19:09:29 menno Exp $
 **/
 
 #include "common.h"
@@ -33,6 +33,21 @@
 {
     uint16_t i;
 
+    /* normal */
+    mdct_init(&(fb->mdct256), 256);
+    mdct_init(&(fb->mdct2048), 2048);
+
+    fb->long_window[0]  = malloc(BLOCK_LEN_LONG*sizeof(real_t));
+    fb->short_window[0] = malloc(BLOCK_LEN_SHORT*sizeof(real_t));
+    fb->long_window[1]  = kbd_long;
+    fb->short_window[1] = kbd_short;
+
+    /* calculate the sine windows */
+    for (i = 0; i < BLOCK_LEN_LONG; i++)
+        fb->long_window[0][i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_LONG) * (i + 0.5));
+    for (i = 0; i < BLOCK_LEN_SHORT; i++)
+        fb->short_window[0][i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_SHORT) * (i + 0.5));
+
 #ifdef LD_DEC
     /* LD */
     mdct_init(&(fb->mdct1024), 1024);
@@ -52,34 +67,19 @@
     for (; i < BLOCK_LEN_LD; i++)
         fb->ld_window[1][i] = 1.0;
 #endif
-
-    /* normal */
-    mdct_init(&(fb->mdct256), 256);
-    mdct_init(&(fb->mdct2048), 2048);
-
-    fb->long_window[0]  = malloc(BLOCK_LEN_LONG*sizeof(real_t));
-    fb->short_window[0] = malloc(BLOCK_LEN_SHORT*sizeof(real_t));
-    fb->long_window[1]  = kbd_long;
-    fb->short_window[1] = kbd_short;
-
-    /* calculate the sine windows */
-    for (i = 0; i < BLOCK_LEN_LONG; i++)
-        fb->long_window[0][i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_LONG) * (i + 0.5));
-    for (i = 0; i < BLOCK_LEN_SHORT; i++)
-        fb->short_window[0][i] = (real_t)sin(M_PI / (2.0 * BLOCK_LEN_SHORT) * (i + 0.5));
 }
 
 void filter_bank_end(fb_info *fb)
 {
     mdct_end(&(fb->mdct256));
-#ifdef LD_DEC
-    mdct_end(&(fb->mdct1024));
-#endif
     mdct_end(&(fb->mdct2048));
 
     if (fb->long_window[0]) free(fb->long_window[0]);
     if (fb->short_window[0]) free(fb->short_window[0]);
+
 #ifdef LD_DEC
+    mdct_end(&(fb->mdct1024));
+
     if (fb->ld_window[0]) free(fb->ld_window[0]);
     if (fb->ld_window[1]) free(fb->ld_window[1]);
 #endif
@@ -179,14 +179,14 @@
     case 2048:
         IMDCT_2048(&(fb->mdct2048), in_data, out_data);
         return;
+    case 256:
+        IMDCT_256(&(fb->mdct256), in_data, out_data);
+        return;
 #ifdef LD_DEC
     case 1024:
         IMDCT_1024(&(fb->mdct1024), in_data, out_data);
         return;
 #endif
-    case 256:
-        IMDCT_256(&(fb->mdct256), in_data, out_data);
-        return;
     }
 }
 
@@ -197,14 +197,14 @@
     case 2048:
         MDCT_2048(&(fb->mdct2048), in_data, out_data);
         return;
+    case 256:
+        MDCT_256(&(fb->mdct256), in_data, out_data);
+        return;
 #ifdef LD_DEC
     case 1024:
         MDCT_1024(&(fb->mdct1024), in_data, out_data);
         return;
 #endif
-    case 256:
-        MDCT_256(&(fb->mdct256), in_data, out_data);
-        return;
     }
 }
 
@@ -213,6 +213,7 @@
                   real_t *time_out, uint8_t object_type)
 {
     real_t *o_buf, *transf_buf;
+    real_t *obuf_temp;
 
     real_t *window_long;
     real_t *window_long_prev;
@@ -294,7 +295,10 @@
         break;
 
     case EIGHT_SHORT_SEQUENCE:
-        fp = o_buf + nflat_ls;
+        obuf_temp = malloc(2*nlong*sizeof(real_t));
+        vzero(obuf_temp+2*nlong-1, 2*nlong);
+
+		fp = obuf_temp;
         for (win = 8-1; win >= 0; --win)
         {
             /* inverse transform */
@@ -309,13 +313,19 @@
 
             /* reversed window function on second half of the new data */
             vmult2(transf_buf+nshort, window_short+nshort-1, fp+nshort, nshort);
-
-            /* shift to next short block */
+			
+			/* shift to next short block */
             freq_in += nshort;
             fp      += nshort;
             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);
         break;
 
     case LONG_STOP_SEQUENCE:
@@ -322,8 +332,8 @@
         /* inverse transform */
         imdct(fb, freq_in, transf_buf, 2*nlong);
 
-        /* zero first part of first half of the data (window function = 0.0) */
-        vzero(transf_buf+nflat_ls-1, nflat_ls);
+		/* zero first part of first half of the data (window function = 0.0) */
+		vzero(transf_buf+nflat_ls-1, nflat_ls);
 
         /* window function (previous) on part of the first half of
            the new data */
@@ -335,14 +345,11 @@
 
         /* overlap and add second half of the old data with first half
            of the new data */
-        vadd(transf_buf+nflat_ls, o_buf+nflat_ls, o_buf+nflat_ls, nshort);
+        vadd(transf_buf, o_buf, o_buf, nlong);
 
-        /* copy last part of first half of the data (window function = 1.0) */
-        vcopy(transf_buf+nflat_ls+nshort, o_buf+nflat_ls+nshort, nflat_ls);
-
-        /* reversed window function on second half of the new data */
+        /* reversed window function on second half of the new data */      
         vmult2(transf_buf+nlong, window_long+nlong-1, o_buf+nlong, nlong);
-        break;
+		break;
     }
 
     /* save second half of data */
--- 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.5 2002/03/16 13:38:36 menno Exp $
+** $Id: mdct.c,v 1.6 2002/03/27 19:09:29 menno Exp $
 **/
 
 /*
@@ -369,7 +369,7 @@
 
 void IMDCT_2048(mdct_info *mdct, fftw_real *in_data, fftw_real *out_data)
 {
-    fftw_complex FFTarray[512];    /* the array for in-place FFT */
+    fftw_complex FFTarray[512]; /* the array for in-place FFT */
     real_t tempr, tempi, fac;
 
 #ifdef USE_TWIDDLE_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.7 2002/03/16 19:18:11 menno Exp $
+** $Id: tns.c,v 1.8 2002/03/27 19:09:29 menno Exp $
 **/
 
 #include "common.h"
@@ -129,7 +129,7 @@
     uint8_t coef_res2, s_mask, n_mask;
     int8_t tmp[TNS_MAX_ORDER+1];
     real_t tmp2[TNS_MAX_ORDER+1], b[TNS_MAX_ORDER+1];
-    real_t iqfac, iqfac_m;
+    real_t iqfac;
 
     /* Some internal tables */
     static uint8_t sgn_mask[] = { 0x2, 0x4, 0x8 };
@@ -145,11 +145,13 @@
         tmp[i] = (coef[i] & s_mask) ? (coef[i] | n_mask) : coef[i];
 
     /* Inverse quantization */
-    iqfac = ((1 << (coef_res_bits-1)) - 0.5f) / M_PI_2;
-    iqfac_m = ((1 << (coef_res_bits-1)) + 0.5f) / M_PI_2;
+    if (tmp[i] >= 0)
+        iqfac = ((1 << (coef_res_bits-1)) - 0.5f) / M_PI_2;
+    else
+        iqfac = ((1 << (coef_res_bits-1)) + 0.5f) / M_PI_2;
 
     for (i = 0; i < order; i++)
-        tmp2[i] = (real_t)sin(tmp[i] / ((tmp[i] >= 0) ? iqfac : iqfac_m));
+        tmp2[i] = (real_t)sin(tmp[i] / iqfac);
 
     /* Conversion to LPC coefficients */
     a[0] = 1;