Split the last pulse out of the alg_quant() main loop.

This commit is contained in:
Jean-Marc Valin 2008-09-21 21:11:39 -04:00
parent 5ea2e7f267
commit 7bb339d9f9

View file

@ -135,11 +135,13 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *
xy = yy = yp = 0;
pulsesLeft = K;
while (pulsesLeft > 0)
while (pulsesLeft > 1)
{
int pulsesAtOnce=1;
int best_id;
celt_word16_t magnitude;
celt_word32_t best_num = -VERY_LARGE16;
celt_word16_t best_den = 0;
#ifdef FIXED_POINT
int rshift;
#endif
@ -157,11 +159,7 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *
add it outside the loop */
yy = MAC16_16(yy, magnitude,magnitude);
/* Choose between fast and accurate strategy depending on where we are in the search */
if (pulsesLeft>1)
{
/* This should ensure that anything we can process will have a better score */
celt_word32_t best_num = -VERY_LARGE16;
celt_word16_t best_den = 0;
j=0;
do {
celt_word16_t Rxy, Ryy;
@ -185,16 +183,39 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *
best_id = j;
}
} while (++j<N);
} else {
j = best_id;
is = MULT16_16(signx[j],pulsesAtOnce);
s = SHL16(is, yshift);
/* Updating the sums of the new pulse(s) */
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 */
y[j] += 2*s;
iy[j] += is;
pulsesLeft -= pulsesAtOnce;
}
{
celt_word16_t g;
celt_word16_t best_num = -VERY_LARGE16;
celt_word16_t best_den = 0;
int best_id = 0;
/* The squared magnitude term gets added anyway, so we might as well
add it outside the loop */
yy = MAC16_16(yy, 1,1);
j=0;
do {
celt_word16_t Rxy, Ryy, Ryp;
celt_word16_t num;
/* Select sign based on X[j] alone */
s = MULT16_16(signx[j],magnitude);
s = signx[j];
/* 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 */
@ -220,25 +241,8 @@ void alg_quant(celt_norm_t *X, celt_mask_t *W, int N, int K, const celt_norm_t *
best_id = j;
}
} while (++j<N);
iy[best_id] += signx[best_id];
}
j = best_id;
is = MULT16_16(signx[j],pulsesAtOnce);
s = SHL16(is, yshift);
/* Updating the sums of the new pulse(s) */
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 */
y[j] += 2*s;
iy[j] += is;
pulsesLeft -= pulsesAtOnce;
}
encode_pulses(iy, N, K, enc);
/* Recompute the gain in one pass to reduce the encoder-decoder mismatch