From: drowe67 Date: Thu, 15 Mar 2012 19:45:14 +0000 (+0000) Subject: clean up ptahces from Thomas X-Git-Url: http://git.whiteaudio.com/gitweb/?a=commitdiff_plain;h=317f197387fa1de2317a562d9d6d29e713c33a11;p=freetel-svn-tracking.git clean up ptahces from Thomas git-svn-id: https://svn.code.sf.net/p/freetel/code@346 01035d8c-6547-0410-b346-abe4f91aad63 --- diff --git a/codec2-dev/src/fft.c b/codec2-dev/src/fft.c index df1fbcf1..f75f110a 100644 --- a/codec2-dev/src/fft.c +++ b/codec2-dev/src/fft.c @@ -34,10 +34,10 @@ \*---------------------------------------------------------------------------*/ -kiss_fft_cpx *fin; -kiss_fft_cpx *fout; -kiss_fft_cfg cfg_forward; -kiss_fft_cfg cfg_reverse; +kiss_fft_cpx *fin = 0; +kiss_fft_cpx *fout = 0; +kiss_fft_cfg cfg_forward = 0; +kiss_fft_cfg cfg_reverse = 0; /*---------------------------------------------------------------------------*\ @@ -51,6 +51,7 @@ kiss_fft_cfg cfg_reverse; void initialize_fft (int n) { + assert(!fin && !fout && !cfg_forward && !cfg_reverse); fin = KISS_FFT_MALLOC (n * sizeof (kiss_fft_cpx)); assert(fin != NULL); fout = KISS_FFT_MALLOC (n * sizeof (kiss_fft_cpx)); @@ -98,3 +99,11 @@ fft (float x[], int n, int isign) x[c + 1] = -fout[(c) / 2].i; } } + +void cleanup_fft(void) +{ + KISS_FFT_FREE(fin); + KISS_FFT_FREE(fout); + KISS_FFT_FREE(cfg_forward); + KISS_FFT_FREE(cfg_reverse); +} diff --git a/codec2-dev/src/fft.h b/codec2-dev/src/fft.h index 84c6737b..e6b583be 100644 --- a/codec2-dev/src/fft.h +++ b/codec2-dev/src/fft.h @@ -12,5 +12,11 @@ #define __FFT__ void fft(float x[], int n, int isign); +void cleanup_fft(void) +#ifdef __GNUC__ + __attribute__ ((destructor)) +#endif + ; + #endif /* __FFT__ */ diff --git a/codec2-dev/unittest/extract.c b/codec2-dev/unittest/extract.c index 36c6d681..77196248 100644 --- a/codec2-dev/unittest/extract.c +++ b/codec2-dev/unittest/extract.c @@ -45,8 +45,8 @@ int main(int argc, char *argv[]) { long lines; /* lines read so far */ if (argc != 5) { - printf("usage: extract TextFile FloatFile start(1 .. 10) end(1 .. 10)\n"); - exit(0); + printf("usage: %s TextFile FloatFile start(1 .. 10) end(1 .. 10)\n", argv[0]); + exit(1); } /* read command line arguments and open files */ diff --git a/codec2-dev/unittest/genlsp.c b/codec2-dev/unittest/genlsp.c index f4a3ddc4..dc608930 100644 --- a/codec2-dev/unittest/genlsp.c +++ b/codec2-dev/unittest/genlsp.c @@ -75,8 +75,8 @@ int main(int argc, char *argv[]) { /* Initialise ------------------------------------------------------*/ if (argc < 3) { - printf("usage: gentest RawFile LSPTextFile [--lspd] [--log] [--lspdt] \n"); - exit(0); + printf("usage: %s RawFile LSPTextFile [--lspd] [--log] [--lspdt] \n", argv[0]); + exit(1); } /* Open files */ diff --git a/codec2-dev/unittest/genres.c b/codec2-dev/unittest/genres.c index 7fb501b4..2da9662c 100644 --- a/codec2-dev/unittest/genres.c +++ b/codec2-dev/unittest/genres.c @@ -46,7 +46,7 @@ int main(int argc, char *argv[]) if (argc < 3) { printf("usage: %s InputFile ResidualFile\n", argv[0]); - exit(0); + exit(1); } /* Open files */ diff --git a/codec2-dev/unittest/mksine.c b/codec2-dev/unittest/mksine.c index 2383e79b..3e5c551a 100644 --- a/codec2-dev/unittest/mksine.c +++ b/codec2-dev/unittest/mksine.c @@ -22,8 +22,8 @@ int main(int argc, char *argv[]) { short buf[N]; if (argc != 3) { - printf("usage: mksine outputFile frequencyHz\n"); - exit(0); + printf("usage: %s outputFile frequencyHz\n", argv[0]); + exit(1); } f = fopen(argv[1] ,"wb"); diff --git a/codec2-dev/unittest/run_tests.sh b/codec2-dev/unittest/run_tests.sh new file mode 100644 index 00000000..06e7b6b9 --- /dev/null +++ b/codec2-dev/unittest/run_tests.sh @@ -0,0 +1,27 @@ +#!/bin/bash + +# verbose, skittish +set -ex + +# run valgrind? +VG="valgrind --error-exitcode=149 --leak-check=full --show-reachable=yes" + +# make sure we're up-to-date +make + + +# runs, not certaion wht it does yet +${VG} ./tcodec2 +${VG} ./tinterp +${VG} ./tquant + +# these fail, missing arguments +${VG} ./extract +${VG} ./genlsp +${VG} ./genres +${VG} ./scalarlsptest +${VG} ./tnlp +${VG} ./vq_train_jvm +${VG} ./vqtrain +${VG} ./vqtrainjnd + diff --git a/codec2-dev/unittest/scalarlsptest.c b/codec2-dev/unittest/scalarlsptest.c index f77a6959..2bf21335 100644 --- a/codec2-dev/unittest/scalarlsptest.c +++ b/codec2-dev/unittest/scalarlsptest.c @@ -53,7 +53,7 @@ int main(int argc, char *argv[]) if (argc < 2) { printf("usage: %s InputFile\n", argv[0]); - exit(0); + exit(1); } if ((ftrain = fopen(argv[1],"rt")) == NULL) { diff --git a/codec2-dev/unittest/tcodec2.c b/codec2-dev/unittest/tcodec2.c index a0b5b4be..c6d4d78e 100644 --- a/codec2-dev/unittest/tcodec2.c +++ b/codec2-dev/unittest/tcodec2.c @@ -185,7 +185,10 @@ int test3() struct CODEC2 *c2; c2 = codec2_create(CODEC2_MODE_2500); - bits = (char*)malloc(codec2_bits_per_frame(c2)); + int numBits = codec2_bits_per_frame(c2); + int numBytes = (numBits+7)>>3; + + bits = (char*)malloc(numBytes); fin = fopen("../raw/hts1a.raw", "rb"); assert(fin != NULL); @@ -196,9 +199,9 @@ int test3() while(fread(buf1, sizeof(short), 2*N, fin) == 2*N) { codec2_encode(c2, (void*)bits, buf1); - fwrite(bits, sizeof(char), codec2_bits_per_frame(c2), fbits); + fwrite(bits, sizeof(char), numBytes, fbits); codec2_decode(c2, buf2, (void*)bits); - fwrite(buf2, sizeof(short), codec2_bits_per_frame(c2), fout); + fwrite(buf2, sizeof(short), numBytes, fout); } free(bits); diff --git a/codec2-dev/unittest/tcontphase.c b/codec2-dev/unittest/tcontphase.c index 403e4f94..6761bac8 100644 --- a/codec2-dev/unittest/tcontphase.c +++ b/codec2-dev/unittest/tcontphase.c @@ -102,8 +102,8 @@ char *argv[]; float f0; if (argc < 3) { - printf("\nusage: tcontphase OutputRawSpeechFile F0\n"); - exit(0); + printf("\nusage: %s OutputRawSpeechFile F0\n", argv[0]); + exit(1); } /* Output file */ diff --git a/codec2-dev/unittest/tinterp.c b/codec2-dev/unittest/tinterp.c index 52e782b4..8520c832 100644 --- a/codec2-dev/unittest/tinterp.c +++ b/codec2-dev/unittest/tinterp.c @@ -31,6 +31,9 @@ #include #include #include +#include +#include +#include #include "defines.h" #include "sine.h" @@ -59,13 +62,14 @@ void write_amp(char file[], MODEL *model) fclose(f); } -char *get_next_float(char *s, float *num) +const char *get_next_float(const char *s, float *num) { - char *p = s; + const char *p = s; char tmp[MAX_STR]; while(*p && !isspace(*p)) p++; + assert((p-s) < (int)(sizeof(tmp)-1)); memcpy(tmp, s, p-s); tmp[p-s] = 0; *num = atof(tmp); @@ -73,13 +77,14 @@ char *get_next_float(char *s, float *num) return p+1; } -char *get_next_int(char *s, int *num) +const char *get_next_int(const char *s, int *num) { - char *p = s; + const char *p = s; char tmp[MAX_STR]; while(*p && !isspace(*p)) p++; + assert((p-s) < (int)(sizeof(tmp)-1)); memcpy(tmp, s, p-s); tmp[p-s] = 0; *num = atoi(tmp); @@ -87,14 +92,15 @@ char *get_next_int(char *s, int *num) return p+1; } -void load_amp(MODEL *model, char file[], int frame) +void load_amp(MODEL *model, const char * file, int frame) { FILE *f; int i; char s[1024]; - char *ps; + const char *ps; f = fopen(file,"rt"); + assert(f); for(i=0; i