From abd67230c196605aadd991e47ede0aee9c87dba9 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Sat, 3 Oct 2009 00:25:15 -0400 Subject: [PATCH] No longer interleaving channels of the normalised spectrum. Also fixed the indexing of the pitch code for stereo --- libcelt/bands.c | 86 ++++++++++++++++--------------------------------- 1 file changed, 28 insertions(+), 58 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index 0137853d..29008454 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -104,7 +104,7 @@ void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_n E = VSHR32(bank[i+c*m->nbEBands], shift); g = EXTRACT16(celt_rcp(SHL32(E,3))); j=eBands[i]; do { - X[j*C+c] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g); + X[j+c*N] = MULT16_16_Q15(VSHR32(freq[j+c*N],shift-1),g); } while (++jnbEBands); } @@ -170,7 +170,7 @@ void normalise_bands(const CELTMode *m, const celt_sig_t * restrict freq, celt_n int j; celt_word16_t g = 1.f/(1e-10+bank[i+c*m->nbEBands]); for (j=eBands[i];jnbEBands],1); j=eBands[i]; do { - freq[j+c*N] = SHL32(MULT16_32_Q15(X[j*C+c], g),2); + freq[j+c*N] = SHL32(MULT16_32_Q15(X[j+c*N], g),2); } while (++jnbEBands];inbEBands+1];i++) @@ -224,13 +224,18 @@ int compute_pitch_gain(const CELTMode *m, const celt_sig_t *X, const celt_sig_t const int C = CHANNELS(m); celt_word32_t Sxy=0, Sxx=0, Syy=0; int len = m->pitchEnd; + const int N = FRAMESIZE(m); #ifdef FIXED_POINT int shift = 0; celt_word32_t maxabs=0; - for (j=0;jpitchEnd; - + + N = FRAMESIZE(m); gain = ADD16(QCONST16(.5,14), MULT16_16_16(QCONST16(.05,14),gain_id)); delta = PDIV32_16(gain, len); if (pred) @@ -311,7 +317,7 @@ void apply_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int gain celt_word16_t gg = gain; for (j=0;j>1;i++) - { - x[i<<1] = tmp[i]; - x[(i<<1)+1] = tmp[i+(N>>1)]; - } - RESTORE_STACK; -} - -void deinterleave(celt_norm_t *x, int N) -{ - int i; - VARDECL(celt_norm_t, tmp); - SAVE_STACK; - ALLOC(tmp, N, celt_norm_t); - - for (i=0;i>1;i++) - { - x[i] = tmp[i<<1]; - x[i+(N>>1)] = tmp[(i<<1)+1]; - } - RESTORE_STACK; -} - #endif /* DISABLE_STEREO */ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int *last_decision) { - int i, c; + int i, c, N0; int NR=0; celt_word32_t ratio = EPSILON; const int C = CHANNELS(m); const celt_int16_t * restrict eBands = m->eBands; + + N0 = FRAMESIZE(m); + for (c=0;cnbEBands;i++) @@ -404,13 +379,13 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, int max_i=0; celt_word16_t max_val=EPSILON; celt_word32_t floor_ener=EPSILON; - celt_norm_t * restrict x = X+C*eBands[i]+c; + celt_norm_t * restrict x = X+eBands[i]+c*N0; N = eBands[i+1]-eBands[i]; for (j=0;jmax_val) + if (ABS16(x[j])>max_val) { - max_val = ABS16(x[C*j]); + max_val = ABS16(x[j]); max_i = j; } } @@ -423,13 +398,13 @@ int folding_decision(const CELTMode *m, celt_norm_t *X, celt_word16_t *average, #else floor_ener = QCONST32(1.,28)-MULT16_16(max_val,max_val); if (max_i < N-1) - floor_ener -= MULT16_16(x[C*(max_i+1)], x[C*(max_i+1)]); + floor_ener -= MULT16_16(x[(max_i+1)], x[(max_i+1)]); if (max_i < N-2) - floor_ener -= MULT16_16(x[C*(max_i+2)], x[C*(max_i+2)]); + floor_ener -= MULT16_16(x[(max_i+2)], x[(max_i+2)]); if (max_i > 0) - floor_ener -= MULT16_16(x[C*(max_i-1)], x[C*(max_i-1)]); + floor_ener -= MULT16_16(x[(max_i-1)], x[(max_i-1)]); if (max_i > 1) - floor_ener -= MULT16_16(x[C*(max_i-2)], x[C*(max_i-2)]); + floor_ener -= MULT16_16(x[(max_i-2)], x[(max_i-2)]); floor_ener = MAX32(floor_ener, EPSILON); #endif if (N>7) @@ -527,7 +502,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t *b const celt_int16_t * restrict eBands = m->eBands; celt_norm_t * restrict norm, *X, *Y; VARDECL(celt_norm_t, _norm); - const int C = CHANNELS(m); int B; celt_word16_t mid, side; SAVE_STACK; @@ -537,7 +511,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t *b norm = _norm; balance = 0; - deinterleave(_X, C*eBands[m->nbEBands+1]); X = _X; Y = _X+eBands[m->nbEBands+1]; for (i=0;inbEBands;i++) @@ -746,7 +719,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t *b renormalise_vector(X+eBands[i], Q15ONE, N, 1); renormalise_vector(Y+eBands[i], Q15ONE, N, 1); } - interleave(_X, C*eBands[m->nbEBands+1]); RESTORE_STACK; } #endif /* DISABLE_STEREO */ @@ -822,7 +794,6 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t const celt_int16_t * restrict eBands = m->eBands; celt_norm_t * restrict norm, *X, *Y; VARDECL(celt_norm_t, _norm); - const int C = CHANNELS(m); int B; celt_word16_t mid, side; SAVE_STACK; @@ -1015,7 +986,6 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t *_X, const celt_ener_t renormalise_vector(X+eBands[i], Q15ONE, N, 1); renormalise_vector(Y+eBands[i], Q15ONE, N, 1); } - interleave(_X, C*eBands[m->nbEBands+1]); RESTORE_STACK; }