From 095c1782c5925b5b37c433b18e438b833fe3f9e7 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Thu, 17 Sep 2009 22:38:34 -0400 Subject: [PATCH] Removed code that is no longer necessary with denorm pitch and spreading --- libcelt/bands.c | 203 ++++-------------------------------------------- libcelt/vq.c | 92 +++------------------- libcelt/vq.h | 4 +- 3 files changed, 27 insertions(+), 272 deletions(-) diff --git a/libcelt/bands.c b/libcelt/bands.c index ccf191fa..bd26547d 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -260,7 +260,7 @@ int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t * g = DIV32(SHL32(SHR32(num,shift),14),SHR32(den,shift)); if (Sxy < MULT16_32_Q15(fact, MULT16_16(celt_sqrt(EPSILON+Sxx),celt_sqrt(EPSILON+Syy)))) g = 0; - /* This MUST round down */ + /* This MUST round down so that we don't over-estimate the gain */ *gain_id = EXTRACT16(SHR32(MULT16_16(20,(g-QCONST16(.5,14))),14)); } #else @@ -271,6 +271,7 @@ int compute_new_pitch(const CELTMode *m, const celt_sig_t *X, const celt_sig_t * g = Sxy/(.1+Sxx+.03*Syy); if (Sxy < .5*fact*celt_sqrt(1+Sxx*Syy)) g = 0; + /* This MUST round down so that we don't over-estimate the gain */ *gain_id = floor(20*(g-.5)); } #endif @@ -301,43 +302,6 @@ void apply_new_pitch(const CELTMode *m, celt_sig_t *X, const celt_sig_t *P, int } } -/* Compute the best gain for each "pitch band" */ -int compute_pitch_gain(const CELTMode *m, const celt_norm_t *X, const celt_norm_t *P, celt_pgain_t *gains) -{ - int i; - int gain_sum = 0; - const celt_int16_t *pBands = m->pBands; - const int C = CHANNELS(m); - - for (i=0;inbPBands;i++) - { - celt_word32_t Sxy=0, Sxx=0; - int j; - /* We know we're not going to overflow because Sxx can't be more than 1 (Q28) */ - for (j=C*pBands[i];j Sxx) - Sxy = Sxx; - /* We need to be a bit conservative (multiply gain by 0.9), otherwise the - residual doesn't quantise well */ - Sxy = MULT16_32_Q15(QCONST16(.99f, 15), Sxy); - /* gain = Sxy/Sxx */ - gains[i] = EXTRACT16(celt_div(Sxy,ADD32(SHR32(Sxx, PGAIN_SHIFT),EPSILON))); - if (gains[i]>QCONST16(.5,15)) - gain_sum++; - } - return gain_sum > 5; -} - #ifndef DISABLE_STEREO static void stereo_band_mix(const CELTMode *m, celt_norm_t *X, const celt_ener_t *bank, int stereo_mode, int bandID, int dir) @@ -480,8 +444,7 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce int i, j, remaining_bits, balance; const celt_int16_t * restrict eBands = m->eBands; celt_norm_t * restrict norm; - VARDECL(celt_norm_t, _norm); const celt_int16_t *pBands = m->pBands; - int pband=-1; + VARDECL(celt_norm_t, _norm); int B; SAVE_STACK; @@ -525,41 +488,12 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce n = SHL16(celt_sqrt(eBands[i+1]-eBands[i]),11); - /* If pitch is in use and this eBand begins a pitch band, encode the pitch gain flag */ - if (pitch_used && eBands[i]< m->pitchEnd && eBands[i] == pBands[pband+1]) - { - int enabled = 1; - pband++; - if (remaining_bits >= 1< QCONST16(.5,15); - ec_enc_bits(enc, enabled, 1); - balance += 1<pitchEnd) { - for (j=eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_quant(X+eBands[i], W+eBands[i], eBands[i+1]-eBands[i], q, spread, P+eBands[i], enc); + alg_quant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, enc); } else { - for (j=eBands[i];jpBands; int pband=-1; int B; celt_word16_t mid, side; @@ -661,23 +594,6 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t } n = SHL16(celt_sqrt((eBands[i+1]-eBands[i])),11); - /* If pitch is in use and this eBand begins a pitch band, encode the pitch gain flag */ - if (pitch_used && eBands[i]< m->pitchEnd && eBands[i] == pBands[pband+1]) - { - int enabled = 1; - pband++; - if (remaining_bits >= 1< QCONST16(.5,15); - ec_enc_bits(enc, enabled, 1); - balance += 1< 8192 ? 1 : 0; c2 = 1-c; - if (eBands[i] >= m->pitchEnd && fold) - { - } else if (pitch_used && eBands[i] < m->pitchEnd) { - stereo_band_mix(m, P, bandE, qb==0, i, 1); - renormalise_vector(P+C*eBands[i], Q15ONE, N, C); - renormalise_vector(P+C*eBands[i]+1, Q15ONE, N, C); - deinterleave(P+C*eBands[i], C*N); - for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_quant(v, W+C*eBands[i], N, q1, spread, P+C*eBands[i]+c*N, enc); + alg_quant(v, N, q1, spread, enc); } else { v[0] = QCONST16(1.f, 14); v[1] = 0; @@ -783,27 +686,17 @@ void quant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t { intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B); deinterleave(P+C*eBands[i], C*N); - } else if (pitch_used && eBands[i] < m->pitchEnd) { - stereo_band_mix(m, P, bandE, qb==0, i, 1); - renormalise_vector(P+C*eBands[i], Q15ONE, N, C); - renormalise_vector(P+C*eBands[i]+1, Q15ONE, N, C); - deinterleave(P+C*eBands[i], C*N); - for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_quant(X+C*eBands[i], W+C*eBands[i], N, q1, spread, P+C*eBands[i], enc); + alg_quant(X+C*eBands[i], N, q1, spread, enc); } else for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_quant(X+C*eBands[i]+N, W+C*eBands[i], N, q2, spread, P+C*eBands[i]+N, enc); + alg_quant(X+C*eBands[i]+N, N, q2, spread, enc); } else for (j=C*eBands[i]+N;jeBands; celt_norm_t * restrict norm; VARDECL(celt_norm_t, _norm); - const celt_int16_t *pBands = m->pBands; - int pband=-1; int B; SAVE_STACK; @@ -890,40 +781,12 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, n = SHL16(celt_sqrt(eBands[i+1]-eBands[i]),11); - /* If pitch is in use and this eBand begins a pitch band, encode the pitch gain flag */ - if (pitch_used && eBands[i] < m->pitchEnd && eBands[i] == pBands[pband+1]) - { - int enabled = 1; - pband++; - if (remaining_bits >= 1<pitchEnd) { - for (j=eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, P+eBands[i], dec); + alg_unquant(X+eBands[i], eBands[i+1]-eBands[i], q, spread, dec); } else { - for (j=eBands[i];jpBands; int pband=-1; int B; celt_word16_t mid, side; @@ -1014,22 +876,6 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm } n = SHL16(celt_sqrt((eBands[i+1]-eBands[i])),11); - /* If pitch is in use and this eBand begins a pitch band, encode the pitch gain flag */ - if (pitch_used && eBands[i]< m->pitchEnd && eBands[i] == pBands[pband+1]) - { - int enabled = 1; - pband++; - if (remaining_bits >= 1< 8192 ? 1 : 0; c2 = 1-c; - if (eBands[i] >= m->pitchEnd && fold) - { - } else if (pitch_used && eBands[i] < m->pitchEnd) { - stereo_band_mix(m, P, bandE, qb==0, i, 1); - renormalise_vector(P+C*eBands[i], Q15ONE, N, C); - renormalise_vector(P+C*eBands[i]+1, Q15ONE, N, C); - deinterleave(P+C*eBands[i], C*N); - for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_unquant(v, N, q1, spread, P+C*eBands[i]+c*N, dec); + alg_unquant(v, N, q1, spread, dec); } else { v[0] = QCONST16(1.f, 14); v[1] = 0; @@ -1130,29 +963,19 @@ void unquant_bands_stereo(const CELTMode *m, celt_norm_t * restrict X, celt_norm { intra_fold(m, X+C*eBands[i], eBands[i+1]-eBands[i], norm, P+C*eBands[i], eBands[i], B); deinterleave(P+C*eBands[i], C*N); - } else if (pitch_used && eBands[i] < m->pitchEnd) { - stereo_band_mix(m, P, bandE, qb==0, i, 1); - renormalise_vector(P+C*eBands[i], Q15ONE, N, C); - renormalise_vector(P+C*eBands[i]+1, Q15ONE, N, C); - deinterleave(P+C*eBands[i], C*N); - for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_unquant(X+C*eBands[i], N, q1, spread, P+C*eBands[i], dec); + alg_unquant(X+C*eBands[i], N, q1, spread, dec); } else for (j=C*eBands[i];j 0) { int spread = (eBands[i] >= m->pitchEnd && fold) ? B : 0; - alg_unquant(X+C*eBands[i]+N, N, q2, spread, P+C*eBands[i]+N, dec); + alg_unquant(X+C*eBands[i]+N, N, q2, spread, dec); } else for (j=C*eBands[i]+N;j0) signx[j]=1; else { signx[j]=-1; X[j]=-X[j]; - P[j]=-P[j]; } iy[j] = 0; y[j] = 0; - sum = MAC16_16(sum, P[j],P[j]); } while (++j=1, "Allocated too many pulses in the quick pass"); - while (pulsesLeft > 1) + while (pulsesLeft > 0) { int pulsesAtOnce=1; int best_id; @@ -292,7 +271,6 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, int spread, celt_no xy = xy + MULT16_16(s,X[j]); /* We're multiplying y[j] by two so we don't have to do it here */ yy = yy + MULT16_16(s,y[j]); - yp = yp + MULT16_16(s, P[j]); /* Only now that we've made the final choice, update y/iy */ /* Multiplying y[j] by 2 so we don't have to do it everywhere else */ @@ -300,54 +278,8 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, int spread, celt_no iy[j] += is; pulsesLeft -= pulsesAtOnce; } - - if (pulsesLeft > 0) - { - celt_word16_t g; - celt_word16_t best_num = -VERY_LARGE16; - celt_word16_t best_den = 0; - int best_id = 0; - celt_word16_t magnitude = SHL16(1, yshift); - - /* The squared magnitude term gets added anyway, so we might as well - add it outside the loop */ - yy = MAC16_16(yy, magnitude,magnitude); - j=0; - do { - celt_word16_t Rxy, Ryy, Ryp; - celt_word16_t num; - /* Select sign based on X[j] alone */ - s = magnitude; - /* Temporary sums of the new pulse(s) */ - Rxy = ROUND16(MAC16_16(xy, s,X[j]), 14); - /* We're multiplying y[j] by two so we don't have to do it here */ - Ryy = ROUND16(MAC16_16(yy, s,y[j]), 14); - Ryp = ROUND16(MAC16_16(yp, s,P[j]), 14); - - /* Compute the gain such that ||p + g*y|| = 1 - ...but instead, we compute g*Ryy to avoid dividing */ - g = celt_psqrt(MULT16_16(Ryp,Ryp) + MULT16_16(Ryy,QCONST16(1.f,14)-Rpp)) - Ryp; - /* Knowing that gain, what's the error: (x-g*y)^2 - (result is negated and we discard x^2 because it's constant) */ - /* score = 2*g*Rxy - g*g*Ryy;*/ -#ifdef FIXED_POINT - /* No need to multiply Rxy by 2 because we did it earlier */ - num = MULT16_16_Q15(ADD16(SUB16(Rxy,g),Rxy),g); -#else - num = g*(2*Rxy-g); -#endif - if (MULT16_16(best_den, num) > MULT16_16(Ryy, best_num)) - { - best_den = Ryy; - best_num = num; - best_id = j; - } - } while (++j