diff --git a/libcelt/celt.c b/libcelt/celt.c index 8de9ddeb85ffc1035571fcab6e0b6e735f8e5719..037b5326fc7a8ed3b60d083869831239e228d323 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -440,42 +440,38 @@ static void compute_inv_mdcts(const CELTMode *mode, int shortBlocks, celt_sig *X const int C = CHANNELS(_C); const int N = mode->shortMdctSize<<LM; const int overlap = OVERLAP(mode); + VARDECL(opus_val32, x); + SAVE_STACK; + + ALLOC(x, N+overlap, opus_val32); c=0; do { int j; - VARDECL(opus_val32, x); - VARDECL(opus_val32, tmp); - int b; - int N2 = N; - int B = 1; - SAVE_STACK; - - ALLOC(x, N+overlap, opus_val32); - ALLOC(tmp, N, opus_val32); + int b; + int N2 = N; + int B = 1; - if (shortBlocks) - { - N2 = mode->shortMdctSize; - B = shortBlocks; - } - /* Prevents problems from the imdct doing the overlap-add */ - CELT_MEMSET(x, 0, overlap); + if (shortBlocks) + { + N2 = mode->shortMdctSize; + B = shortBlocks; + } + /* Prevents problems from the imdct doing the overlap-add */ + CELT_MEMSET(x, 0, overlap); - for (b=0;b<B;b++) - { - /* De-interleaving the sub-frames */ - for (j=0;j<N2;j++) - tmp[j] = X[(j*B+b)+c*N2*B]; - clt_mdct_backward(&mode->mdct, tmp, x+N2*b, mode->window, overlap, shortBlocks ? mode->maxLM : mode->maxLM-LM); - } + for (b=0;b<B;b++) + { + /* IMDCT on the interleaved the sub-frames */ + clt_mdct_backward(&mode->mdct, &X[b+c*N2*B], x+N2*b, mode->window, overlap, shortBlocks ? mode->maxLM : mode->maxLM-LM, B); + } - for (j=0;j<overlap;j++) - out_mem[c][j] = x[j] + overlap_mem[c][j]; - for (;j<N;j++) - out_mem[c][j] = x[j]; - for (j=0;j<overlap;j++) - overlap_mem[c][j] = x[N+j]; - RESTORE_STACK; + for (j=0;j<overlap;j++) + out_mem[c][j] = x[j] + overlap_mem[c][j]; + for (;j<N;j++) + out_mem[c][j] = x[j]; + for (j=0;j<overlap;j++) + overlap_mem[c][j] = x[N+j]; } while (++c<C); + RESTORE_STACK; } static void deemphasis(celt_sig *in[], opus_val16 *pcm, int N, int _C, int downsample, const opus_val16 *coef, celt_sig *mem) diff --git a/libcelt/mdct.c b/libcelt/mdct.c index e04f437250b346092e3cda1de163674f2453190a..4a41517bd4e9cb71ccffecfe3f1e453c3ec062d0 100644 --- a/libcelt/mdct.c +++ b/libcelt/mdct.c @@ -202,7 +202,8 @@ void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar RESTORE_STACK; } -void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, const opus_val16 * restrict window, int overlap, int shift) +void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar * restrict out, + const opus_val16 * restrict window, int overlap, int shift, int stride) { int i; int N, N2, N4; @@ -227,7 +228,7 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala { /* Temp pointers to make it really clear to the compiler what we're doing */ const kiss_fft_scalar * restrict xp1 = in; - const kiss_fft_scalar * restrict xp2 = in+N2-1; + const kiss_fft_scalar * restrict xp2 = in+stride*(N2-1); kiss_fft_scalar * restrict yp = f2; const kiss_twiddle_scalar *t = &l->trig[0]; for(i=0;i<N4;i++) @@ -238,8 +239,8 @@ void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scala /* works because the cos is nearly one */ *yp++ = yr - S_MUL(yi,sine); *yp++ = yi + S_MUL(yr,sine); - xp1+=2; - xp2-=2; + xp1+=2*stride; + xp2-=2*stride; } } diff --git a/libcelt/mdct.h b/libcelt/mdct.h index 9d43ae97810937b05eda0f1b208e10133db5c9da..32942ca76376b7b651f32b7172d833ff097849ec 100644 --- a/libcelt/mdct.h +++ b/libcelt/mdct.h @@ -60,6 +60,7 @@ void clt_mdct_forward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar /** Compute a backward MDCT (no scaling) and performs weighted overlap-add (scales implicitly by 1/2) */ -void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out, const opus_val16 * restrict window, int overlap, int shift); +void clt_mdct_backward(const mdct_lookup *l, kiss_fft_scalar *in, kiss_fft_scalar *out, + const opus_val16 * restrict window, int overlap, int shift, int stride); #endif diff --git a/libcelt/tests/mdct-test.c b/libcelt/tests/mdct-test.c index 25bb017558d26c706e09996184db4d452babadea..604d0fcc0c397934e62e17ee8656d73fc0e52f0f 100644 --- a/libcelt/tests/mdct-test.c +++ b/libcelt/tests/mdct-test.c @@ -122,7 +122,7 @@ void test1d(int nfft,int isinverse) { for (k=0;k<nfft;++k) out[k] = 0; - clt_mdct_backward(&cfg,in,out, window, nfft/2, 0); + clt_mdct_backward(&cfg,in,out, window, nfft/2, 0, 1); check_inv(in,out,nfft,isinverse); } else { clt_mdct_forward(&cfg,in,out,window, nfft/2, 0);