shithub: opus

Download patch

ref: 2b747c9817fe12f2123abad4861448dfddf033a0
parent: 52dc66b88777f5617e6ecf5838e81c48348aaa84
author: Jean-Marc Valin <[email protected]>
date: Wed Dec 8 06:06:09 EST 2010

Simplifying the allocation code and making sure both channels get a bit

--- a/libcelt/rate.c
+++ b/libcelt/rate.c
@@ -140,7 +140,9 @@
 
 #define ALLOC_STEPS 6
 
-static inline int interp_bits2pulses(const CELTMode *m, int start, int end, int *bits1, int *bits2, int total, int *bits, int *ebits, int *fine_priority, int len, int _C, int LM)
+static inline int interp_bits2pulses(const CELTMode *m, int start, int end,
+      int *bits1, int *bits2, const int *thresh, int total, int *bits,
+      int *ebits, int *fine_priority, int len, int _C, int LM)
 {
    int psum;
    int lo, hi;
@@ -148,14 +150,8 @@
    int logM;
    const int C = CHANNELS(_C);
    int codedBands=-1;
-   VARDECL(int, thresh);
    SAVE_STACK;
 
-   ALLOC(thresh, len, int);
-
-   /* Below this threshold, we don't allocate any PVQ bits */
-   for (j=start;j<end;j++)
-      thresh[j] = 2*(C*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>3;
    logM = LM<<BITRES;
    lo = 0;
    hi = 1<<ALLOC_STEPS;
@@ -167,12 +163,10 @@
       {
          int tmp = bits1[j] + (mid*bits2[j]>>ALLOC_STEPS);
          /* Don't allocate more than we can actually use */
-         if (tmp > 64*C<<BITRES<<LM)
-            tmp = 64*C<<BITRES<<LM;
          if (tmp >= thresh[j])
             psum += tmp;
-         else if (tmp >= 1<<BITRES)
-            psum += 1<<BITRES;
+         else if (tmp >= C<<BITRES)
+            psum += C<<BITRES;
       }
       if (psum > (total<<BITRES))
          hi = mid;
@@ -188,8 +182,8 @@
       {
          bits[j] = tmp;
          codedBands = j;
-      } else if (tmp >= 1<<BITRES)
-         bits[j] = 1<<BITRES;
+      } else if (tmp >= C<<BITRES)
+         bits[j] = C<<BITRES;
       else
          bits[j] = 0;
       /* Don't allocate more than we can actually use */
@@ -292,7 +286,7 @@
 
    /* Below this threshold, we don't allocate any PVQ bits */
    for (j=start;j<end;j++)
-      thresh[j] = 2*(C*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>3;
+      thresh[j] = (4*(m->eBands[j+1]-m->eBands[j])<<LM<<BITRES)>>3;
    /* Tilt of the allocation curve */
    for (j=start;j<end;j++)
       trim_offset[j] = C*(m->eBands[j+1]-m->eBands[j])*(alloc_trim-5-LM)*(m->nbEBands-j-1)
@@ -339,7 +333,8 @@
          bits1[j] = 0;
       bits1[j] += offsets[j];
    }
-   codedBands = interp_bits2pulses(m, start, end, bits1, bits2, total, pulses, ebits, fine_priority, len, C, LM);
+   codedBands = interp_bits2pulses(m, start, end, bits1, bits2, thresh,
+         total, pulses, ebits, fine_priority, len, C, LM);
    RESTORE_STACK;
    return codedBands;
 }