diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/lowshelf.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/lowshelf.c | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/lowshelf.c b/apps/plugins/pdbox/PDa/extra/lowshelf.c new file mode 100644 index 0000000000..52c30d839d --- /dev/null +++ b/apps/plugins/pdbox/PDa/extra/lowshelf.c | |||
@@ -0,0 +1,182 @@ | |||
1 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | ||
2 | |||
3 | |||
4 | /* | ||
5 | |||
6 | These filter coefficients computations are taken from | ||
7 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | ||
8 | |||
9 | written by Robert Bristow-Johnson | ||
10 | |||
11 | */ | ||
12 | |||
13 | #include "m_pd.h" | ||
14 | #ifdef NT | ||
15 | #pragma warning( disable : 4244 ) | ||
16 | #pragma warning( disable : 4305 ) | ||
17 | #endif | ||
18 | #include <math.h> | ||
19 | #include "filters.h" | ||
20 | |||
21 | |||
22 | |||
23 | /* ------------------- lowshelf ----------------------------*/ | ||
24 | |||
25 | static t_class *lowshelf_class; | ||
26 | |||
27 | void lowshelf_bang(t_rbjfilter *x) | ||
28 | { | ||
29 | t_atom at[5]; | ||
30 | t_float omega = e_omega(x->x_freq,x->x_rate); | ||
31 | t_float A = e_A(x->x_gain); | ||
32 | t_float cs = cos(omega); | ||
33 | t_float sn = sin(omega); | ||
34 | t_float beta = e_beta(A,x->x_bw*0.01); | ||
35 | |||
36 | t_float b0 = A*((A+1) - (A-1)*cs + beta*sn); | ||
37 | t_float b1 = 2.*A*((A-1) - (A+1)*cs); | ||
38 | t_float b2 = A*((A+1) - (A-1)*cs - beta*sn); | ||
39 | t_float a0 = ((A+1) + (A-1)*cs + beta*sn); | ||
40 | t_float a1 = -2.*((A-1) + (A+1)*cs); | ||
41 | t_float a2 = ((A+1) + (A-1)*cs - beta*sn); | ||
42 | |||
43 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ | ||
44 | |||
45 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | ||
46 | post("lowshelf: filter unstable -> resetting"); | ||
47 | a0=1.;a1=0.;a2=0.; | ||
48 | b0=1.;b1=0.;b2=0.; | ||
49 | } | ||
50 | |||
51 | SETFLOAT(at,-a1/a0); | ||
52 | SETFLOAT(at+1,-a2/a0); | ||
53 | SETFLOAT(at+2,b0/a0); | ||
54 | SETFLOAT(at+3,b1/a0); | ||
55 | SETFLOAT(at+4,b2/a0); | ||
56 | |||
57 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | ||
58 | } | ||
59 | |||
60 | |||
61 | void lowshelf_float(t_rbjfilter *x,t_floatarg f) | ||
62 | { | ||
63 | x->x_freq = f; | ||
64 | lowshelf_bang(x); | ||
65 | } | ||
66 | |||
67 | |||
68 | static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) | ||
69 | { | ||
70 | t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class); | ||
71 | |||
72 | x->x_rate = 44100.0; | ||
73 | outlet_new(&x->x_obj,&s_float); | ||
74 | floatinlet_new(&x->x_obj, &x->x_gain); | ||
75 | floatinlet_new(&x->x_obj, &x->x_bw); | ||
76 | if (f > 0.) x->x_freq = f; | ||
77 | if (bw > 0.) x->x_bw = bw; | ||
78 | if (g != 0.) x->x_gain = g; | ||
79 | return (x); | ||
80 | } | ||
81 | |||
82 | |||
83 | void lowshelf_setup(void) | ||
84 | { | ||
85 | lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0, | ||
86 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); | ||
87 | class_addbang(lowshelf_class,lowshelf_bang); | ||
88 | class_addfloat(lowshelf_class,lowshelf_float); | ||
89 | } | ||
90 | |||
91 | |||
92 | /* (C) Guenter Geiger <geiger@epy.co.at> */ | ||
93 | |||
94 | |||
95 | /* | ||
96 | |||
97 | These filter coefficients computations are taken from | ||
98 | http://www.harmony-central.com/Computer/Programming/Audio-EQ-Cookbook.txt | ||
99 | |||
100 | written by Robert Bristow-Johnson | ||
101 | |||
102 | */ | ||
103 | |||
104 | #include "m_pd.h" | ||
105 | #ifdef NT | ||
106 | #pragma warning( disable : 4244 ) | ||
107 | #pragma warning( disable : 4305 ) | ||
108 | #endif | ||
109 | #include <math.h> | ||
110 | #include "filters.h" | ||
111 | |||
112 | |||
113 | |||
114 | /* ------------------- lowshelf ----------------------------*/ | ||
115 | |||
116 | static t_class *lowshelf_class; | ||
117 | |||
118 | void lowshelf_bang(t_rbjfilter *x) | ||
119 | { | ||
120 | t_atom at[5]; | ||
121 | t_float omega = e_omega(x->x_freq,x->x_rate); | ||
122 | t_float A = e_A(x->x_gain); | ||
123 | t_float cs = cos(omega); | ||
124 | t_float sn = sin(omega); | ||
125 | t_float beta = e_beta(A,x->x_bw*0.01); | ||
126 | |||
127 | t_float b0 = A*((A+1) - (A-1)*cs + beta*sn); | ||
128 | t_float b1 = 2.*A*((A-1) - (A+1)*cs); | ||
129 | t_float b2 = A*((A+1) - (A-1)*cs - beta*sn); | ||
130 | t_float a0 = ((A+1) + (A-1)*cs + beta*sn); | ||
131 | t_float a1 = -2.*((A-1) + (A+1)*cs); | ||
132 | t_float a2 = ((A+1) + (A-1)*cs - beta*sn); | ||
133 | |||
134 | /* post("bang %f %f %f",x->x_freq, x->x_gain, x->x_bw); */ | ||
135 | |||
136 | if (!check_stability(-a1/a0,-a2/a0,b0/a0,b1/a0,b2/a0)) { | ||
137 | post("lowshelf: filter unstable -> resetting"); | ||
138 | a0=1.;a1=0.;a2=0.; | ||
139 | b0=1.;b1=0.;b2=0.; | ||
140 | } | ||
141 | |||
142 | SETFLOAT(at,-a1/a0); | ||
143 | SETFLOAT(at+1,-a2/a0); | ||
144 | SETFLOAT(at+2,b0/a0); | ||
145 | SETFLOAT(at+3,b1/a0); | ||
146 | SETFLOAT(at+4,b2/a0); | ||
147 | |||
148 | outlet_list(x->x_obj.ob_outlet,&s_list,5,at); | ||
149 | } | ||
150 | |||
151 | |||
152 | void lowshelf_float(t_rbjfilter *x,t_floatarg f) | ||
153 | { | ||
154 | x->x_freq = f; | ||
155 | lowshelf_bang(x); | ||
156 | } | ||
157 | |||
158 | |||
159 | static void *lowshelf_new(t_floatarg f,t_floatarg g,t_floatarg bw) | ||
160 | { | ||
161 | t_rbjfilter *x = (t_rbjfilter *)pd_new(lowshelf_class); | ||
162 | |||
163 | x->x_rate = 44100.0; | ||
164 | outlet_new(&x->x_obj,&s_float); | ||
165 | floatinlet_new(&x->x_obj, &x->x_gain); | ||
166 | floatinlet_new(&x->x_obj, &x->x_bw); | ||
167 | if (f > 0.) x->x_freq = f; | ||
168 | if (bw > 0.) x->x_bw = bw; | ||
169 | if (g != 0.) x->x_gain = g; | ||
170 | return (x); | ||
171 | } | ||
172 | |||
173 | |||
174 | void lowshelf_setup(void) | ||
175 | { | ||
176 | lowshelf_class = class_new(gensym("lowshelf"), (t_newmethod)lowshelf_new, 0, | ||
177 | sizeof(t_rbjfilter), 0,A_DEFFLOAT,A_DEFFLOAT,A_DEFFLOAT,0); | ||
178 | class_addbang(lowshelf_class,lowshelf_bang); | ||
179 | class_addfloat(lowshelf_class,lowshelf_float); | ||
180 | } | ||
181 | |||
182 | |||