Changed compute_allocation_table() so it handles ebands that start and end in the...
authorJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 14 Apr 2010 21:42:22 +0000 (17:42 -0400)
committerJean-Marc Valin <jean-marc.valin@octasic.com>
Wed, 14 Apr 2010 21:42:22 +0000 (17:42 -0400)
libcelt/modes.c
libcelt/vq.c

index 89d2f29..513edab 100644 (file)
@@ -200,25 +200,37 @@ static void compute_allocation_table(CELTMode *mode, int res)
       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;
 }
index a59411c..0b8fe3c 100644 (file)
@@ -360,6 +360,7 @@ celt_word16 renormalise_vector(celt_norm *X, celt_word16 value, int N, int strid
    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 @@ celt_word16 renormalise_vector(celt_norm *X, celt_word16 value, int N, int strid
 #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;