shithub: opus

Download patch

ref: 6d3829f266f0c9aa86e10b5998cbfbb450d2797e
parent: c09807d3e574576e5fb894ccef600734f6c8ee04
author: Jean-Marc Valin <[email protected]>
date: Fri Aug 27 13:52:38 EDT 2010

CELT no longer prints to stderr (unless assertions are enabled)

--- a/libcelt/arch.h
+++ b/libcelt/arch.h
@@ -44,6 +44,13 @@
 
 #define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__);
 #ifdef ENABLE_ASSERTIONS
+#include <stdio.h>
+#include <stdlib.h>
+static inline void _celt_fatal(const char *str, const char *file, int line)
+{
+   fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
+   abort();
+}
 #define celt_assert(cond) {if (!(cond)) {celt_fatal("assertion failed: " #cond);}}
 #define celt_assert2(cond, message) {if (!(cond)) {celt_fatal("assertion failed: " #cond "\n" message);}}
 #else
--- a/libcelt/celt.c
+++ b/libcelt/celt.c
@@ -119,14 +119,11 @@
 {
    if (channels < 0 || channels > 2)
    {
-      celt_warning("Only mono and stereo supported");
       if (error)
          *error = CELT_BAD_ARG;
       return NULL;
    }
 
-   CELT_MEMSET((char*)st, 0, celt_encoder_get_size(mode, channels));
-   
    if (st==NULL)
    {
       if (error)
@@ -133,6 +130,9 @@
          *error = CELT_ALLOC_FAIL;
       return NULL;
    }
+
+   CELT_MEMSET((char*)st, 0, celt_encoder_get_size(mode, channels));
+   
    st->mode = mode;
    st->overlap = mode->overlap;
    st->channels = channels;
@@ -1155,14 +1155,11 @@
 {
    if (channels < 0 || channels > 2)
    {
-      celt_warning("Only mono and stereo supported");
       if (error)
          *error = CELT_BAD_ARG;
       return NULL;
    }
 
-   CELT_MEMSET((char*)st, 0, celt_decoder_get_size(mode, channels));
-
    if (st==NULL)
    {
       if (error)
@@ -1169,6 +1166,8 @@
          *error = CELT_ALLOC_FAIL;
       return NULL;
    }
+
+   CELT_MEMSET((char*)st, 0, celt_decoder_get_size(mode, channels));
 
    st->mode = mode;
    st->overlap = mode->overlap;
--- a/libcelt/entdec.c
+++ b/libcelt/entdec.c
@@ -45,10 +45,7 @@
 }
 
 unsigned char ec_byte_look_at_end(ec_byte_buffer *_b){
-  if (_b->end_ptr < _b->buf)
-  {
-    celt_fatal("Trying to read raw bits before the beginning of the stream");
-  }
+  celt_assert2 (_b->end_ptr >= _b->buf, "Trying to read raw bits before the beginning of the stream");
   return *(_b->end_ptr--);
 }
 
@@ -99,7 +96,6 @@
     t = t<<ftb|ec_dec_bits(_this,ftb);
     if (t>_ft)
     {
-      celt_notify("uint decode error");
       _this->error |= 1;
       t = _ft;
     }
--- a/libcelt/kiss_fft.c
+++ b/libcelt/kiss_fft.c
@@ -460,8 +460,6 @@
 #ifndef RADIX_TWO_ONLY
         case 3: kf_bfly3(Fout,fstride,st,m, N, m2); break;
         case 5: kf_bfly5(Fout,fstride,st,m, N, m2); break;
-#else
-       default: celt_fatal("kiss_fft: only powers of two enabled");
 #endif
     }    
 }
@@ -494,8 +492,6 @@
 #ifndef RADIX_TWO_ONLY
       case 3: ki_bfly3(Fout,fstride,st,m, N, m2); break;
       case 5: ki_bfly5(Fout,fstride,st,m, N, m2); break;
-#else
-      default: celt_fatal("kiss_fft: only powers of two enabled");
 #endif
    }    
 }
@@ -558,9 +554,12 @@
                 p = n;          /* no more factors, skip to end */
         }
         n /= p;
+#ifdef RADIX_TWO_ONLY
+        if (p!=2 && p != 4)
+#else
         if (p>5)
+#endif
         {
-           celt_warning("Only powers of 2, 3 and 5 are supported");
            return 0;
         }
         *facbuf++ = p;
--- a/libcelt/modes.c
+++ b/libcelt/modes.c
@@ -262,7 +262,6 @@
          return (CELTMode*)static_mode_list[i];
       }
    }
-   celt_warning("Mode not included as part of the static modes");
    if (error)
       *error = CELT_BAD_ARG;
    return NULL;
@@ -291,7 +290,6 @@
    
    if (Fs < 8000 || Fs > 96000)
    {
-      celt_warning("Sampling rate must be between 8 kHz and 96 kHz");
       if (error)
          *error = CELT_BAD_ARG;
       return NULL;
@@ -298,7 +296,6 @@
    }
    if (frame_size < 40 || frame_size > 1024 || frame_size%2!=0)
    {
-      celt_warning("Only even frame sizes from 40 to 1024 are supported");
       if (error)
          *error = CELT_BAD_ARG;
       return NULL;
@@ -428,10 +425,7 @@
 {
 #ifndef STATIC_MODES
    if (mode == NULL)
-   {
-      celt_warning("NULL passed to celt_mode_destroy");
       return;
-   }
 
    celt_free((celt_int16*)mode->eBands);
    celt_free((celt_int16*)mode->allocVectors);
--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -63,14 +63,6 @@
 }
 #endif
 
-/** CELT wrapper for realloc(). To do your own dynamic allocation, all you need to do is replace this function, celt_alloc and celt_free */
-#ifndef OVERRIDE_CELT_REALLOC
-static inline void *celt_realloc (void *ptr, int size)
-{
-   return realloc(ptr, size);
-}
-#endif
-
 /** CELT wrapper for free(). To do your own dynamic allocation, all you need to do is replace this function, celt_realloc and celt_alloc */
 #ifndef OVERRIDE_CELT_FREE
 static inline void celt_free (void *ptr)
@@ -102,44 +94,6 @@
 #ifndef OVERRIDE_CELT_MEMSET
 #define CELT_MEMSET(dst, c, n) (memset((dst), (c), (n)*sizeof(*(dst))))
 #endif
-
-
-#ifndef OVERRIDE_CELT_FATAL
-static inline void _celt_fatal(const char *str, const char *file, int line)
-{
-   fprintf (stderr, "Fatal (internal) error in %s, line %d: %s\n", file, line, str);
-   abort();
-}
-#endif
-
-#ifndef OVERRIDE_CELT_WARNING
-static inline void celt_warning(const char *str)
-{
-#ifndef DISABLE_WARNINGS
-   fprintf (stderr, "warning: %s\n", str);
-#endif
-}
-#endif
-
-#ifndef OVERRIDE_CELT_WARNING_INT
-static inline void celt_warning_int(const char *str, int val)
-{
-#ifndef DISABLE_WARNINGS
-   fprintf (stderr, "warning: %s %d\n", str, val);
-#endif
-}
-#endif
-
-#ifndef OVERRIDE_CELT_NOTIFY
-static inline void celt_notify(const char *str)
-{
-#ifndef DISABLE_NOTIFICATIONS
-   fprintf (stderr, "notification: %s\n", str);
-#endif
-}
-#endif
-
-
 
 /*#ifdef __GNUC__
 #pragma GCC poison printf sprintf