shithub: opus

Download patch

ref: 5aaf12333eabafde133b5e255c86d8455960f95a
parent: 8eadcdc61136793373e69bde1bddd0d28633f0a3
author: Jean-Marc Valin <[email protected]>
date: Tue May 26 17:50:38 EDT 2009

Enabling more than 128 pulses for N=3 and N=4.

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -49,6 +49,8 @@
 #endif
 
 #define IMUL32(a,b) ((a)*(b))
+#define UMUL32(a,b) ((celt_int32_t)(a)*(celt_int32_t)(b))
+#define UMUL16_16(a,b) ((celt_int32_t)(a)*(celt_int32_t)(b))
 
 #define ABS(x) ((x) < 0 ? (-(x)) : (x))      /**< Absolute integer value. */
 #define ABS16(x) ((x) < 0 ? (-(x)) : (x))    /**< Absolute 16-bit value.  */
--- a/libcelt/rate.h
+++ b/libcelt/rate.h
@@ -49,7 +49,7 @@
    hi = MAX_PULSES-1;
    
    /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */
-   if (0 && bits > cache[MAX_PULSES-1] && N==3)
+   if (bits > cache[MAX_PULSES-1] && N<=4)
    {
       /*int pulses;
       pulses = 127;
@@ -56,14 +56,30 @@
       while (16 + log2_frac(2*(pulses+1)*(pulses+1) + 1, 4) <= bits && pulses < 32767)
          pulses++;*/
       lo = 127;
-      hi = 32767;
-      for (i=0;i<15;i++)
+      switch (N)
       {
-         int pulses = (lo+hi)>>1;
-         if (16 + log2_frac(2*pulses*pulses + 1, 4) > bits)
-            hi = pulses;
-         else
-            lo = pulses;
+         case 3:
+            hi = 32767;
+            for (i=0;i<15;i++)
+            {
+               int pulses = (lo+hi)>>1;
+               if (log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4) > bits)
+                  hi = pulses;
+               else
+                  lo = pulses;
+            }
+            break;
+         case 4:
+            hi = 1172;
+            for (i=0;i<15;i++)
+            {
+               int pulses = (lo+hi)>>1;
+               if (log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4) > bits)
+                  hi = pulses;
+               else
+                  lo = pulses;
+            }
+            break;
       }
       return lo;
    }
@@ -89,11 +105,18 @@
 static inline int pulses2bits(const celt_int16_t *cache, int N, int pulses)
 {
    /* Use of more than MAX_PULSES is disabled until we are able to cwrs that decently */
-   if (0 && pulses > 127)
+   if (pulses > 127)
    {
       int bits;
-      celt_assert (N==3);
-      bits = 16 + log2_frac(2*pulses*pulses + 1, 4);
+      switch (N)
+      {
+         case 3:
+            bits = log2_frac(((UMUL16_16(pulses,pulses)>>1)+1)>>1, 4);
+            break;
+         case 4:
+            bits = log2_frac((UMUL32(UMUL16_16(pulses,pulses)+2,pulses))/3<<3, 4);
+            break;
+      }
       /*printf ("%d <- %d\n", bits, pulses);*/
       return bits;
    }