Mercurial > mplayer.hg
annotate libaf/filter.c @ 32151:681716cd9232
Simplify DirectFB check using function_check().
author | diego |
---|---|
date | Tue, 14 Sep 2010 10:25:12 +0000 |
parents | 32725ca88fed |
children |
rev | line source |
---|---|
28229
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
1 /* |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
2 * design and implementation of different types of digital filters |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
3 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
4 * Copyright (C) 2001 Anders Johansson ajh@atri.curtin.edu.au |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
5 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
6 * This file is part of MPlayer. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
7 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
11 * (at your option) any later version. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
12 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
16 * GNU General Public License for more details. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
17 * |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
72d0b1444141
Replace informal license notices by standard license header
diego
parents:
27258
diff
changeset
|
21 */ |
7568 | 22 |
9217
420e2b2f8e5a
compiler warning fixes patch by Dominik Mierzejewski <dominik@rangers.eu.org>
arpi
parents:
8832
diff
changeset
|
23 #include <string.h> |
7568 | 24 #include <math.h> |
25 #include "dsp.h" | |
26 | |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
27 /****************************************************************************** |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
28 * FIR filter implementations |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
29 ******************************************************************************/ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
30 |
7568 | 31 /* C implementation of FIR filter y=w*x |
32 | |
33 n number of filter taps, where mod(n,4)==0 | |
34 w filter taps | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
35 x input signal must be a circular buffer which is indexed backwards |
7568 | 36 */ |
27258 | 37 inline FLOAT_TYPE af_filter_fir(register unsigned int n, const FLOAT_TYPE* w, |
38 const FLOAT_TYPE* x) | |
7568 | 39 { |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
40 register FLOAT_TYPE y; // Output |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
41 y = 0.0; |
7568 | 42 do{ |
43 n--; | |
44 y+=w[n]*x[n]; | |
45 }while(n != 0); | |
46 return y; | |
47 } | |
48 | |
49 /* C implementation of parallel FIR filter y(k)=w(k) * x(k) (where * denotes convolution) | |
50 | |
51 n number of filter taps, where mod(n,4)==0 | |
52 d number of filters | |
53 xi current index in xq | |
54 w filter taps k by n big | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
55 x input signal must be a circular buffers which are indexed backwards |
7568 | 56 y output buffer |
57 s output buffer stride | |
58 */ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
59 FLOAT_TYPE* af_filter_pfir(unsigned int n, unsigned int d, unsigned int xi, |
27258 | 60 const FLOAT_TYPE** w, const FLOAT_TYPE** x, FLOAT_TYPE* y, |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
61 unsigned int s) |
7568 | 62 { |
27258 | 63 register const FLOAT_TYPE* xt = *x + xi; |
64 register const FLOAT_TYPE* wt = *w; | |
7568 | 65 register int nt = 2*n; |
66 while(d-- > 0){ | |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14274
diff
changeset
|
67 *y = af_filter_fir(n,wt,xt); |
7568 | 68 wt+=n; |
69 xt+=nt; | |
70 y+=s; | |
71 } | |
72 return y; | |
73 } | |
74 | |
75 /* Add new data to circular queue designed to be used with a parallel | |
76 FIR filter, with d filters. xq is the circular queue, in pointing | |
77 at the new samples, xi current index in xq and n the length of the | |
78 filter. xq must be n*2 by k big, s is the index for in. | |
79 */ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
80 int af_filter_updatepq(unsigned int n, unsigned int d, unsigned int xi, |
27258 | 81 FLOAT_TYPE** xq, const FLOAT_TYPE* in, unsigned int s) |
7568 | 82 { |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
83 register FLOAT_TYPE* txq = *xq + xi; |
7568 | 84 register int nt = n*2; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
85 |
7568 | 86 while(d-- >0){ |
87 *txq= *(txq+n) = *in; | |
88 txq+=nt; | |
89 in+=s; | |
90 } | |
91 return (++xi)&(n-1); | |
92 } | |
93 | |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
94 /****************************************************************************** |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
95 * FIR filter design |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
96 ******************************************************************************/ |
7568 | 97 |
98 /* Design FIR filter using the Window method | |
99 | |
100 n filter length must be odd for HP and BS filters | |
101 w buffer for the filter taps (must be n long) | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
102 fc cutoff frequencies (1 for LP and HP, 2 for BP and BS) |
7568 | 103 0 < fc < 1 where 1 <=> Fs/2 |
104 flags window and filter type as defined in filter.h | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
105 variables are ored together: i.e. LP|HAMMING will give a |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
106 low pass filter designed using a hamming window |
7568 | 107 opt beta constant used only when designing using kaiser windows |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
108 |
7568 | 109 returns 0 if OK, -1 if fail |
110 */ | |
27258 | 111 int af_filter_design_fir(unsigned int n, FLOAT_TYPE* w, const FLOAT_TYPE* fc, |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
112 unsigned int flags, FLOAT_TYPE opt) |
7568 | 113 { |
114 unsigned int o = n & 1; // Indicator for odd filter length | |
115 unsigned int end = ((n + 1) >> 1) - o; // Loop end | |
116 unsigned int i; // Loop index | |
117 | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
118 FLOAT_TYPE k1 = 2 * M_PI; // 2*pi*fc1 |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
119 FLOAT_TYPE k2 = 0.5 * (FLOAT_TYPE)(1 - o);// Constant used if the filter has even length |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
120 FLOAT_TYPE k3; // 2*pi*fc2 Constant used in BP and BS design |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
121 FLOAT_TYPE g = 0.0; // Gain |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
122 FLOAT_TYPE t1,t2,t3; // Temporary variables |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
123 FLOAT_TYPE fc1,fc2; // Cutoff frequencies |
7568 | 124 |
125 // Sanity check | |
126 if(!w || (n == 0)) return -1; | |
127 | |
128 // Get window coefficients | |
129 switch(flags & WINDOW_MASK){ | |
130 case(BOXCAR): | |
14274 | 131 af_window_boxcar(n,w); break; |
7568 | 132 case(TRIANG): |
14274 | 133 af_window_triang(n,w); break; |
7568 | 134 case(HAMMING): |
14274 | 135 af_window_hamming(n,w); break; |
7568 | 136 case(HANNING): |
14274 | 137 af_window_hanning(n,w); break; |
7568 | 138 case(BLACKMAN): |
14274 | 139 af_window_blackman(n,w); break; |
7568 | 140 case(FLATTOP): |
14274 | 141 af_window_flattop(n,w); break; |
7568 | 142 case(KAISER): |
14274 | 143 af_window_kaiser(n,w,opt); break; |
7568 | 144 default: |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
145 return -1; |
7568 | 146 } |
147 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
148 if(flags & (LP | HP)){ |
7568 | 149 fc1=*fc; |
150 // Cutoff frequency must be < 0.5 where 0.5 <=> Fs/2 | |
151 fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25; | |
152 k1 *= fc1; | |
153 | |
154 if(flags & LP){ // Low pass filter | |
155 | |
156 // If the filter length is odd, there is one point which is exactly | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
157 // in the middle. The value at this point is 2*fCutoff*sin(x)/x, |
7568 | 158 // where x is zero. To make sure nothing strange happens, we set this |
159 // value separately. | |
160 if (o){ | |
161 w[end] = fc1 * w[end] * 2.0; | |
162 g=w[end]; | |
163 } | |
164 | |
165 // Create filter | |
166 for (i=0 ; i<end ; i++){ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
167 t1 = (FLOAT_TYPE)(i+1) - k2; |
7568 | 168 w[end-i-1] = w[n-end+i] = w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc |
169 g += 2*w[end-i-1]; // Total gain in filter | |
170 } | |
171 } | |
172 else{ // High pass filter | |
173 if (!o) // High pass filters must have odd length | |
174 return -1; | |
175 w[end] = 1.0 - (fc1 * w[end] * 2.0); | |
176 g= w[end]; | |
177 | |
178 // Create filter | |
179 for (i=0 ; i<end ; i++){ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
180 t1 = (FLOAT_TYPE)(i+1); |
7568 | 181 w[end-i-1] = w[n-end+i] = -1 * w[end-i-1] * sin(k1 * t1)/(M_PI * t1); // Sinc |
182 g += ((i&1) ? (2*w[end-i-1]) : (-2*w[end-i-1])); // Total gain in filter | |
183 } | |
184 } | |
185 } | |
186 | |
187 if(flags & (BP | BS)){ | |
188 fc1=fc[0]; | |
189 fc2=fc[1]; | |
190 // Cutoff frequencies must be < 1.0 where 1.0 <=> Fs/2 | |
191 fc1 = ((fc1 <= 1.0) && (fc1 > 0.0)) ? fc1/2 : 0.25; | |
192 fc2 = ((fc2 <= 1.0) && (fc2 > 0.0)) ? fc2/2 : 0.25; | |
193 k3 = k1 * fc2; // 2*pi*fc2 | |
194 k1 *= fc1; // 2*pi*fc1 | |
195 | |
196 if(flags & BP){ // Band pass | |
197 // Calculate center tap | |
198 if (o){ | |
199 g=w[end]*(fc1+fc2); | |
200 w[end] = (fc2 - fc1) * w[end] * 2.0; | |
201 } | |
202 | |
203 // Create filter | |
204 for (i=0 ; i<end ; i++){ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
205 t1 = (FLOAT_TYPE)(i+1) - k2; |
7568 | 206 t2 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 |
207 t3 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 | |
208 g += w[end-i-1] * (t3 + t2); // Total gain in filter | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
209 w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); |
7568 | 210 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
211 } |
7568 | 212 else{ // Band stop |
213 if (!o) // Band stop filters must have odd length | |
214 return -1; | |
215 w[end] = 1.0 - (fc2 - fc1) * w[end] * 2.0; | |
216 g= w[end]; | |
217 | |
218 // Create filter | |
219 for (i=0 ; i<end ; i++){ | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
220 t1 = (FLOAT_TYPE)(i+1); |
7568 | 221 t2 = sin(k1 * t1)/(M_PI * t1); // Sinc fc1 |
222 t3 = sin(k3 * t1)/(M_PI * t1); // Sinc fc2 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
223 w[end-i-1] = w[n-end+i] = w[end-i-1] * (t2 - t3); |
7568 | 224 g += 2*w[end-i-1]; // Total gain in filter |
225 } | |
226 } | |
227 } | |
228 | |
229 // Normalize gain | |
230 g=1/g; | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
231 for (i=0; i<n; i++) |
7568 | 232 w[i] *= g; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
233 |
7568 | 234 return 0; |
235 } | |
236 | |
237 /* Design polyphase FIR filter from prototype filter | |
238 | |
239 n length of prototype filter | |
240 k number of polyphase components | |
241 w prototype filter taps | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
242 pw Parallel FIR filter |
7568 | 243 g Filter gain |
244 flags FWD forward indexing | |
245 REW reverse indexing | |
246 ODD multiply every 2nd filter tap by -1 => HP filter | |
247 | |
248 returns 0 if OK, -1 if fail | |
249 */ | |
27258 | 250 int af_filter_design_pfir(unsigned int n, unsigned int k, const FLOAT_TYPE* w, |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
251 FLOAT_TYPE** pw, FLOAT_TYPE g, unsigned int flags) |
7568 | 252 { |
253 int l = (int)n/k; // Length of individual FIR filters | |
254 int i; // Counters | |
255 int j; | |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
256 FLOAT_TYPE t; // g * w[i] |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
257 |
7568 | 258 // Sanity check |
259 if(l<1 || k<1 || !w || !pw) | |
260 return -1; | |
261 | |
262 // Do the stuff | |
263 if(flags&REW){ | |
264 for(j=l-1;j>-1;j--){//Columns | |
265 for(i=0;i<(int)k;i++){//Rows | |
266 t=g * *w++; | |
267 pw[i][j]=t * ((flags & ODD) ? ((j & 1) ? -1 : 1) : 1); | |
268 } | |
269 } | |
270 } | |
271 else{ | |
272 for(j=0;j<l;j++){//Columns | |
273 for(i=0;i<(int)k;i++){//Rows | |
274 t=g * *w++; | |
275 pw[i][j]=t * ((flags & ODD) ? ((j & 1) ? 1 : -1) : 1); | |
276 } | |
277 } | |
278 } | |
279 return -1; | |
280 } | |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
281 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
282 /****************************************************************************** |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
283 * IIR filter design |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
284 ******************************************************************************/ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
285 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
286 /* Helper functions for the bilinear transform */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
287 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
288 /* Pre-warp the coefficients of a numerator or denominator. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
289 Note that a0 is assumed to be 1, so there is no wrapping |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
290 of it. |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
291 */ |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
292 static void af_filter_prewarp(FLOAT_TYPE* a, FLOAT_TYPE fc, FLOAT_TYPE fs) |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
293 { |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
294 FLOAT_TYPE wp; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
295 wp = 2.0 * fs * tan(M_PI * fc / fs); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
296 a[2] = a[2]/(wp * wp); |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
297 a[1] = a[1]/wp; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
298 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
299 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
300 /* Transform the numerator and denominator coefficients of s-domain |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
301 biquad section into corresponding z-domain coefficients. |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
302 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
303 The transfer function for z-domain is: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
304 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
305 1 + alpha1 * z^(-1) + alpha2 * z^(-2) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
306 H(z) = ------------------------------------- |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
307 1 + beta1 * z^(-1) + beta2 * z^(-2) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
308 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
309 Store the 4 IIR coefficients in array pointed by coef in following |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
310 order: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
311 beta1, beta2 (denominator) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
312 alpha1, alpha2 (numerator) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
313 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
314 Arguments: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
315 a - s-domain numerator coefficients |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
316 b - s-domain denominator coefficients |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
317 k - filter gain factor. Initially set to 1 and modified by each |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
318 biquad section in such a way, as to make it the |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
319 coefficient by which to multiply the overall filter gain |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
320 in order to achieve a desired overall filter gain, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
321 specified in initial value of k. |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
322 fs - sampling rate (Hz) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
323 coef - array of z-domain coefficients to be filled in. |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
324 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
325 Return: On return, set coef z-domain coefficients and k to the gain |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
326 required to maintain overall gain = 1.0; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
327 */ |
27258 | 328 static void af_filter_bilinear(const FLOAT_TYPE* a, const FLOAT_TYPE* b, FLOAT_TYPE* k, |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
329 FLOAT_TYPE fs, FLOAT_TYPE *coef) |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
330 { |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
331 FLOAT_TYPE ad, bd; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
332 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
333 /* alpha (Numerator in s-domain) */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
334 ad = 4. * a[2] * fs * fs + 2. * a[1] * fs + a[0]; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
335 /* beta (Denominator in s-domain) */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
336 bd = 4. * b[2] * fs * fs + 2. * b[1] * fs + b[0]; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
337 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
338 /* Update gain constant for this section */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
339 *k *= ad/bd; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
340 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
341 /* Denominator */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
342 *coef++ = (2. * b[0] - 8. * b[2] * fs * fs)/bd; /* beta1 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
343 *coef++ = (4. * b[2] * fs * fs - 2. * b[1] * fs + b[0])/bd; /* beta2 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
344 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
345 /* Numerator */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
346 *coef++ = (2. * a[0] - 8. * a[2] * fs * fs)/ad; /* alpha1 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
347 *coef = (4. * a[2] * fs * fs - 2. * a[1] * fs + a[0])/ad; /* alpha2 */ |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
348 } |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
349 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
350 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
351 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
352 /* IIR filter design using bilinear transform and prewarp. Transforms |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
353 2nd order s domain analog filter into a digital IIR biquad link. To |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
354 create a filter fill in a, b, Q and fs and make space for coef and k. |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
355 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
356 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
357 Example Butterworth design: |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
358 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
359 Below are Butterworth polynomials, arranged as a series of 2nd |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
360 order sections: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
361 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
362 Note: n is filter order. |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
363 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
364 n Polynomials |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
365 ------------------------------------------------------------------- |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
366 2 s^2 + 1.4142s + 1 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
367 4 (s^2 + 0.765367s + 1) * (s^2 + 1.847759s + 1) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
368 6 (s^2 + 0.5176387s + 1) * (s^2 + 1.414214 + 1) * (s^2 + 1.931852s + 1) |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
369 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
370 For n=4 we have following equation for the filter transfer function: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
371 1 1 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
372 T(s) = --------------------------- * ---------------------------- |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
373 s^2 + (1/Q) * 0.765367s + 1 s^2 + (1/Q) * 1.847759s + 1 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
374 |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
375 The filter consists of two 2nd order sections since highest s power |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
376 is 2. Now we can take the coefficients, or the numbers by which s |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
377 is multiplied and plug them into a standard formula to be used by |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
378 bilinear transform. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
379 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
380 Our standard form for each 2nd order section is: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
381 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
382 a2 * s^2 + a1 * s + a0 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
383 H(s) = ---------------------- |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
384 b2 * s^2 + b1 * s + b0 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
385 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
386 Note that Butterworth numerator is 1 for all filter sections, which |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
387 means s^2 = 0 and s^1 = 0 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
388 |
11000 | 389 Let's convert standard Butterworth polynomials into this form: |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
390 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
391 0 + 0 + 1 0 + 0 + 1 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
392 --------------------------- * -------------------------- |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
393 1 + ((1/Q) * 0.765367) + 1 1 + ((1/Q) * 1.847759) + 1 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
394 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
395 Section 1: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
396 a2 = 0; a1 = 0; a0 = 1; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
397 b2 = 1; b1 = 0.765367; b0 = 1; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
398 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
399 Section 2: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
400 a2 = 0; a1 = 0; a0 = 1; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
401 b2 = 1; b1 = 1.847759; b0 = 1; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
402 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
403 Q is filter quality factor or resonance, in the range of 1 to |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
404 1000. The overall filter Q is a product of all 2nd order stages. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
405 For example, the 6th order filter (3 stages, or biquads) with |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
406 individual Q of 2 will have filter Q = 2 * 2 * 2 = 8. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
407 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
408 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
409 Arguments: |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
410 a - s-domain numerator coefficients, a[1] is always assumed to be 1.0 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
411 b - s-domain denominator coefficients |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
412 Q - Q value for the filter |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
413 k - filter gain factor. Initially set to 1 and modified by each |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
414 biquad section in such a way, as to make it the |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
415 coefficient by which to multiply the overall filter gain |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
416 in order to achieve a desired overall filter gain, |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
417 specified in initial value of k. |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
418 fs - sampling rate (Hz) |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
419 coef - array of z-domain coefficients to be filled in. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
420 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
421 Note: Upon return from each call, the k argument will be set to a |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
422 value, by which to multiply our actual signal in order for the gain |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
423 to be one. On second call to szxform() we provide k that was |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
424 changed by the previous section. During actual audio filtering |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
425 k can be used for gain compensation. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
426 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
427 return -1 if fail 0 if success. |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
428 */ |
27258 | 429 int af_filter_szxform(const FLOAT_TYPE* a, const FLOAT_TYPE* b, FLOAT_TYPE Q, FLOAT_TYPE fc, |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
430 FLOAT_TYPE fs, FLOAT_TYPE *k, FLOAT_TYPE *coef) |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
431 { |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
432 FLOAT_TYPE at[3]; |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
433 FLOAT_TYPE bt[3]; |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
434 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28229
diff
changeset
|
435 if(!a || !b || !k || !coef || (Q>1000.0 || Q< 1.0)) |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
436 return -1; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
437 |
26350
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
438 memcpy(at,a,3*sizeof(FLOAT_TYPE)); |
07abe94a9cc4
Fix illegal identifier: Rename _ftype_t macro to FLOAT_TYPE.
diego
parents:
24890
diff
changeset
|
439 memcpy(bt,b,3*sizeof(FLOAT_TYPE)); |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
440 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
441 bt[1]/=Q; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
442 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
443 /* Calculate a and b and overwrite the original values */ |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14274
diff
changeset
|
444 af_filter_prewarp(at, fc, fs); |
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14274
diff
changeset
|
445 af_filter_prewarp(bt, fc, fs); |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
446 /* Execute bilinear transform */ |
14275
de13fd557440
less namespace pollution #2 (prefixed globals in filter.c with af_filter_)
alex
parents:
14274
diff
changeset
|
447 af_filter_bilinear(at, bt, k, fs, coef); |
8832
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
448 |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
449 return 0; |
a1578b329cc0
Adding sub-woofer filter, use this filter to add a sub channel to the audio stream
anders
parents:
7568
diff
changeset
|
450 } |