shithub: aacdec

Download patch

ref: d192652be0d3eb46ef2c96c073ef183fef1eb063
parent: c8e86c51125df3a307e1d674534a537287b079f4
author: menno <menno>
date: Sun Apr 21 05:00:40 EDT 2002

Finished QMF filterbanks for SBR

--- 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.8 2002/04/20 22:20:15 menno Exp $
+** $Id: common.h,v 1.9 2002/04/21 09:00:40 menno Exp $
 **/
 
 #ifndef __COMMON_H__
@@ -170,6 +170,11 @@
   #include <math.h>
 
 #endif
+
+typedef struct {
+    real_t re;
+    real_t im;
+} complex_t;
 
 
 /* common functions */
--- 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.7 2002/04/07 21:26:04 menno Exp $
+** $Id: mdct.c,v 1.8 2002/04/21 09:00:40 menno Exp $
 **/
 
 /*
@@ -57,8 +57,8 @@
 
     mdct->N = N;
     mdct->sincos = (faad_sincos*)malloc(N/4*sizeof(faad_sincos));
-    mdct->Z1 = (fftw_complex*)malloc(N/4*sizeof(faad_complex));
-    mdct->Z2 = (fftw_complex*)malloc(N/4*sizeof(faad_complex));
+    mdct->Z1 = (complex_t*)malloc(N/4*sizeof(complex_t));
+    mdct->Z2 = (complex_t*)malloc(N/4*sizeof(complex_t));
 
     for (k = 0; k < N/4; k++)
     {
@@ -89,8 +89,8 @@
 {
     uint16_t k;
 
-    fftw_complex *Z1    = mdct->Z1;
-    fftw_complex *Z2    = mdct->Z2;
+    complex_t *Z1       = mdct->Z1;
+    complex_t *Z2       = mdct->Z2;
     faad_sincos *sincos = mdct->sincos;
 
     uint16_t N  = mdct->N;
@@ -142,8 +142,8 @@
 {
     uint16_t k;
 
-    fftw_complex *Z1    = mdct->Z1;
-    fftw_complex *Z2    = mdct->Z2;
+    complex_t *Z1       = mdct->Z1;
+    complex_t *Z2       = mdct->Z2;
     faad_sincos *sincos = mdct->sincos;
 
     uint16_t N  = mdct->N;
--- a/libfaad/mdct.h
+++ b/libfaad/mdct.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: mdct.h,v 1.6 2002/04/07 21:26:04 menno Exp $
+** $Id: mdct.h,v 1.7 2002/04/21 09:00:40 menno Exp $
 **/
 
 #ifndef __MDCT_H__
@@ -29,18 +29,13 @@
 #include <fftw.h>
 
 typedef struct {
-    real_t re;
-    real_t im;
-} faad_complex;
-
-typedef struct {
     real_t sin;
     real_t cos;
 } faad_sincos;
 
 typedef struct {
-    fftw_complex *Z1;
-    fftw_complex *Z2;
+    complex_t *Z1;
+    complex_t *Z2;
     faad_sincos *sincos;
     fftw_plan plan_backward;
 #ifdef LTP_DEC
--- a/libfaad/sbr_dec.c
+++ b/libfaad/sbr_dec.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: sbr_dec.c,v 1.1 2002/04/20 22:20:15 menno Exp $
+** $Id: sbr_dec.c,v 1.2 2002/04/21 09:00:40 menno Exp $
 **/
 
 #include "common.h"
@@ -23,5 +23,7 @@
 
 #ifdef SBR
 
+#include "sbr_syntax.h"
+#include "sbr_qmf.h"
 
 #endif
--- a/libfaad/sbr_huff.c
+++ b/libfaad/sbr_huff.c
@@ -16,12 +16,14 @@
 ** along with this program; if not, write to the Free Software 
 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 **
-** $Id: sbr_huff.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+** $Id: sbr_huff.c,v 1.2 2002/04/21 09:00:40 menno Exp $
 **/
 
 #include "common.h"
 
 #ifdef SBR
+
+#include "bits.h"
 
 
 #endif
--- a/libfaad/sbr_qmf.c
+++ b/libfaad/sbr_qmf.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: sbr_qmf.c,v 1.1 2002/04/20 14:45:13 menno Exp $
+** $Id: sbr_qmf.c,v 1.2 2002/04/21 09:00:40 menno Exp $
 **/
 
 #include "common.h"
@@ -23,10 +23,16 @@
 
 #ifdef SBR
 
-void sbr_qmf_analysis()
+#include "sbr_qmf.h"
+
+void sbr_qmf_analysis(real_t *input, complex_t **Xlow)
 {
     uint8_t l;
+    real_t x[320], z[320], u[64];
+    real_t *inptr = input;
 
+    memset(x, 0, 320*sizeof(real_t));
+
     /* qmf subsample l */
     for (l = 0; l < 32; l++)
     {
@@ -34,15 +40,15 @@
         uint16_t n;
 
         /* shift input buffer x */
-        for (n = 320 - 1; n <= 0; n++)
+        for (n = 320 - 1; n <= 0; n--)
         {
             x[n] = x[n - 32];
         }
 
         /* add new samples to input buffer x */
-        for (n = 32 - 1; n <= 0; n++)
+        for (n = 32 - 1; n <= 0; n--)
         {
-            x[n] = input_sample;
+            x[n] = *inptr++;
         }
 
         /* window by 320 coefficients to produce array z */
@@ -66,17 +72,87 @@
         /* calculate 32 subband samples by introducing Xlow */
         for (k = 0; k < 32; k++)
         {
-            Xlow[k][l] = 0.0;
+            Xlow[k][l].re = 0.0;
+            Xlow[k][l].im = 0.0;
+
             for (n = 0; n < 64; n++)
             {
-                Xlow[k][l] += u[n] * 2 * exp(i*M_PI/64 * (k + 0.5) * (2*n - 0.5));
+                /* complex exponential
+                Xlow[k][l] += 2.0 * u[n] * exp(i*M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
+                */
+                Xlow[k][l].re += 2.0 * u[n] * cos(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
+                Xlow[k][l].im += 2.0 * u[n] * sin(M_PI/64.0 * (k + 0.5) * (2.0*n - 0.5));
             }
         }
     }
 }
 
-void sbr_qmf_analysis()
+void sbr_qmf_synthesis(complex_t **Xlow, real_t *output)
 {
+    uint8_t l, k;
+    uint16_t n;
+    real_t v[640], w[640];
+    real_t *outptr = output;
+
+    memset(v, 0, 640 * sizeof(real_t));
+
+    /* qmf subsample l */
+    for (l = 0; l < 32; l++)
+    {
+        /* shift buffer */
+        for (n = 1280-1; n <= 128; n--)
+        {
+            v[n] = v[n - 128];
+        }
+
+        /* calculate 128 samples */
+        for (n = 0; n < 128; n++)
+        {
+            v[n] = 0;
+
+            for (k = 0; k < 64; k++)
+            {
+                complex_t vc;
+
+                /* complex exponential
+                vc = 64.0 * sin(i*M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
+                */
+                vc.re = 64.0 * cos(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
+                vc.im = 64.0 * sin(M_PI/128.0 * (k + 0.5) * (2.0*n - 255.0));
+
+                /* take the real part only */
+                v[n] += Xlow[k][l].re * vc.re - Xlow[k][l].im * vc.im;
+            }
+        }
+
+        for (n = 0; n < 4; n++)
+        {
+            for (k = 0; k < 64; k++)
+            {
+                w[128 * n +      k] = v[256 * n +       k];
+                w[128 * n + 64 + k] = v[256 * n + 192 + k];
+            }
+        }
+
+        /* window */
+        for (n = 0; n < 640; n++)
+        {
+            w[n] *= qmf_c[n];
+        }
+
+        /* calculate 64 output samples */
+        for (k = 0; k < 64; k++)
+        {
+            real_t sample = 0.0;
+
+            for (n = 0; n < 9; n++)
+            {
+                sample += w[64 * n + k];
+            }
+
+            *outptr++ = sample;
+        }
+    }
 }
 
 static real_t qmf_c[] = {
--- a/libfaad/sbr_qmf.h
+++ b/libfaad/sbr_qmf.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: sbr_qmf.h,v 1.1 2002/04/20 14:45:13 menno Exp $
+** $Id: sbr_qmf.h,v 1.2 2002/04/21 09:00:40 menno Exp $
 **/
 
 #ifdef SBR
@@ -30,6 +30,8 @@
 
 static real_t qmf_c[];
 
+void sbr_qmf_analysis(real_t *input, complex_t **Xlow);
+void sbr_qmf_synthesis(complex_t **Xlow, real_t *output);
 
 #ifdef __cplusplus
 }
--- a/libfaad/sbr_syntax.c
+++ b/libfaad/sbr_syntax.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: sbr_syntax.c,v 1.2 2002/04/20 22:20:15 menno Exp $
+** $Id: sbr_syntax.c,v 1.3 2002/04/21 09:00:40 menno Exp $
 **/
 
 /*
@@ -521,7 +521,7 @@
                     sbr->bs_data_env[ch][env][0] = faad_getbits(ld, 7
                         DEBUGVAR(1,275,"sbr_envelope(): bs_data_env"));
                 }
-                for (band = 1; band < num_env_bands[bs_freq_res[ch][env]]; band++)
+                for (band = 1; band < sbr->num_env_bands[bs_freq_res[ch][env]]; band++)
                 {
                     sbr->bs_data_env[ch][env][band] = huff_dec(ld, f_huff, bs_codeword);
                 }