shithub: opus

Download patch

ref: e28f25f0d14959d521fda0cdb8f1220995bc50e8
parent: f958477a54541d65059227b1760ead814025d469
author: Jean-Marc Valin <[email protected]>
date: Thu Mar 27 10:18:28 EDT 2008

Removed a few int divisions from the intra prediction code.

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -324,9 +324,9 @@
       {
          q -= 1;
          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
-            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)
@@ -381,9 +381,9 @@
       {
          q -= 1;
          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
-            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)
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -270,7 +270,7 @@
    int sign;
    celt_word32_t E;
    celt_word16_t pred_gain;
-   int max_pos = N0-N/B;
+   int max_pos = N0-N;
    if (max_pos > MAX_INTRA)
       max_pos = MAX_INTRA;
 
@@ -283,9 +283,9 @@
          complain to your compilor vendor */
       j=0;
       do {
-         xy = MAC16_16(xy, x[j], Y[i+N-j-1]);
-         yy = MAC16_16(yy, Y[i+N-j-1], Y[i+N-j-1]);
-      } while (++j<N); /* Promises we loop at least once */
+         xy = MAC16_16(xy, x[j], Y[i+B*N-j-1]);
+         yy = MAC16_16(yy, Y[i+B*N-j-1], Y[i+B*N-j-1]);
+      } while (++j<B*N); /* Promises we loop at least once */
       /* Using xy^2/yy as the score but without having to do the division */
       num = MULT16_16(ROUND16(xy,14),ROUND16(xy,14));
       den = ROUND16(yy,14);
@@ -311,9 +311,9 @@
    /*printf ("%d %d ", sign, best);*/
    ec_enc_bits(enc,sign,1);
    if (max_pos == MAX_INTRA)
-      ec_enc_bits(enc,best/B,LOG_MAX_INTRA);
+      ec_enc_bits(enc,best,LOG_MAX_INTRA);
    else
-      ec_enc_uint(enc,best/B,max_pos);
+      ec_enc_uint(enc,best,max_pos);
 
    /*printf ("%d %f\n", best, best_score);*/
    
@@ -322,21 +322,21 @@
    else
       pred_gain = pg[K];
    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]);
    }
    /*pred_gain = pred_gain/sqrt(E);*/
    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);
    if (K>0)
    {
-      for (j=0;j<N;j++)
+      for (j=0;j<B*N;j++)
          x[j] -= P[j];
    } else {
-      for (j=0;j<N;j++)
+      for (j=0;j<B*N;j++)
          x[j] = P[j];
    }
    /*printf ("quant ");*/
@@ -352,7 +352,7 @@
    int best;
    celt_word32_t E;
    celt_word16_t pred_gain;
-   int max_pos = N0-N/B;
+   int max_pos = N0-N;
    if (max_pos > MAX_INTRA)
       max_pos = MAX_INTRA;
    
@@ -363,9 +363,9 @@
       s = -1;
    
    if (max_pos == MAX_INTRA)
-      best = B*ec_dec_bits(dec, LOG_MAX_INTRA);
+      best = ec_dec_bits(dec, LOG_MAX_INTRA);
    else
-      best = B*ec_dec_uint(dec, max_pos);
+      best = ec_dec_uint(dec, max_pos);
    /*printf ("%d %d ", sign, best);*/
 
    if (K>10)
@@ -373,18 +373,18 @@
    else
       pred_gain = pg[K];
    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]);
    }
    /*pred_gain = pred_gain/sqrt(E);*/
    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);
    if (K==0)
    {
-      for (j=0;j<N;j++)
+      for (j=0;j<B*N;j++)
          x[j] = P[j];
    }
 }
@@ -400,7 +400,7 @@
    {
       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];
             E += P[j*B+i]*P[j*B+i];
@@ -407,7 +407,7 @@
          }
       }
    } else {
-      for (j=0;j<N;j++)
+      for (j=0;j<B*N;j++)
       {
          P[j] = Y[j];
          E = MAC16_16(E, P[j],P[j]);
@@ -414,9 +414,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);
-   for (j=0;j<N;j++)
+   for (j=0;j<B*N;j++)
       x[j] = P[j];
 }