shithub: opus

Download patch

ref: 9b98aaa741635ccbb0b9ed6acff45a88f84e96e8
parent: 7c673cfcdc18422fdf65eff4c70cde3b7c9df876
author: Gregory Maxwell <[email protected]>
date: Sat Dec 18 21:50:12 EST 2010

Eliminate some divisions from rate.c.

--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -149,6 +149,7 @@
    int i, j;
    int logM;
    const int C = CHANNELS(_C);
+   int stereo;
    int codedBands=-1;
    int alloc_floor;
    int left, percoeff;
@@ -157,6 +158,7 @@
    SAVE_STACK;
 
    alloc_floor = C<<BITRES;
+   stereo = C>1;
 
    logM = LM<<BITRES;
    lo = 0;
@@ -324,7 +326,7 @@
 
          /* Make sure not to bust */
          if (C*ebits[j] > (bits[j]>>BITRES))
-            ebits[j] = bits[j]/C >> BITRES;
+            ebits[j] = bits[j] >> stereo >> BITRES;
 
          /* More than 7 is useless because that's about as far as PVQ can go */
          if (ebits[j]>7)
@@ -332,7 +334,7 @@
 
       } else {
          /* For N=1, all bits go to fine energy except for a single sign bit */
-         ebits[j] = IMIN(IMAX(0,(bits[j]/C >> BITRES)-1),7);
+         ebits[j] = IMIN(IMAX(0,(bits[j] >> stereo >> BITRES)-1),7);
          fine_priority[j] = (ebits[j]+1)*C<<BITRES >= (bits[j]-balance);
          /* N=1 bands can't take advantage of the re-balancing in
              quant_all_bands() because they don't have shape, only fine energy.
@@ -353,7 +355,7 @@
    /* The skipped bands use all their bits for fine energy. */
    for (;j<end;j++)
    {
-      ebits[j] = bits[j]/C >> BITRES;
+      ebits[j] = bits[j] >> stereo >> BITRES;
       celt_assert(C*ebits[j]<<BITRES == bits[j]);
       bits[j] = 0;
       fine_priority[j] = ebits[j]<1;