Mercurial > pygar
view tools/audio_processor_test/fir/checker/checker.cpp @ 47:97d1959f7c5c pygar svn.48
[svn r48] changed sctipt to use our own programs, changed rlp.wav and rlp1.wav to be shorter
author | rlm |
---|---|
date | Wed, 05 May 2010 13:23:58 -0400 |
parents | 90197e3375e2 |
children |
line wrap: on
line source
1 #include <stdio.h>2 #include <assert.h>3 #include <string.h>4 #include "SndfileWavUtil.h"6 const int Taps = 9;7 static int newest;8 static short int x[Taps] = {0,0,0,0,0,0,0,0,0};9 static short int fir(short int);10 const int short_sz = sizeof(short);12 // lifted from the bluespec code13 static double h[Taps] = {-0.0124,14 0.0,15 -0.0133,16 0.0,17 0.8181,18 0.0,19 -0.0133,20 0.0,21 -0.0124};24 int25 main (int argc, char * argv [])26 {27 const char* inputWavFileName;28 const char* outputWavFileName;30 FILE *inputPcmFile;31 FILE *outputPcmFile;33 short int sample;35 inputWavFileName = argv[1];36 outputWavFileName = argv[2];38 // Convert input wav to pcm39 generate_pcm(inputWavFileName, "input.pcm");41 inputPcmFile = fopen("input.pcm", "r");42 outputPcmFile = fopen("output.pcm", "w");44 assert(inputPcmFile);45 assert(outputPcmFile);47 newest = 0;48 memset(x, 0, sizeof(x));50 while(fread(&sample, short_sz, 1, inputPcmFile)) {51 sample = fir(sample);52 assert(fwrite(&sample,short_sz,1,outputPcmFile));53 }55 fclose(inputPcmFile);56 fclose(outputPcmFile);58 generate_wav("output.pcm", inputWavFileName, outputWavFileName);59 }61 short int62 fir(short int sample)63 {65 x[newest] = sample;66 double y = 0;68 for (int k = 0; k < Taps; k++) {70 short int bits = x[(newest+k)%Taps];71 double x = (double)bits;72 y += h[k] * x;74 }76 newest = (newest == 0) ? (Taps-1) : (newest-1);78 short int rv = ((short int)y)&0x0000FFFF;79 return rv;80 }