Mercurial > pygar
comparison 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 |
comparison
equal
deleted
inserted
replaced
22:0cfbb1e2de22 | 23:90197e3375e2 |
---|---|
1 #include <stdio.h> | |
2 #include <assert.h> | |
3 #include <string.h> | |
4 #include "SndfileWavUtil.h" | |
5 | |
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); | |
11 | |
12 // lifted from the bluespec code | |
13 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}; | |
22 | |
23 | |
24 int | |
25 main (int argc, char * argv []) | |
26 { | |
27 const char* inputWavFileName; | |
28 const char* outputWavFileName; | |
29 | |
30 FILE *inputPcmFile; | |
31 FILE *outputPcmFile; | |
32 | |
33 short int sample; | |
34 | |
35 inputWavFileName = argv[1]; | |
36 outputWavFileName = argv[2]; | |
37 | |
38 // Convert input wav to pcm | |
39 generate_pcm(inputWavFileName, "input.pcm"); | |
40 | |
41 inputPcmFile = fopen("input.pcm", "r"); | |
42 outputPcmFile = fopen("output.pcm", "w"); | |
43 | |
44 assert(inputPcmFile); | |
45 assert(outputPcmFile); | |
46 | |
47 newest = 0; | |
48 memset(x, 0, sizeof(x)); | |
49 | |
50 while(fread(&sample, short_sz, 1, inputPcmFile)) { | |
51 sample = fir(sample); | |
52 assert(fwrite(&sample,short_sz,1,outputPcmFile)); | |
53 } | |
54 | |
55 fclose(inputPcmFile); | |
56 fclose(outputPcmFile); | |
57 | |
58 generate_wav("output.pcm", inputWavFileName, outputWavFileName); | |
59 } | |
60 | |
61 short int | |
62 fir(short int sample) | |
63 { | |
64 | |
65 x[newest] = sample; | |
66 double y = 0; | |
67 | |
68 for (int k = 0; k < Taps; k++) { | |
69 | |
70 short int bits = x[(newest+k)%Taps]; | |
71 double x = (double)bits; | |
72 y += h[k] * x; | |
73 | |
74 } | |
75 | |
76 newest = (newest == 0) ? (Taps-1) : (newest-1); | |
77 | |
78 short int rv = ((short int)y)&0x0000FFFF; | |
79 return rv; | |
80 } | |
81 |