Mercurial > pygar
diff tools/audio_processor_test/gen_tone/gen_tone.cpp @ 23:90197e3375e2 pygar svn.24
[svn r24] added testing, but something is wrong with our c++ file.
author | rlm |
---|---|
date | Wed, 28 Apr 2010 08:19:09 -0400 |
parents | |
children |
line wrap: on
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tools/audio_processor_test/gen_tone/gen_tone.cpp Wed Apr 28 08:19:09 2010 -0400 1.3 @@ -0,0 +1,63 @@ 1.4 +#include <stdio.h> 1.5 +#include <assert.h> 1.6 +#include <string.h> 1.7 +#include <sndfile.h> 1.8 +#include <stdlib.h> 1.9 +#include "SndfileWavUtil.h" 1.10 + 1.11 +// foreward declaration. This is defined in DFT.cpp 1.12 +int DFT(int dir,int m,double *x1,double *y1); 1.13 + 1.14 +const int Points = 8; 1.15 + 1.16 +int 1.17 +do_gen (int argc, char * argv []) 1.18 +{ 1.19 + int frames; 1.20 + int targ_freqA; 1.21 + int targ_freqB; 1.22 + char* refWavFile; 1.23 + char* outWavFile; 1.24 + FILE* outPCM; 1.25 + const int short_sz = sizeof(short int); 1.26 + 1.27 + frames = atoi(argv[1]); 1.28 + targ_freqA = atoi(argv[2]); 1.29 + targ_freqB = atoi(argv[3]); 1.30 + refWavFile = argv[4]; 1.31 + outWavFile = argv[5]; 1.32 + 1.33 + outPCM = fopen("output.pcm", "w"); 1.34 + 1.35 + printf("targ_freqA %d\ntarg_freqB %d\nframes %d\n", targ_freqA, targ_freqB, frames); 1.36 + 1.37 + while(frames-- > 0){ 1.38 + 1.39 + double dreal[Points]; 1.40 + double dimag[Points]; 1.41 + 1.42 + for(int i = 0; i < Points; i++) 1.43 + dreal[i] = (i == targ_freqA) ? 1000 : (i == targ_freqB) ? 1000 : 0; 1.44 + for(int i = 0; i < Points; i++) 1.45 + dimag[i] = 0.0; 1.46 + 1.47 + DFT(-1,Points,dreal,dimag); 1.48 + 1.49 + for(int i = 0; i < Points; i++){ 1.50 + short int rv = (int)dreal[i]; 1.51 + assert(fwrite(&rv,short_sz,1,outPCM)); 1.52 + } 1.53 + 1.54 + } 1.55 + 1.56 + fclose(outPCM); 1.57 + 1.58 + generate_wav("output.pcm", refWavFile, outWavFile); 1.59 +} 1.60 + 1.61 +int 1.62 +main(int argc, char* argv[]) 1.63 +{ 1.64 + do_gen(argc, argv); 1.65 + exit(1); 1.66 +}