summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/filters.h
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/filters.h')
-rw-r--r--apps/plugins/pdbox/PDa/extra/filters.h148
1 files changed, 148 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/filters.h b/apps/plugins/pdbox/PDa/extra/filters.h
new file mode 100644
index 0000000000..72d997e425
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/filters.h
@@ -0,0 +1,148 @@
1/*
2
3 These filter coefficients computations are taken from
4 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
5
6 written by Robert Bristow-Johnson
7
8*/
9
10
11#ifndef __GGEE_FILTERS_H__
12#define __GGEE_FILTERS_H__
13
14
15
16#ifndef M_PI
17#define M_PI 3.141593f
18#endif
19
20
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)))
27
28
29
30
31typedef struct _rbjfilter
32{
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;
39
40
41static int check_stability(t_float fb1,
42 t_float fb2,
43 t_float ff1,
44 t_float ff2,
45 t_float ff3)
46{
47 float discriminant = fb1 * fb1 + 4 * fb2;
48
49 if (discriminant < 0) /* imaginary roots -- resonant filter */
50 {
51 /* they're conjugates so we just check that the product
52 is less than one */
53 if (fb2 >= -1.0f) goto stable;
54 }
55 else /* real roots */
56 {
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;
63 }
64 return 0;
65stable:
66 return 1;
67}
68
69
70
71
72
73
74#endif
75/*
76
77 These filter coefficients computations are taken from
78 http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt
79
80 written by Robert Bristow-Johnson
81
82*/
83
84
85#ifndef __GGEE_FILTERS_H__
86#define __GGEE_FILTERS_H__
87
88
89
90#ifndef M_PI
91#define M_PI 3.141593f
92#endif
93
94
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)))
101
102
103
104
105typedef struct _rbjfilter
106{
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;
113
114
115static int check_stability(t_float fb1,
116 t_float fb2,
117 t_float ff1,
118 t_float ff2,
119 t_float ff3)
120{
121 float discriminant = fb1 * fb1 + 4 * fb2;
122
123 if (discriminant < 0) /* imaginary roots -- resonant filter */
124 {
125 /* they're conjugates so we just check that the product
126 is less than one */
127 if (fb2 >= -1.0f) goto stable;
128 }
129 else /* real roots */
130 {
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;
137 }
138 return 0;
139stable:
140 return 1;
141}
142
143
144
145
146
147
148#endif