-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter.c
80 lines (73 loc) · 1.56 KB
/
filter.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "filter.h"
static float filter_taps[SAMPLEFILTER_TAP_NUM] = {
-0.000325463741319,
0.000756483757868,
0.00146557833068,
0.00095358339604,
-0.00103854783811,
-0.00319028855301,
-0.00293344305828,
0.00109442975372,
0.00640950677916,
0.00738019868731,
0.000352530216333,
-0.010853914544,
-0.0155918952078,
-0.00530383270234,
0.01583962515,
0.0297110620886,
0.01755319722,
-0.0204241275787,
-0.056505702436,
-0.0497136823833,
0.023651458323,
0.145785108209,
0.260909825563,
0.308036655188,
0.260909825563,
0.145785108209,
0.023651458323,
-0.0497136823833,
-0.056505702436,
-0.0204241275787,
0.01755319722,
0.0297110620886,
0.01583962515,
-0.00530383270234,
-0.0155918952078,
-0.010853914544,
0.000352530216333,
0.00738019868731,
0.00640950677916,
0.00109442975372,
-0.00293344305828,
-0.00319028855301,
-0.00103854783811,
0.00095358339604,
0.00146557833068,
0.000756483757868,
-0.000325463741319,
};
#pragma GCC push_options
#pragma GCC optimize ("unroll-loops")
void SampleFilter_init(SampleFilter* f) {
int i;
for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i)
f->history[i] = 0;
f->last_index = 0;
}
void SampleFilter_put(SampleFilter* f, float input) {
f->history[f->last_index++] = input;
if(f->last_index == SAMPLEFILTER_TAP_NUM)
f->last_index = 0;
}
float SampleFilter_get(SampleFilter* f) {
float acc = 0;
int index = f->last_index, i;
for(i = 0; i < SAMPLEFILTER_TAP_NUM; ++i) {
index = index != 0 ? index-1 : SAMPLEFILTER_TAP_NUM-1;
acc += f->history[index] * filter_taps[i];
};
return acc;
}
#pragma GCC pop_options