annotate tools/audio_processor_test/fir/checker/checker.cpp @ 75:a15cc186e07d pygar svn.76

[svn r76] should be fully parameterized for however many cores we want (not fully tested)
author punk
date Wed, 12 May 2010 03:14:53 -0400
parents 90197e3375e2
children
rev   line source
rlm@23 1 #include <stdio.h>
rlm@23 2 #include <assert.h>
rlm@23 3 #include <string.h>
rlm@23 4 #include "SndfileWavUtil.h"
rlm@23 5
rlm@23 6 const int Taps = 9;
rlm@23 7 static int newest;
rlm@23 8 static short int x[Taps] = {0,0,0,0,0,0,0,0,0};
rlm@23 9 static short int fir(short int);
rlm@23 10 const int short_sz = sizeof(short);
rlm@23 11
rlm@23 12 // lifted from the bluespec code
rlm@23 13 static double h[Taps] = {-0.0124,
rlm@23 14 0.0,
rlm@23 15 -0.0133,
rlm@23 16 0.0,
rlm@23 17 0.8181,
rlm@23 18 0.0,
rlm@23 19 -0.0133,
rlm@23 20 0.0,
rlm@23 21 -0.0124};
rlm@23 22
rlm@23 23
rlm@23 24 int
rlm@23 25 main (int argc, char * argv [])
rlm@23 26 {
rlm@23 27 const char* inputWavFileName;
rlm@23 28 const char* outputWavFileName;
rlm@23 29
rlm@23 30 FILE *inputPcmFile;
rlm@23 31 FILE *outputPcmFile;
rlm@23 32
rlm@23 33 short int sample;
rlm@23 34
rlm@23 35 inputWavFileName = argv[1];
rlm@23 36 outputWavFileName = argv[2];
rlm@23 37
rlm@23 38 // Convert input wav to pcm
rlm@23 39 generate_pcm(inputWavFileName, "input.pcm");
rlm@23 40
rlm@23 41 inputPcmFile = fopen("input.pcm", "r");
rlm@23 42 outputPcmFile = fopen("output.pcm", "w");
rlm@23 43
rlm@23 44 assert(inputPcmFile);
rlm@23 45 assert(outputPcmFile);
rlm@23 46
rlm@23 47 newest = 0;
rlm@23 48 memset(x, 0, sizeof(x));
rlm@23 49
rlm@23 50 while(fread(&sample, short_sz, 1, inputPcmFile)) {
rlm@23 51 sample = fir(sample);
rlm@23 52 assert(fwrite(&sample,short_sz,1,outputPcmFile));
rlm@23 53 }
rlm@23 54
rlm@23 55 fclose(inputPcmFile);
rlm@23 56 fclose(outputPcmFile);
rlm@23 57
rlm@23 58 generate_wav("output.pcm", inputWavFileName, outputWavFileName);
rlm@23 59 }
rlm@23 60
rlm@23 61 short int
rlm@23 62 fir(short int sample)
rlm@23 63 {
rlm@23 64
rlm@23 65 x[newest] = sample;
rlm@23 66 double y = 0;
rlm@23 67
rlm@23 68 for (int k = 0; k < Taps; k++) {
rlm@23 69
rlm@23 70 short int bits = x[(newest+k)%Taps];
rlm@23 71 double x = (double)bits;
rlm@23 72 y += h[k] * x;
rlm@23 73
rlm@23 74 }
rlm@23 75
rlm@23 76 newest = (newest == 0) ? (Taps-1) : (newest-1);
rlm@23 77
rlm@23 78 short int rv = ((short int)y)&0x0000FFFF;
rlm@23 79 return rv;
rlm@23 80 }
rlm@23 81