rlm@23: #include rlm@23: #include rlm@23: #include rlm@23: #include "SndfileWavUtil.h" rlm@23: rlm@23: const int Taps = 9; rlm@23: static int newest; rlm@23: static short int x[Taps] = {0,0,0,0,0,0,0,0,0}; rlm@23: static short int fir(short int); rlm@23: const int short_sz = sizeof(short); rlm@23: rlm@23: // lifted from the bluespec code rlm@23: static double h[Taps] = {-0.0124, rlm@23: 0.0, rlm@23: -0.0133, rlm@23: 0.0, rlm@23: 0.8181, rlm@23: 0.0, rlm@23: -0.0133, rlm@23: 0.0, rlm@23: -0.0124}; rlm@23: rlm@23: rlm@23: int rlm@23: main (int argc, char * argv []) rlm@23: { rlm@23: const char* inputWavFileName; rlm@23: const char* outputWavFileName; rlm@23: rlm@23: FILE *inputPcmFile; rlm@23: FILE *outputPcmFile; rlm@23: rlm@23: short int sample; rlm@23: rlm@23: inputWavFileName = argv[1]; rlm@23: outputWavFileName = argv[2]; rlm@23: rlm@23: // Convert input wav to pcm rlm@23: generate_pcm(inputWavFileName, "input.pcm"); rlm@23: rlm@23: inputPcmFile = fopen("input.pcm", "r"); rlm@23: outputPcmFile = fopen("output.pcm", "w"); rlm@23: rlm@23: assert(inputPcmFile); rlm@23: assert(outputPcmFile); rlm@23: rlm@23: newest = 0; rlm@23: memset(x, 0, sizeof(x)); rlm@23: rlm@23: while(fread(&sample, short_sz, 1, inputPcmFile)) { rlm@23: sample = fir(sample); rlm@23: assert(fwrite(&sample,short_sz,1,outputPcmFile)); rlm@23: } rlm@23: rlm@23: fclose(inputPcmFile); rlm@23: fclose(outputPcmFile); rlm@23: rlm@23: generate_wav("output.pcm", inputWavFileName, outputWavFileName); rlm@23: } rlm@23: rlm@23: short int rlm@23: fir(short int sample) rlm@23: { rlm@23: rlm@23: x[newest] = sample; rlm@23: double y = 0; rlm@23: rlm@23: for (int k = 0; k < Taps; k++) { rlm@23: rlm@23: short int bits = x[(newest+k)%Taps]; rlm@23: double x = (double)bits; rlm@23: y += h[k] * x; rlm@23: rlm@23: } rlm@23: rlm@23: newest = (newest == 0) ? (Taps-1) : (newest-1); rlm@23: rlm@23: short int rv = ((short int)y)&0x0000FFFF; rlm@23: return rv; rlm@23: } rlm@23: