summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/moog~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/moog~.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/moog~.c184
1 files changed, 1 insertions, 183 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/moog~.c b/apps/plugins/pdbox/PDa/extra/moog~.c
index ee7acc99aa..48d4dfe932 100644
--- a/apps/plugins/pdbox/PDa/extra/moog~.c
+++ b/apps/plugins/pdbox/PDa/extra/moog~.c
@@ -181,186 +181,4 @@ void moog_tilde_setup(void)
181 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0); 181 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
182 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL); 182 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
183} 183}
184/* (C) Guenter Geiger <geiger@epy.co.at> */ 184
185
186
187#include "math.h"
188#include <m_pd.h>
189
190/* ----------------------------- moog ----------------------------- */
191static t_class *moog_class;
192
193
194typedef struct _moog
195{
196 t_object x_obj;
197 t_pd in2;
198 t_sample x_1,x_2,x_3,x_4;
199 t_sample y_1,y_2,y_3,y_4;
200} t_moog;
201
202static void moog_reset(t_moog *x)
203{
204 x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
205 x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
206
207}
208
209
210
211static void *moog_new(t_symbol *s, int argc, t_atom *argv)
212{
213 if (argc > 1) post("moog~: extra arguments ignored");
214 {
215 t_moog *x = (t_moog *)pd_new(moog_class);
216 outlet_new(&x->x_obj, &s_signal);
217 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
218 inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
219 moog_reset(x);
220 return (x);
221 }
222
223
224}
225
226
227
228static t_sample calc_k(t_sample f,t_sample k) {
229 if (k>itofix(4)) k = itofix(4);
230 if (k < 0) k = 0;
231 if (f <= itofix(3800)) return k;
232 k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
233 return k;
234}
235
236t_int *moog_perform(t_int *w)
237{
238 t_moog* x = (t_moog*) (w[1]);
239 t_sample *in1 = (t_sample *)(w[2]);
240 t_sample *p = (t_sample *)(w[3]);
241 t_sample *k = (t_sample *)(w[4]);
242
243 t_sample *out = (t_sample *)(w[5]);
244 int n = (int)(w[6]);
245 t_sample in;
246 t_sample pt,pt1;
247
248 t_sample x1 = x->x_1;
249 t_sample x2 = x->x_2;
250 t_sample x3 = x->x_3;
251 t_sample x4 = x->x_4;
252 t_sample ys1 = x->y_1;
253 t_sample ys2 = x->y_2;
254 t_sample ys3 = x->y_3;
255 t_sample ys4 = x->y_4;
256
257
258 while (n--) {
259 if (*p > itofix(8140)) *p = itofix(8140);
260 *k = calc_k(*p,*k);
261 pt =*p;
262 pt1=mult((pt+1),ftofix(0.76923077));
263 in = *in1++ - mult(*k,ys4);
264 ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
265 x1 = in;
266 ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
267 x2 = ys1;
268 ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
269 x3 = ys2;
270 ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
271 x4 = ys3;
272 *out++ = ys4;
273 }
274
275
276 x->y_1 = ys1;
277 x->y_2 = ys2;
278 x->y_3 = ys3;
279 x->y_4 = ys4;
280 x->x_1 = x1;
281 x->x_2 = x2;
282 x->x_3 = x3;
283 x->x_4 = x4;
284
285 return (w+7);
286}
287
288
289#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
290
291t_int *moog_perf8(t_int *w)
292{
293 t_moog* x = (t_moog*) (w[1]);
294 t_sample *in1 = (t_sample *)(w[2]);
295 t_sample *p = (t_sample *)(w[3]);
296 t_sample *k = (t_sample *)(w[4]);
297 t_sample *out = (t_sample *)(w[5]);
298 int n = (int)(w[6]);
299
300 t_sample x1 = x->x_1;
301 t_sample x2 = x->x_2;
302 t_sample x3 = x->x_3;
303 t_sample x4 = x->x_4;
304 t_sample ys1 = x->y_1;
305 t_sample ys2 = x->y_2;
306 t_sample ys3 = x->y_3;
307 t_sample ys4 = x->y_4;
308
309 t_sample temp,temp2;
310 t_sample pt,pt1;
311 t_sample in;
312
313 while (n--) {
314 if (*p > itofix(8140)) *p = itofix(8140);
315 *k = calc_k(*p,*k);
316
317 pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
318 pt1=mult((pt+itofix(1)),ftofix(0.76923077));
319 in = *in1++ - mult(*k,ys4);
320 ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
321 x1 = in;
322 ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
323 x2 = ys1;
324 ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
325 x3 = ys2;
326 ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
327 x4 = ys3;
328 *out++ = ys4;
329
330 p++;k++;
331 }
332
333 x->y_1 = ys1;
334 x->y_2 = ys2;
335 x->y_3 = ys3;
336 x->y_4 = ys4;
337 x->x_1 = x1;
338 x->x_2 = x2;
339 x->x_3 = x3;
340 x->x_4 = x4;
341
342 return (w+7);
343}
344
345void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
346{
347 if (n&7)
348 dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
349 else
350 dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
351}
352
353static void moog_dsp(t_moog *x, t_signal **sp)
354{
355 dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
356}
357
358
359void moog_tilde_setup(void)
360{
361 moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
362 sizeof(t_moog), 0, A_GIMME, 0);
363 class_addmethod(moog_class, nullfn, gensym("signal"), 0);
364 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
365 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
366}