ref: c7e0b76c06101766201f7b6ee1859306f5480914
parent: 4ff068e670a9e857aa3f3879190279ca2d9d38f1
author: Jean-Marc Valin <[email protected]>
date: Sun Mar 16 03:55:29 EDT 2008
Making sure not to use the C library calls directly
--- a/libcelt/_kiss_fft_guts.h
+++ b/libcelt/_kiss_fft_guts.h
@@ -224,8 +224,5 @@
(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 */
--- 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. */
--- 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"
--- 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);
--- 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"
--- a/libcelt/entenc.c
+++ b/libcelt/entenc.c
@@ -59,7 +59,7 @@
}
void ec_byte_writeclear(ec_byte_buffer *_b){
- free(_b->buf);
+ celt_free(_b->buf);
}
--- 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
--- a/libcelt/os_support.h
+++ b/libcelt/os_support.h
@@ -116,7 +116,7 @@
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 @@
}
#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 */
--- 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)
{
--- 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};
--- 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 @@
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)
--- 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 @@
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 @@
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 @@
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 @@
}
#endif
celt_mode_destroy(mode);
- celt_free(in);
- celt_free(out);
+ free(in);
+ free(out);
return 0;
}