shithub: opus

Download patch

ref: 137f3366bc0ea0a9c24420ce779435866f00f44e
parent: 31bec963bb078b4f47e48c9092b7e86a0fb28aea
author: Jean-Marc Valin <[email protected]>
date: Wed Apr 14 13:42:22 EDT 2010

Changed compute_allocation_table() so it handles ebands that start and end in the same allocation band. Also fixed a minor C89 issue.

--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -200,25 +200,37 @@
       int eband = 0;
       for (j=0;j<nBark;j++)
       {
-         int edge, low;
+         int edge, low, high;
          celt_int32 alloc;
-         edge = mode->eBands[eband+1]*res;
+
          alloc = mode->mdctSize*band_allocation[i*BARK_BANDS+j];
-         if (edge < bark_freq[j+1])
+         low = bark_freq[j];
+         high = bark_freq[j+1];
+
+         edge = mode->eBands[eband+1]*res;
+         while (edge <= high)
          {
-            int num, den;
-            num = alloc * (edge-bark_freq[j]);
-            den = bark_freq[j+1]-bark_freq[j];
-            low = (num+den/2)/den;
-            allocVectors[i*mode->nbEBands+eband] = (current+low+128)/256;
-            current=0;
+            celt_int32 num;
+            int den, bits;
+            num = alloc * (edge-low);
+            den = high-low;
+            /* Divide with rounding */
+            bits = (2*num+den)/(2*den);
+            allocVectors[i*mode->nbEBands+eband] = (current+bits+128)>>8;
+
+            /* Remove the part of the band we just allocated */
+            low = edge;
+            alloc -= bits;
+
+            /* Move to next eband */
+            current = 0;
             eband++;
-            current += alloc-low;
-         } else {
-            current += alloc;
-         }   
+            edge = mode->eBands[eband+1]*res;
+         }
+         current += alloc;
       }
-      allocVectors[i*mode->nbEBands+eband] = (current+128)/256;
+      if (eband < mode->nbEBands)
+         allocVectors[i*mode->nbEBands+eband] = (current+128)>>8;
    }
    mode->allocVectors = allocVectors;
 }
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -360,6 +360,7 @@
    int i;
    celt_word32 E = EPSILON;
    celt_word16 g;
+   celt_word32 t;
    celt_norm *xptr = X;
    for (i=0;i<N;i++)
    {
@@ -369,7 +370,7 @@
 #ifdef FIXED_POINT
    int k = celt_ilog2(E)>>1;
 #endif
-   celt_word32 t = VSHR32(E, (k-7)<<1);
+   t = VSHR32(E, (k-7)<<1);
    g = MULT16_16_Q15(value, celt_rsqrt_norm(t));
 
    xptr = X;