This source file includes following definitions.
- fir16_create
- fir16_flush
- fir16_free
- fir16
- fir32_create
- fir32_flush
- fir32_free
- fir32
1
2
3
4
5
6
7
8
9
10
11
12
13
14 #if !defined(_FIR_H_)
15 #define _FIR_H_
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 struct fir16_state_t {
42 int taps;
43 int curr_pos;
44 const int16_t *coeffs;
45 int16_t *history;
46 };
47
48
49
50
51
52
53 struct fir32_state_t {
54 int taps;
55 int curr_pos;
56 const int32_t *coeffs;
57 int16_t *history;
58 };
59
60
61
62
63
64 struct fir_float_state_t {
65 int taps;
66 int curr_pos;
67 const float *coeffs;
68 float *history;
69 };
70
71 static inline const int16_t *fir16_create(struct fir16_state_t *fir,
72 const int16_t *coeffs, int taps)
73 {
74 fir->taps = taps;
75 fir->curr_pos = taps - 1;
76 fir->coeffs = coeffs;
77 fir->history = kcalloc(taps, sizeof(int16_t), GFP_KERNEL);
78 return fir->history;
79 }
80
81 static inline void fir16_flush(struct fir16_state_t *fir)
82 {
83 memset(fir->history, 0, fir->taps * sizeof(int16_t));
84 }
85
86 static inline void fir16_free(struct fir16_state_t *fir)
87 {
88 kfree(fir->history);
89 }
90
91 static inline int16_t fir16(struct fir16_state_t *fir, int16_t sample)
92 {
93 int32_t y;
94 int i;
95 int offset1;
96 int offset2;
97
98 fir->history[fir->curr_pos] = sample;
99
100 offset2 = fir->curr_pos;
101 offset1 = fir->taps - offset2;
102 y = 0;
103 for (i = fir->taps - 1; i >= offset1; i--)
104 y += fir->coeffs[i] * fir->history[i - offset1];
105 for (; i >= 0; i--)
106 y += fir->coeffs[i] * fir->history[i + offset2];
107 if (fir->curr_pos <= 0)
108 fir->curr_pos = fir->taps;
109 fir->curr_pos--;
110 return (int16_t) (y >> 15);
111 }
112
113 static inline const int16_t *fir32_create(struct fir32_state_t *fir,
114 const int32_t *coeffs, int taps)
115 {
116 fir->taps = taps;
117 fir->curr_pos = taps - 1;
118 fir->coeffs = coeffs;
119 fir->history = kcalloc(taps, sizeof(int16_t), GFP_KERNEL);
120 return fir->history;
121 }
122
123 static inline void fir32_flush(struct fir32_state_t *fir)
124 {
125 memset(fir->history, 0, fir->taps * sizeof(int16_t));
126 }
127
128 static inline void fir32_free(struct fir32_state_t *fir)
129 {
130 kfree(fir->history);
131 }
132
133 static inline int16_t fir32(struct fir32_state_t *fir, int16_t sample)
134 {
135 int i;
136 int32_t y;
137 int offset1;
138 int offset2;
139
140 fir->history[fir->curr_pos] = sample;
141 offset2 = fir->curr_pos;
142 offset1 = fir->taps - offset2;
143 y = 0;
144 for (i = fir->taps - 1; i >= offset1; i--)
145 y += fir->coeffs[i] * fir->history[i - offset1];
146 for (; i >= 0; i--)
147 y += fir->coeffs[i] * fir->history[i + offset2];
148 if (fir->curr_pos <= 0)
149 fir->curr_pos = fir->taps;
150 fir->curr_pos--;
151 return (int16_t) (y >> 15);
152 }
153
154 #endif