Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin...
[kugel-rb.git] / apps / plugins / pdbox / PDa / extra / filters.h
blob72d997e4258191c529d13011dd9c346165d54ad7
1 /*
3 These filter coefficients computations are taken from
4 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
6 written by Robert Bristow-Johnson
8 */
11 #ifndef __GGEE_FILTERS_H__
12 #define __GGEE_FILTERS_H__
16 #ifndef M_PI
17 #define M_PI 3.141593f
18 #endif
21 #include <math.h>
22 #define LN2 0.69314718
23 #define e_A(g) (pow(10,(g/40.)))
24 #define e_omega(f,r) (2.0*M_PI*f/r)
25 #define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega)))
26 #define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1)))
31 typedef struct _rbjfilter
33 t_object x_obj;
34 t_float x_rate;
35 t_float x_freq;
36 t_float x_gain;
37 t_float x_bw;
38 } t_rbjfilter;
41 static int check_stability(t_float fb1,
42 t_float fb2,
43 t_float ff1,
44 t_float ff2,
45 t_float ff3)
47 float discriminant = fb1 * fb1 + 4 * fb2;
49 if (discriminant < 0) /* imaginary roots -- resonant filter */
51 /* they're conjugates so we just check that the product
52 is less than one */
53 if (fb2 >= -1.0f) goto stable;
55 else /* real roots */
57 /* check that the parabola 1 - fb1 x - fb2 x^2 has a
58 vertex between -1 and 1, and that it's nonnegative
59 at both ends, which implies both roots are in [1-,1]. */
60 if (fb1 <= 2.0f && fb1 >= -2.0f &&
61 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
62 goto stable;
64 return 0;
65 stable:
66 return 1;
74 #endif
77 These filter coefficients computations are taken from
78 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
80 written by Robert Bristow-Johnson
85 #ifndef __GGEE_FILTERS_H__
86 #define __GGEE_FILTERS_H__
90 #ifndef M_PI
91 #define M_PI 3.141593f
92 #endif
95 #include <math.h>
96 #define LN2 0.69314718
97 #define e_A(g) (pow(10,(g/40.)))
98 #define e_omega(f,r) (2.0*M_PI*f/r)
99 #define e_alpha(bw,omega) (sin(omega)*sinh(LN2/2. * bw * omega/sin(omega)))
100 #define e_beta(a,S) (sqrt((a*a + 1)/(S) - (a-1)*(a-1)))
105 typedef struct _rbjfilter
107 t_object x_obj;
108 t_float x_rate;
109 t_float x_freq;
110 t_float x_gain;
111 t_float x_bw;
112 } t_rbjfilter;
115 static int check_stability(t_float fb1,
116 t_float fb2,
117 t_float ff1,
118 t_float ff2,
119 t_float ff3)
121 float discriminant = fb1 * fb1 + 4 * fb2;
123 if (discriminant < 0) /* imaginary roots -- resonant filter */
125 /* they're conjugates so we just check that the product
126 is less than one */
127 if (fb2 >= -1.0f) goto stable;
129 else /* real roots */
131 /* check that the parabola 1 - fb1 x - fb2 x^2 has a
132 vertex between -1 and 1, and that it's nonnegative
133 at both ends, which implies both roots are in [1-,1]. */
134 if (fb1 <= 2.0f && fb1 >= -2.0f &&
135 1.0f - fb1 -fb2 >= 0 && 1.0f + fb1 - fb2 >= 0)
136 goto stable;
138 return 0;
139 stable:
140 return 1;
148 #endif