Window both sides of overlap when adding them.
authorNils Wallménius <nils@rockbox.org>
Sat, 1 Dec 2012 20:11:50 +0000 (21:11 +0100)
committerJean-Marc Valin <jmvalin@jmvalin.ca>
Sat, 1 Dec 2012 20:54:04 +0000 (15:54 -0500)
Signed-off-by: Jean-Marc Valin <jmvalin@jmvalin.ca>
celt/celt_decoder.c
celt/celt_encoder.c
celt/mdct.c

index 68671db..78d5f21 100644 (file)
@@ -495,7 +495,7 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
          }
 
          /* Move memory one frame to the left */
-         OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap);
+         OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);
 
          /* Extrapolate excitation with the right period, taking decay into account */
          for (i=0;i<len;i++)
@@ -562,11 +562,8 @@ static void celt_decode_lost(CELTDecoder * OPUS_RESTRICT st, opus_val16 * OPUS_R
             MDCT of next frames. */
          for (i=0;i<overlap/2;i++)
          {
-            opus_val32 tmp;
-            tmp = MULT16_32_Q15(mode->window[i],           etmp[overlap-1-i]) +
-                  MULT16_32_Q15(mode->window[overlap-i-1], etmp[i          ]);
-            out_mem[c][MAX_PERIOD+i] = MULT16_32_Q15(mode->window[overlap-i-1], tmp);
-            out_mem[c][MAX_PERIOD+overlap-i-1] = MULT16_32_Q15(mode->window[i], tmp);
+            out_mem[c][MAX_PERIOD+i] = MULT16_32_Q15(mode->window[i], etmp[overlap-1-i]) +
+                                       MULT16_32_Q15(mode->window[overlap-i-1], etmp[i]);
          }
       } while (++c<C);
    }
@@ -858,7 +855,7 @@ int celt_decode_with_ec(CELTDecoder * OPUS_RESTRICT st, const unsigned char *dat
    denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M);
 
    c=0; do {
-      OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap);
+      OPUS_MOVE(decode_mem[c], decode_mem[c]+N, DECODE_BUFFER_SIZE-N+overlap/2);
    } while (++c<CC);
 
    c=0; do {
index 8b92811..d0274b8 100644 (file)
@@ -1741,7 +1741,7 @@ int celt_encode_with_ec(CELTEncoder * OPUS_RESTRICT st, const opus_val16 * pcm,
       denormalise_bands(mode, X, freq, bandE, st->start, effEnd, C, M);
 
       c=0; do {
-         OPUS_MOVE(st->syn_mem[c], st->syn_mem[c]+N, 2*MAX_PERIOD-N+overlap);
+         OPUS_MOVE(st->syn_mem[c], st->syn_mem[c]+N, 2*MAX_PERIOD-N+overlap/2);
       } while (++c<CC);
 
       if (CC==2&&C==1)
index c0d04b0..3123908 100644 (file)
@@ -291,10 +291,11 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
       }
       for(; i < N4; i++)
       {
-         kiss_fft_scalar x1;
+         kiss_fft_scalar x1, x2;
          x1 = *fp1--;
-         *yp1++ +=-MULT16_32_Q15(*wp1, x1);
-         *xp1-- += MULT16_32_Q15(*wp2, x1);
+         x2 = *yp1;
+         *yp1++ = MULT16_32_Q15(*wp2, x2) - MULT16_32_Q15(*wp1, x1);
+         *xp1-- = MULT16_32_Q15(*wp1, x2) + MULT16_32_Q15(*wp2, x1);
          wp1++;
          wp2--;
       }
@@ -302,9 +303,6 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
    {
       kiss_fft_scalar * OPUS_RESTRICT fp2 = f2+N4;
       kiss_fft_scalar * OPUS_RESTRICT xp2 = out+N2;
-      kiss_fft_scalar * OPUS_RESTRICT yp2 = out+N-1-(N4-overlap/2);
-      const opus_val16 * OPUS_RESTRICT wp1 = window;
-      const opus_val16 * OPUS_RESTRICT wp2 = window+overlap-1;
       for(i = 0; i< N4-overlap/2; i++)
       {
          *xp2 = *fp2;
@@ -313,12 +311,7 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala
       }
       for(; i < N4; i++)
       {
-         kiss_fft_scalar x2;
-         x2 = *fp2++;
-         *yp2--  = MULT16_32_Q15(*wp1, x2);
-         *xp2++  = MULT16_32_Q15(*wp2, x2);
-         wp1++;
-         wp2--;
+         *xp2++ = *fp2++;
       }
    }
    RESTORE_STACK;