diff options
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/lowshelf.c')
-rw-r--r-- | apps/plugins/pdbox/PDa/extra/lowshelf.c | 93 |
1 files changed, 1 insertions, 92 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/lowshelf.c b/apps/plugins/pdbox/PDa/extra/lowshelf.c index 52c30d839d..ba32b6dba8 100644 --- a/apps/plugins/pdbox/PDa/extra/lowshelf.c +++ b/apps/plugins/pdbox/PDa/extra/lowshelf.c | |||
@@ -88,95 +88,4 @@ void lowshelf_setup(void) | |||
88 | class_addfloat(lowshelf_class,lowshelf_float); | 88 | class_addfloat(lowshelf_class,lowshelf_float); |
89 | } | 89 | } |
90 | 90 | ||
91 | 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 | |||