Mercurial > pygar
diff tools/audio_processor_test/fir/checker/checker.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/fir/checker/checker.cpp Wed Apr 28 08:19:09 2010 -0400 1.3 @@ -0,0 +1,81 @@ 1.4 +#include <stdio.h> 1.5 +#include <assert.h> 1.6 +#include <string.h> 1.7 +#include "SndfileWavUtil.h" 1.8 + 1.9 +const int Taps = 9; 1.10 +static int newest; 1.11 +static short int x[Taps] = {0,0,0,0,0,0,0,0,0}; 1.12 +static short int fir(short int); 1.13 +const int short_sz = sizeof(short); 1.14 + 1.15 +// lifted from the bluespec code 1.16 +static double h[Taps] = {-0.0124, 1.17 + 0.0, 1.18 + -0.0133, 1.19 + 0.0, 1.20 + 0.8181, 1.21 + 0.0, 1.22 + -0.0133, 1.23 + 0.0, 1.24 + -0.0124}; 1.25 + 1.26 + 1.27 +int 1.28 +main (int argc, char * argv []) 1.29 +{ 1.30 + const char* inputWavFileName; 1.31 + const char* outputWavFileName; 1.32 + 1.33 + FILE *inputPcmFile; 1.34 + FILE *outputPcmFile; 1.35 + 1.36 + short int sample; 1.37 + 1.38 + inputWavFileName = argv[1]; 1.39 + outputWavFileName = argv[2]; 1.40 + 1.41 + // Convert input wav to pcm 1.42 + generate_pcm(inputWavFileName, "input.pcm"); 1.43 + 1.44 + inputPcmFile = fopen("input.pcm", "r"); 1.45 + outputPcmFile = fopen("output.pcm", "w"); 1.46 + 1.47 + assert(inputPcmFile); 1.48 + assert(outputPcmFile); 1.49 + 1.50 + newest = 0; 1.51 + memset(x, 0, sizeof(x)); 1.52 + 1.53 + while(fread(&sample, short_sz, 1, inputPcmFile)) { 1.54 + sample = fir(sample); 1.55 + assert(fwrite(&sample,short_sz,1,outputPcmFile)); 1.56 + } 1.57 + 1.58 + fclose(inputPcmFile); 1.59 + fclose(outputPcmFile); 1.60 + 1.61 + generate_wav("output.pcm", inputWavFileName, outputWavFileName); 1.62 +} 1.63 + 1.64 +short int 1.65 +fir(short int sample) 1.66 +{ 1.67 + 1.68 + x[newest] = sample; 1.69 + double y = 0; 1.70 + 1.71 + for (int k = 0; k < Taps; k++) { 1.72 + 1.73 + short int bits = x[(newest+k)%Taps]; 1.74 + double x = (double)bits; 1.75 + y += h[k] * x; 1.76 + 1.77 + } 1.78 + 1.79 + newest = (newest == 0) ? (Taps-1) : (newest-1); 1.80 + 1.81 + short int rv = ((short int)y)&0x0000FFFF; 1.82 + return rv; 1.83 +} 1.84 +