Moved the windowing from compute_inv_mdcts() to mdct_backward()
authorJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Tue, 22 Apr 2008 02:18:36 +0000 (12:18 +1000)
committerJean-Marc Valin <Jean-Marc.Valin@csiro.au>
Tue, 22 Apr 2008 02:18:36 +0000 (12:18 +1000)
libcelt/celt.c
libcelt/mdct.c
libcelt/mdct.h
tests/mdct-test.c

index ec7b544..63e8c60 100644 (file)
@@ -199,21 +199,21 @@ static void compute_inv_mdcts(const CELTMode *mode, const celt_word16_t * restri
    {
       int j;
       if (C==1) {
-         mdct_backward(lookup, X, x);
+         mdct_backward(lookup, X, x, window, overlap);
       } else {
          /* De-interleaving the sub-frames */
          for (j=0;j<N;j++)
             tmp[j] = X[C*j+c];
-         mdct_backward(lookup, tmp, x);
+         mdct_backward(lookup, tmp, x, window, overlap);
       }
          /* The first and last part would need to be set to zero if we actually
       wanted to use them. */
       for (j=0;j<overlap;j++)
-         out_mem[C*(MAX_PERIOD-N)+C*j+c] = 2*(mdct_overlap[C*j+c]+MULT16_32_Q15(window[j],x[j+N4]));
+         out_mem[C*(MAX_PERIOD-N)+C*j+c] = mdct_overlap[C*j+c]+x[j+N4];
       for (j=0;j<overlap;j++)
-         mdct_overlap[C*(overlap-j-1)+c] = MULT16_32_Q15(window[j],x[2*N-j-N4-1]);
+         mdct_overlap[C*(overlap-j-1)+c] = x[2*N-j-N4-1];
       for (j=0;j<2*N4;j++)
-         out_mem[C*(MAX_PERIOD-N)+C*(j+overlap)+c] = 2*x[j+N4+overlap];
+         out_mem[C*(MAX_PERIOD-N)+C*(j+overlap)+c] = x[j+N4+overlap];
    }
    RESTORE_STACK;
 }
index 4d39eae..a5ab3c3 100644 (file)
@@ -184,7 +184,7 @@ void mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * r
 }
 
 
-void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out)
+void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, const celt_word16_t * restrict window, int overlap)
 {
    int i;
    int N, N2, N4;
@@ -208,7 +208,7 @@ void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *
          *yp++ =  S_MUL(*xp2, t[N4]) - S_MUL(*xp1,t[0]);
          xp1+=2;
          xp2-=2;
-        t++;
+         t++;
       }
    }
 
@@ -238,8 +238,8 @@ void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *
       kiss_fft_scalar * restrict yp = out+N4;
       for(i = 0; i < N4; i++)
       {
-         *yp++ =-*fp1;
-         *yp++ = *fp2;
+         *yp++ =-*fp1*2;
+         *yp++ = *fp2*2;
          fp1 += 2;
          fp2 -= 2;
       }
@@ -247,14 +247,30 @@ void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *
 
    /* Mirror on both sides for TDAC */
    {
-      const kiss_fft_scalar * restrict xp1 = out+N2-1;
-      const kiss_fft_scalar * restrict xp2 = out+N2;
-      kiss_fft_scalar * restrict yp1 = out;
-      kiss_fft_scalar * restrict yp2 = out+N-1;
-      for(i = 0; i < N4; i++)
+      kiss_fft_scalar * restrict xp1 = out+N2-1;
+      kiss_fft_scalar * restrict xp2 = out+N2;
+      kiss_fft_scalar * restrict yp1 = out+N4-overlap/2;
+      kiss_fft_scalar * restrict yp2 = out+N-1-(N4-overlap/2);
+      const celt_word16_t * restrict wp1 = window;
+      const celt_word16_t * restrict wp2 = window+overlap-1;
+      for(i = 0; i< N4-overlap/2; i++)
+      {
+         *xp1 = *xp1;
+         *xp2 = *xp2;
+         xp1--;
+         xp2++;
+      }
+      for(; i < N4; i++)
       {
-         *yp1++ =-*xp1--;
-         *yp2-- = *xp2++;
+         kiss_fft_scalar x1, x2;
+         x1 = *xp1;
+         x2 = *xp2;
+         *yp1++ =-MULT16_32_Q15(*wp1, x1);
+         *yp2-- = MULT16_32_Q15(*wp1, x2);
+         *xp1-- = MULT16_32_Q15(*wp2, x1);
+         *xp2++ = MULT16_32_Q15(*wp2, x2);
+         wp1++;
+         wp2--;
       }
    }
    RESTORE_STACK;
index 46f3c13..991d7c3 100644 (file)
@@ -46,6 +46,7 @@
 #define MDCT_H
 
 #include "kiss_fft.h"
+#include "arch.h"
 
 typedef struct {
    int n;
@@ -60,6 +61,6 @@ void mdct_clear(mdct_lookup *l);
 void mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out, const celt_word16_t *window, int overlap);
 
 /** Compute a backward MDCT (no scaling) */
-void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out);
+void mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out, const celt_word16_t * restrict window, int overlap);
 
 #endif
index e4cc65c..c03c191 100644 (file)
@@ -99,7 +99,7 @@ void test1d(int nfft,int isinverse)
        
     if (isinverse)
     {
-       mdct_backward(&cfg,in,out);
+       mdct_backward(&cfg,in,out, NULL, 0);
        check_inv(in,out,nfft,isinverse);
     } else {
        mdct_forward(&cfg,in,out,NULL, 0);