shithub: opus

Download patch

ref: a66b7574f6257e38155b96bcd43b8f2b18d95c43
parent: 9d2d0510a1ae9afd1f2d13df850faf763dcc28be
author: Jean-Marc Valin <[email protected]>
date: Mon Jan 10 08:21:04 EST 2011

Defines MAX_FINE_BITS to ensure that we're using the same value everywhere

--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -965,32 +965,7 @@
    ALLOC(lowband_scratch, M*(eBands[m->nbEBands]-eBands[m->nbEBands-1]), celt_norm);
    norm = _norm;
    norm2 = norm + M*eBands[m->nbEBands];
-#if 0
-   if (C==2)
-   {
-      int j;
-      int left = 0;
-      for (j=intensity;j<codedBands;j++)
-      {
-         int tmp = pulses[j]/2;
-         left += tmp;
-         pulses[j] -= tmp;
-      }
-      if (codedBands) {
-         int perband;
-         perband = left/(m->eBands[codedBands]-m->eBands[start]);
-         for (j=start;j<codedBands;j++)
-            pulses[j] += perband*(m->eBands[j+1]-m->eBands[j]);
-         left = left-(m->eBands[codedBands]-m->eBands[start])*perband;
-         for (j=start;j<codedBands;j++)
-         {
-            int tmp = IMIN(left, m->eBands[j+1]-m->eBands[j]);
-            pulses[j] += tmp;
-            left -= tmp;
-         }
-      }
-   }
-#endif
+
    if (encode)
       seed = ((ec_enc*)ec)->rng;
    else
--- a/libcelt/quant_bands.c
+++ b/libcelt/quant_bands.c
@@ -41,6 +41,7 @@
 #include "arch.h"
 #include "mathops.h"
 #include "stack_alloc.h"
+#include "rate.h"
 
 #ifdef FIXED_POINT
 /* Mean energy in each band quantized in Q6 */
@@ -384,7 +385,7 @@
    {
       for (i=start;i<end && bits_left>=C ;i++)
       {
-         if (fine_quant[i] >= 7 || fine_priority[i]!=prio)
+         if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i]!=prio)
             continue;
          c=0;
          do {
@@ -495,7 +496,7 @@
    {
       for (i=start;i<end && bits_left>=C ;i++)
       {
-         if (fine_quant[i] >= 8 || fine_priority[i]!=prio)
+         if (fine_quant[i] >= MAX_FINE_BITS || fine_priority[i]!=prio)
             continue;
          c=0;
          do {
--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -366,9 +366,8 @@
          if (C*ebits[j] > (bits[j]>>BITRES))
             ebits[j] = bits[j] >> stereo >> BITRES;
 
-         /* More than 8 is useless because that's about as far as PVQ can go */
-         if (ebits[j]>8)
-            ebits[j]=8;
+         /* More than that is useless because that's about as far as PVQ can go */
+         ebits[j] = IMIN(ebits[j], MAX_FINE_BITS);
 
          /* If we rounded down or capped this band, make it a candidate for the
              final fine energy pass */
@@ -376,7 +375,7 @@
 
       } else {
          /* For N=1, all bits go to fine energy except for a single sign bit */
-         ebits[j] = IMIN(IMAX(0,(bits[j] >> stereo >> BITRES)-1),8);
+         ebits[j] = IMIN(IMAX(0,(bits[j] >> stereo >> BITRES)-1),MAX_FINE_BITS);
          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.
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -38,6 +38,8 @@
 
 #define MAX_PULSES 128
 
+#define MAX_FINE_BITS 8
+
 #define BITRES 3
 #define FINE_OFFSET 21
 #define QTHETA_OFFSET 4