shithub: opus

Download patch

ref: 4ff068e670a9e857aa3f3879190279ca2d9d38f1
parent: bfcbd184b5413f0cbddc286b2b4e57f8bd1ac90c
author: Jean-Marc Valin <[email protected]>
date: Sat Mar 15 19:34:39 EDT 2008

Some work on assertions.

--- a/TODO
+++ b/TODO
@@ -6,8 +6,9 @@
 - Dynamic (intra-frame) bit allocation 
 - Joint encoding of stereo energy
 - Disable intra-frame prediction for more than X pulses
+- Remove contraction?
+- Simplify search?
+- Remove pulse spreading?
 
 - Encode band shape (or just tilt)?
-- Make pitch less aggressive instead of using contraction?
 - Make energy encoding more robust to losses?
-- Revisit pulse spreading
--- a/configure.ac
+++ b/configure.ac
@@ -108,6 +108,11 @@
   AC_DEFINE([STATIC_MODES], , [Static modes])
 fi])
 
+AC_ARG_ENABLE(assertions, [  --enable-assertions],
+[if test "$enableval" = yes; then
+  AC_DEFINE([ENABLE_ASSERTIONS], , [Assertions])
+fi])
+
 if test $ac_cv_c_compiler_gnu = yes ; then
         CFLAGS="$CFLAGS -fvisibility=hidden -W -Wstrict-prototypes -Wall -Wextra -Wcast-align -Wnested-externs -Wshadow -Wno-parentheses -Wno-unused-parameter -Wno-sign-compare"
         #CFLAGS="$CFLAGS -fvisibility=hidden -W -Wstrict-prototypes -Wmissing-prototypes -Wall -Waggregate-return -Wcast-align -Wcast-qual -Wnested-externs -Wshadow -Wno-parentheses"
--- a/libcelt/bands.c
+++ b/libcelt/bands.c
@@ -93,7 +93,7 @@
             maxval = MAX32(maxval, ABS32(X[j*C+c]));
          if (maxval > 0)
          {
-            int shift = celt_ilog2(maxval)-10;
+            int shift = celt_zlog2(maxval)-10;
             for (j=B*eBands[i];j<B*eBands[i+1];j++)
                sum += VSHR32(X[j*C+c],shift)*VSHR32(X[j*C+c],shift);
             /* We're adding one here to make damn sure we never end up with a pitch vector that's
@@ -122,7 +122,7 @@
          celt_word16_t g;
          int j,shift;
          celt_word16_t E;
-         shift = celt_ilog2(bank[i*C+c])-13;
+         shift = celt_zlog2(bank[i*C+c])-13;
          E = VSHR32(bank[i*C+c], shift);
          if (E>0)
             g = DIV32_16(QCONST32(1.f,28),MULT16_16_Q14(E,sqrtC_1[C-1]));
@@ -420,7 +420,7 @@
       celt_word16_t a1, a2;
       celt_word16_t norm;
 #ifdef FIXED_POINT
-      int shift = celt_ilog2(MAX32(bank[i*C], bank[i*C+1]))-13;
+      int shift = celt_zlog2(MAX32(bank[i*C], bank[i*C+1]))-13;
 #endif
       left = VSHR32(bank[i*C],shift);
       right = VSHR32(bank[i*C+1],shift);
--- a/libcelt/mathops.h
+++ b/libcelt/mathops.h
@@ -53,9 +53,17 @@
 #ifdef FIXED_POINT
 
 #include "entcode.h"
+#include "os_support.h"
 
 /** Integer log in base2. Undefined for zero and negative numbers */
 static inline celt_int16_t celt_ilog2(celt_word32_t x)
+{
+   celt_assert2(x>0, "celt_ilog2() only defined for strictly positive numbers");
+   return EC_ILOG(x)-1;
+}
+
+/** Integer log in base2. Defined for zero, but not for negative numbers */
+static inline celt_int16_t celt_zlog2(celt_word32_t x)
 {
    return EC_ILOG(x)-1;
 }
--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -157,18 +157,14 @@
 #endif
 
 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
+#ifdef ENABLE_ASSERTIONS
 #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
-
-#ifndef RELEASE
-static inline void print_vec(float *vec, int len, char *name)
-{
-   int i;
-   printf ("%s ", name);
-   for (i=0;i<len;i++)
-      printf (" %f", vec[i]);
-   printf ("\n");
-}
+#define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
+#else
+#define celt_assert(cond)
+#define celt_assert2(cond, message)
 #endif
 
-#endif
+
+#endif /* OS_SUPPORT_H */
 
--- a/libcelt/vq.c
+++ b/libcelt/vq.c
@@ -167,8 +167,7 @@
    }
    Rpp = ROUND(Rpp, NORM_SHIFT);
    Rxp = ROUND(Rxp, NORM_SHIFT);
-   if (Rpp>NORM_SCALING)
-      celt_fatal("Rpp > 1");
+   celt_assert2(Rpp<=NORM_SCALING, "Rpp should never have a norm greater than unity");
 
    /* We only need to initialise the zero because the first iteration only uses that */
    for (i=0;i<N;i++)
@@ -266,8 +265,7 @@
 
       }
       
-      if (!(nbest[0]->score > -VERY_LARGE32))
-         celt_fatal("Could not find any match in VQ codebook. Something got corrupted somewhere.");
+      celt_assert2(nbest[0]->score > -VERY_LARGE32, "Could not find any match in VQ codebook. Something got corrupted somewhere.");
       /* Only now that we've made the final choice, update ny/iny and others */
       for (k=0;k<Lupdate;k++)
       {