Removed a few int divisions from the intra prediction code.

This commit is contained in:
Jean-Marc Valin 2008-03-27 14:18:28 +11:00
parent f958477a54
commit e28f25f0d1
2 changed files with 26 additions and 26 deletions

View file

@ -324,9 +324,9 @@ void quant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P, ce
{ {
q -= 1; q -= 1;
if (q<0) if (q<0)
intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]); intra_fold(X+B*eBands[i], eBands[i+1]-eBands[i], norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]);
else else
intra_prediction(X+B*eBands[i], W+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], enc); intra_prediction(X+B*eBands[i], W+B*eBands[i], eBands[i+1]-eBands[i], q, norm, P+B*eBands[i], B, eBands[i], enc);
} }
if (q > 0) if (q > 0)
@ -381,9 +381,9 @@ void unquant_bands(const CELTMode *m, celt_norm_t * restrict X, celt_norm_t *P,
{ {
q -= 1; q -= 1;
if (q<0) if (q<0)
intra_fold(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]); intra_fold(X+B*eBands[i], eBands[i+1]-eBands[i], norm, P+B*eBands[i], B, eBands[i], eBands[m->nbEBands+1]);
else else
intra_unquant(X+B*eBands[i], B*(eBands[i+1]-eBands[i]), q, norm, P+B*eBands[i], B, eBands[i], dec); intra_unquant(X+B*eBands[i], eBands[i+1]-eBands[i], q, norm, P+B*eBands[i], B, eBands[i], dec);
} }
if (q > 0) if (q > 0)

View file

@ -270,7 +270,7 @@ void intra_prediction(celt_norm_t *x, celt_mask_t *W, int N, int K, celt_norm_t
int sign; int sign;
celt_word32_t E; celt_word32_t E;
celt_word16_t pred_gain; celt_word16_t pred_gain;
int max_pos = N0-N/B; int max_pos = N0-N;
if (max_pos > MAX_INTRA) if (max_pos > MAX_INTRA)
max_pos = MAX_INTRA; max_pos = MAX_INTRA;
@ -283,9 +283,9 @@ void intra_prediction(celt_norm_t *x, celt_mask_t *W, int N, int K, celt_norm_t
complain to your compilor vendor */ complain to your compilor vendor */
j=0; j=0;
do { do {
xy = MAC16_16(xy, x[j], Y[i+N-j-1]); xy = MAC16_16(xy, x[j], Y[i+B*N-j-1]);
yy = MAC16_16(yy, Y[i+N-j-1], Y[i+N-j-1]); yy = MAC16_16(yy, Y[i+B*N-j-1], Y[i+B*N-j-1]);
} while (++j<N); /* Promises we loop at least once */ } while (++j<B*N); /* Promises we loop at least once */
/* Using xy^2/yy as the score but without having to do the division */ /* Using xy^2/yy as the score but without having to do the division */
num = MULT16_16(ROUND16(xy,14),ROUND16(xy,14)); num = MULT16_16(ROUND16(xy,14),ROUND16(xy,14));
den = ROUND16(yy,14); den = ROUND16(yy,14);
@ -311,9 +311,9 @@ void intra_prediction(celt_norm_t *x, celt_mask_t *W, int N, int K, celt_norm_t
/*printf ("%d %d ", sign, best);*/ /*printf ("%d %d ", sign, best);*/
ec_enc_bits(enc,sign,1); ec_enc_bits(enc,sign,1);
if (max_pos == MAX_INTRA) if (max_pos == MAX_INTRA)
ec_enc_bits(enc,best/B,LOG_MAX_INTRA); ec_enc_bits(enc,best,LOG_MAX_INTRA);
else else
ec_enc_uint(enc,best/B,max_pos); ec_enc_uint(enc,best,max_pos);
/*printf ("%d %f\n", best, best_score);*/ /*printf ("%d %f\n", best, best_score);*/
@ -322,21 +322,21 @@ void intra_prediction(celt_norm_t *x, celt_mask_t *W, int N, int K, celt_norm_t
else else
pred_gain = pg[K]; pred_gain = pg[K];
E = EPSILON; E = EPSILON;
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
{ {
P[j] = s*Y[best+N-j-1]; P[j] = s*Y[best+B*N-j-1];
E = MAC16_16(E, P[j],P[j]); E = MAC16_16(E, P[j],P[j]);
} }
/*pred_gain = pred_gain/sqrt(E);*/ /*pred_gain = pred_gain/sqrt(E);*/
pred_gain = MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9))); pred_gain = MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9)));
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8); P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8);
if (K>0) if (K>0)
{ {
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
x[j] -= P[j]; x[j] -= P[j];
} else { } else {
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
x[j] = P[j]; x[j] = P[j];
} }
/*printf ("quant ");*/ /*printf ("quant ");*/
@ -352,7 +352,7 @@ void intra_unquant(celt_norm_t *x, int N, int K, celt_norm_t *Y, celt_norm_t * r
int best; int best;
celt_word32_t E; celt_word32_t E;
celt_word16_t pred_gain; celt_word16_t pred_gain;
int max_pos = N0-N/B; int max_pos = N0-N;
if (max_pos > MAX_INTRA) if (max_pos > MAX_INTRA)
max_pos = MAX_INTRA; max_pos = MAX_INTRA;
@ -363,9 +363,9 @@ void intra_unquant(celt_norm_t *x, int N, int K, celt_norm_t *Y, celt_norm_t * r
s = -1; s = -1;
if (max_pos == MAX_INTRA) if (max_pos == MAX_INTRA)
best = B*ec_dec_bits(dec, LOG_MAX_INTRA); best = ec_dec_bits(dec, LOG_MAX_INTRA);
else else
best = B*ec_dec_uint(dec, max_pos); best = ec_dec_uint(dec, max_pos);
/*printf ("%d %d ", sign, best);*/ /*printf ("%d %d ", sign, best);*/
if (K>10) if (K>10)
@ -373,18 +373,18 @@ void intra_unquant(celt_norm_t *x, int N, int K, celt_norm_t *Y, celt_norm_t * r
else else
pred_gain = pg[K]; pred_gain = pg[K];
E = EPSILON; E = EPSILON;
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
{ {
P[j] = s*Y[best+N-j-1]; P[j] = s*Y[best+B*N-j-1];
E = MAC16_16(E, P[j],P[j]); E = MAC16_16(E, P[j],P[j]);
} }
/*pred_gain = pred_gain/sqrt(E);*/ /*pred_gain = pred_gain/sqrt(E);*/
pred_gain = MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9))); pred_gain = MULT16_16_Q15(pred_gain,celt_rcp(SHL32(celt_sqrt(E),9)));
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8); P[j] = PSHR32(MULT16_16(pred_gain, P[j]),8);
if (K==0) if (K==0)
{ {
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
x[j] = P[j]; x[j] = P[j];
} }
} }
@ -400,23 +400,23 @@ void intra_fold(celt_norm_t *x, int N, celt_norm_t *Y, celt_norm_t * restrict P,
{ {
for (i=0;i<B;i++) for (i=0;i<B;i++)
{ {
for (j=0;j<N/B;j++) for (j=0;j<N;j++)
{ {
P[j*B+i] = Y[(Nmax-N0-j-1)*B+i]; P[j*B+i] = Y[(Nmax-N0-j-1)*B+i];
E += P[j*B+i]*P[j*B+i]; E += P[j*B+i]*P[j*B+i];
} }
} }
} else { } else {
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
{ {
P[j] = Y[j]; P[j] = Y[j];
E = MAC16_16(E, P[j],P[j]); E = MAC16_16(E, P[j],P[j]);
} }
} }
g = celt_rcp(SHL32(celt_sqrt(E),9)); g = celt_rcp(SHL32(celt_sqrt(E),9));
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
P[j] = PSHR32(MULT16_16(g, P[j]),8); P[j] = PSHR32(MULT16_16(g, P[j]),8);
for (j=0;j<N;j++) for (j=0;j<B*N;j++)
x[j] = P[j]; x[j] = P[j];
} }