diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/filters.h')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/filters.h | 155 |
1 files changed, 81 insertions, 74 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/filters.h b/apps/plugins/pdbox/PDa/extra/filters.h index 8a91f75073..2eaf2b09f9 100644 --- a/apps/plugins/pdbox/PDa/extra/filters.h +++ b/apps/plugins/pdbox/PDa/extra/filters.h | |||
@@ -1,75 +1,82 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | These filter coefficients computations are taken from | 3 | These filter coefficients computations are taken from |
4 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | 4 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt |
5 | 5 | ||
6 | written by Robert Bristow-Johnson | 6 | written by Robert Bristow-Johnson |
7 | 7 | ||
8 | */ | 8 | */ |
9 | 9 | ||
10 | 10 | ||
11 | #ifndef __GGEE_FILTERS_H__ | 11 | #ifndef __GGEE_FILTERS_H__ |
12 | #define __GGEE_FILTERS_H__ | 12 | #define __GGEE_FILTERS_H__ |
13 | 13 | ||
14 | 14 | #ifdef ROCKBOX | |
15 | 15 | #include "math.h" | |
16 | #ifndef M_PI | 16 | #else |
17 | #define M_PI 3.141593f | 17 | #include <math.h> |
18 | #endif | 18 | #endif |
19 | 19 | ||
20 | 20 | #ifndef M_PI | |
21 | #include <math.h> | 21 | #define M_PI 3.141593f |
22 | #define LN2 0.69314718 | 22 | #endif |
23 | #define e_A(g) (pow(10,(g/40.))) | 23 | |
24 | #define e_omega(f,r) (2.0*M_PI*f/r) | 24 | #define LN2 0.69314718 |
25 | #define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega))) | 25 | #define e_A(g) (pow(10,(g/40.))) |
26 | #define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1))) | 26 | #define e_omega(f,r) (2.0*M_PI*f/r) |
27 | 27 | #define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega))) | |
28 | 28 | #define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1))) | |
29 | 29 | ||
30 | 30 | ||
31 | typedef struct _rbjfilter | 31 | |
32 | { | 32 | |
33 | t_object x_obj; | 33 | typedef struct _rbjfilter |
34 | t_float x_rate; | 34 | { |
35 | t_float x_freq; | 35 | t_object x_obj; |
36 | t_float x_gain; | 36 | t_float x_rate; |
37 | t_float x_bw; | 37 | t_float x_freq; |
38 | } t_rbjfilter; | 38 | t_float x_gain; |
39 | 39 | t_float x_bw; | |
40 | 40 | } t_rbjfilter; | |
41 | static int check_stability(t_float fb1, | 41 | |
42 | t_float fb2, | 42 | |
43 | t_float ff1, | 43 | static int check_stability(t_float fb1, |
44 | t_float ff2, | 44 | t_float fb2, |
45 | t_float ff3) | 45 | t_float ff1, |
46 | { | 46 | t_float ff2, |
47 | float discriminant = fb1 * fb1 + 4 * fb2; | 47 | t_float ff3) |
48 | 48 | { | |
49 | if (discriminant < 0) /* imaginary roots -- resonant filter */ | 49 | #ifdef ROCKBOX |
50 | { | 50 | (void) ff1; |
51 | /* they're conjugates so we just check that the product | 51 | (void) ff2; |
52 | is less than one */ | 52 | (void) ff3; |
53 | if (fb2 >= -1.0f) goto stable; | 53 | #endif |
54 | } | 54 | float discriminant = fb1 * fb1 + 4 * fb2; |
55 | else /* real roots */ | 55 | |
56 | { | 56 | if (discriminant < 0) /* imaginary roots -- resonant filter */ |
57 | /* check that the parabola 1 - fb1 x - fb2 x^2 has a | 57 | { |
58 | vertex between -1 and 1, and that it's nonnegative | 58 | /* they're conjugates so we just check that the product |
59 | at both ends, which implies both roots are in [1-,1]. */ | 59 | is less than one */ |
60 | if (fb1 <= 2.0f && fb1 >= -2.0f && | 60 | if (fb2 >= -1.0f) goto stable; |
61 | 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0) | 61 | } |
62 | goto stable; | 62 | else /* real roots */ |
63 | } | 63 | { |
64 | return 0; | 64 | /* check that the parabola 1 - fb1 x - fb2 x^2 has a |
65 | stable: | 65 | vertex between -1 and 1, and that it's nonnegative |
66 | return 1; | 66 | at both ends, which implies both roots are in [1-,1]. */ |
67 | } | 67 | if (fb1 <= 2.0f && fb1 >= -2.0f && |
68 | 68 | 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0) | |
69 | 69 | goto stable; | |
70 | 70 | } | |
71 | 71 | return 0; | |
72 | 72 | stable: | |
73 | 73 | return 1; | |
74 | #endif | 74 | } |
75 | |||
76 | |||
77 | |||
78 | |||
79 | |||
80 | |||
81 | #endif | ||
75 | 82 | ||