From 6d3829f266f0c9aa86e10b5998cbfbb450d2797e Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin Date: Fri, 27 Aug 2010 17:52:38 -0400 Subject: [PATCH] CELT no longer prints to stderr (unless assertions are enabled) --- libcelt/arch.h | 7 +++++++ libcelt/celt.c | 11 +++++------ libcelt/entdec.c | 6 +----- libcelt/kiss_fft.c | 9 ++++----- libcelt/modes.c | 6 ------ libcelt/os_support.h | 46 -------------------------------------------- 6 files changed, 17 insertions(+), 68 deletions(-) diff --git a/libcelt/arch.h b/libcelt/arch.h index 48c53d42..e4f27392 100644 --- 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 +#include +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 diff --git a/libcelt/celt.c b/libcelt/celt.c index c43df841..4727adfd 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -119,20 +119,20 @@ CELTEncoder *celt_encoder_init(CELTEncoder *st, const CELTMode *mode, int channe { 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) *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 @@ CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channe { 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) @@ -1170,6 +1167,8 @@ CELTDecoder *celt_decoder_init(CELTDecoder *st, const CELTMode *mode, int channe return NULL; } + CELT_MEMSET((char*)st, 0, celt_decoder_get_size(mode, channels)); + st->mode = mode; st->overlap = mode->overlap; st->channels = channels; diff --git a/libcelt/entdec.c b/libcelt/entdec.c index d56fc5be..aca0aca2 100644 --- a/libcelt/entdec.c +++ b/libcelt/entdec.c @@ -45,10 +45,7 @@ void ec_byte_readinit(ec_byte_buffer *_b,unsigned char *_buf,ec_uint32 _bytes){ } 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 @@ ec_uint32 ec_dec_uint(ec_dec *_this,ec_uint32 _ft){ t = t<_ft) { - celt_notify("uint decode error"); _this->error |= 1; t = _ft; } diff --git a/libcelt/kiss_fft.c b/libcelt/kiss_fft.c index b0518f55..138bb4f0 100644 --- a/libcelt/kiss_fft.c +++ b/libcelt/kiss_fft.c @@ -460,8 +460,6 @@ static void kf_work( #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 @@ static void ki_work( #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 @@ int kf_factor(int n,celt_int16 * facbuf) 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; diff --git a/libcelt/modes.c b/libcelt/modes.c index 9a02306b..5f665c29 100644 --- a/libcelt/modes.c +++ b/libcelt/modes.c @@ -262,7 +262,6 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) 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,14 +290,12 @@ CELTMode *celt_mode_create(celt_int32 Fs, int frame_size, int *error) 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; } 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 @@ void celt_mode_destroy(CELTMode *mode) { #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); diff --git a/libcelt/os_support.h b/libcelt/os_support.h index 8a47df9a..80928aa1 100644 --- a/libcelt/os_support.h +++ b/libcelt/os_support.h @@ -63,14 +63,6 @@ static inline void *celt_alloc_scratch (int size) } #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) @@ -103,44 +95,6 @@ static inline void celt_free_scratch (void *ptr) #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 #pragma GCC poison malloc free realloc calloc