From c7e0b76c06101766201f7b6ee1859306f5480914 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <jean-marc.valin@usherbrooke.ca> Date: Sun, 16 Mar 2008 07:55:29 +1100 Subject: [PATCH] Making sure not to use the C library calls directly --- libcelt/_kiss_fft_guts.h | 3 --- libcelt/arch.h | 14 ++++++++++++-- libcelt/bands.c | 1 + libcelt/celt.c | 1 + libcelt/cwrs.h | 1 + libcelt/entenc.c | 2 +- libcelt/mdct.c | 1 + libcelt/os_support.h | 22 +++++----------------- libcelt/pitch.c | 1 + libcelt/quant_bands.c | 1 + libcelt/quant_pitch.c | 8 +++----- libcelt/testcelt.c | 12 ++++-------- 12 files changed, 31 insertions(+), 36 deletions(-) diff --git a/libcelt/_kiss_fft_guts.h b/libcelt/_kiss_fft_guts.h index 73ac7d678..df4d8c74c 100644 --- a/libcelt/_kiss_fft_guts.h +++ b/libcelt/_kiss_fft_guts.h @@ -224,8 +224,5 @@ struct kiss_fft_state{ (x)->i = TRIG_UPSCALE*celt_cos_norm((phase)-32768);\ }while(0) -/* a debugging function */ -#define pcpx(c)\ - fprintf(stderr,"%g + %gi\n",(double)((c)->r),(double)((c)->i) ) #endif /* KISS_FFT_GUTS_H */ diff --git a/libcelt/arch.h b/libcelt/arch.h index 83e48ab82..3a03b0ae7 100644 --- a/libcelt/arch.h +++ b/libcelt/arch.h @@ -1,7 +1,7 @@ /* Copyright (C) 2003-2008 Jean-Marc Valin */ /** @file arch.h - @brief Various architecture definitions Speex + @brief Various architecture definitions for CELT */ /* Redistribution and use in source and binary forms, with or without @@ -36,7 +36,17 @@ #define ARCH_H #include "celt_types.h" -#include "stack_alloc.h" + + +#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); +#ifdef ENABLE_ASSERTIONS +#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 +#define celt_assert(cond) +#define celt_assert2(cond, message) +#endif + #define ABS(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute integer value. */ #define ABS16(x) ((x) < 0 ? (-(x)) : (x)) /**< Absolute 16-bit value. */ diff --git a/libcelt/bands.c b/libcelt/bands.c index ed3f86c45..165ab2a9d 100644 --- a/libcelt/bands.c +++ b/libcelt/bands.c @@ -38,6 +38,7 @@ #include "modes.h" #include "vq.h" #include "cwrs.h" +#include "stack_alloc.h" #include "os_support.h" #include "mathops.h" diff --git a/libcelt/celt.c b/libcelt/celt.c index e50017966..33f63b341 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -48,6 +48,7 @@ #include "quant_bands.h" #include "psy.h" #include "rate.h" +#include "stack_alloc.h" static const celt_word16_t preemph = QCONST16(0.8f,15); diff --git a/libcelt/cwrs.h b/libcelt/cwrs.h index 7d07c6b1b..f3f8bdd4e 100644 --- a/libcelt/cwrs.h +++ b/libcelt/cwrs.h @@ -33,6 +33,7 @@ #define CWRS_H #include "arch.h" +#include "stack_alloc.h" #include "entenc.h" #include "entdec.h" diff --git a/libcelt/entenc.c b/libcelt/entenc.c index 22b17e70d..6cbdc3a89 100644 --- a/libcelt/entenc.c +++ b/libcelt/entenc.c @@ -59,7 +59,7 @@ void ec_byte_writecopy(ec_byte_buffer *_b,void *_source,long _bytes){ } void ec_byte_writeclear(ec_byte_buffer *_b){ - free(_b->buf); + celt_free(_b->buf); } diff --git a/libcelt/mdct.c b/libcelt/mdct.c index 59d40e9af..85355d135 100644 --- a/libcelt/mdct.c +++ b/libcelt/mdct.c @@ -52,6 +52,7 @@ #include "os_support.h" #include "_kiss_fft_guts.h" #include "mathops.h" +#include "stack_alloc.h" #ifndef M_PI #define M_PI 3.141592653 diff --git a/libcelt/os_support.h b/libcelt/os_support.h index 18381fc9a..b0916c0c0 100644 --- a/libcelt/os_support.h +++ b/libcelt/os_support.h @@ -116,7 +116,7 @@ static inline void celt_free_scratch (void *ptr) 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); - exit(1); + abort(); } #endif @@ -147,24 +147,12 @@ static inline void celt_notify(const char *str) } #endif -#ifndef OVERRIDE_CELT_PUTC -/** Speex wrapper for putc */ -static inline void _celt_putc(int ch, void *file) -{ - FILE *f = (FILE *)file; - fprintf(f, "%c", ch); -} -#endif -#define celt_fatal(str) _celt_fatal(str, __FILE__, __LINE__); -#ifdef ENABLE_ASSERTIONS -#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 -#define celt_assert(cond) -#define celt_assert2(cond, message) -#endif +#ifdef __GNUC__ +#pragma GCC poison printf sprintf +#pragma GCC poison malloc free realloc calloc +#endif #endif /* OS_SUPPORT_H */ diff --git a/libcelt/pitch.c b/libcelt/pitch.c index d81e2ecce..8b7ccce58 100644 --- a/libcelt/pitch.c +++ b/libcelt/pitch.c @@ -47,6 +47,7 @@ #include "psy.h" #include "os_support.h" #include "mathops.h" +#include "stack_alloc.h" kiss_fftr_cfg pitch_state_alloc(int max_lag) { diff --git a/libcelt/quant_bands.c b/libcelt/quant_bands.c index 26423a438..cc757d19f 100644 --- a/libcelt/quant_bands.c +++ b/libcelt/quant_bands.c @@ -39,6 +39,7 @@ #include "os_support.h" #include "arch.h" #include "mathops.h" +#include "stack_alloc.h" #ifdef FIXED_POINT const celt_word16_t eMeans[24] = {11520, -2048, -3072, -640, 256, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; diff --git a/libcelt/quant_pitch.c b/libcelt/quant_pitch.c index 8c7708563..4f3d822a9 100644 --- a/libcelt/quant_pitch.c +++ b/libcelt/quant_pitch.c @@ -39,8 +39,6 @@ #include "arch.h" #include "mathops.h" -//#define PGAIN(codebook, i) ((celt_pgain_t)(Q15ONE*(codebook)[i])) - #ifdef FIXED_POINT #define PGAIN(codebook, i) ((i)&1 ? (celt_word16_t)(((codebook)[(i)>>1]&0x00ffU)<<7) : (celt_word16_t)(((codebook)[(i)>>1]&0xff00U)>>1) ) #else @@ -55,7 +53,7 @@ int vq_index(celt_pgain_t *in, const celt_uint16_t *codebook, int len, int entries) { int i,j; - int index = 0; + int ind = 0; celt_word32_t min_dist=0; int best_index=0; for (i=0;i<entries;i++) @@ -63,8 +61,8 @@ int vq_index(celt_pgain_t *in, const celt_uint16_t *codebook, int len, int entri celt_word32_t dist=0; for (j=0;j<len;j++) { - celt_pgain_t tmp = SHR16(SUB16(in[j],PGAIN(codebook, index)),1); - index++; + celt_pgain_t tmp = SHR16(SUB16(in[j],PGAIN(codebook, ind)),1); + ind++; dist = MAC16_16(dist, tmp, tmp); } if (i==0 || dist<min_dist) diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index 7ab80a591..8756f7c83 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -39,7 +39,6 @@ #include <stdlib.h> #include <math.h> #include <string.h> -#include "os_support.h" int main(int argc, char *argv[]) { @@ -106,11 +105,10 @@ int main(int argc, char *argv[]) celt_mode_info(mode, CELT_GET_FRAME_SIZE, &frame_size); celt_mode_info(mode, CELT_GET_NB_CHANNELS, &channels); - in = (celt_int16_t*)celt_alloc(frame_size*channels*sizeof(celt_int16_t)); - out = (celt_int16_t*)celt_alloc(frame_size*channels*sizeof(celt_int16_t)); + in = (celt_int16_t*)malloc(frame_size*channels*sizeof(celt_int16_t)); + out = (celt_int16_t*)malloc(frame_size*channels*sizeof(celt_int16_t)); while (!feof(fin)) { - SAVE_STACK; fread(in, sizeof(short), frame_size*channels, fin); if (feof(fin)) break; @@ -118,7 +116,6 @@ int main(int argc, char *argv[]) if (len <= 0) { fprintf (stderr, "celt_encode() returned %d\n", len); - RESTORE_STACK; return 1; } /* This is to simulate packet loss */ @@ -141,7 +138,6 @@ int main(int argc, char *argv[]) count++; fwrite(out, sizeof(short), (frame_size-skip)*channels, fout); skip = 0; - RESTORE_STACK; } celt_encoder_destroy(enc); celt_decoder_destroy(dec); @@ -159,8 +155,8 @@ int main(int argc, char *argv[]) } #endif celt_mode_destroy(mode); - celt_free(in); - celt_free(out); + free(in); + free(out); return 0; } -- GitLab