Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / lop~.c
blob3443d7fdafd33efcaf22ae32a7ebf87d66a3c697
1 #include "../src/m_pd.h"
2 #include <../src/m_fixed.h>
4 typedef struct lopctl
6 t_sample c_x;
7 t_sample c_coef;
8 } t_lopctl;
10 typedef struct siglop
12 t_object x_obj;
13 float x_sr;
14 float x_hz;
15 t_lopctl x_cspace;
16 t_lopctl *x_ctl;
17 float x_f;
18 } t_siglop;
20 t_class *siglop_class;
22 static void siglop_ft1(t_siglop *x, t_floatarg f);
24 static void *siglop_new(t_floatarg f)
26 t_siglop *x = (t_siglop *)pd_new(siglop_class);
27 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
28 outlet_new(&x->x_obj, gensym("signal"));
29 x->x_sr = 44100;
30 x->x_ctl = &x->x_cspace;
31 x->x_cspace.c_x = 0;
32 siglop_ft1(x, f);
33 x->x_f = 0;
34 return (x);
37 static void siglop_ft1(t_siglop *x, t_floatarg f)
39 t_float coeff;
40 if (f < 0.001) f = 10;
41 x->x_hz = f;
42 coeff = f * (2 * 3.14159) / x->x_sr;
43 if (coeff > 1) coeff = 1;
44 x->x_ctl->c_coef = ftofix(coeff);
47 static void siglop_clear(t_siglop *x, t_floatarg q)
49 #ifdef ROCKBOX
50 (void) q;
51 #endif
52 x->x_cspace.c_x = 0;
56 static t_int *siglop_perform(t_int *w)
58 t_sample *in = (t_sample *)(w[1]);
59 t_sample *out = (t_sample *)(w[2]);
60 t_lopctl *c = (t_lopctl *)(w[3]);
61 int n = (t_int)(w[4]);
62 int i;
63 t_sample last = c->c_x;
64 t_sample coef = c->c_coef;
65 t_sample feedback = ftofix(1) - coef;
66 for (i = 0; i < n; i++)
67 last = *out++ = mult(coef, *in++) + mult(feedback,last);
68 if (PD_BADFLOAT(last))
69 last = 0;
70 c->c_x = last;
71 return (w+5);
74 static void siglop_dsp(t_siglop *x, t_signal **sp)
76 x->x_sr = sp[0]->s_sr;
77 siglop_ft1(x, x->x_hz);
78 dsp_add(siglop_perform, 4,
79 sp[0]->s_vec, sp[1]->s_vec,
80 x->x_ctl, sp[0]->s_n);
84 void lop_tilde_setup(void)
86 siglop_class = class_new(gensym("lop~"), (t_newmethod)siglop_new, 0,
87 sizeof(t_siglop), 0, A_DEFFLOAT, 0);
88 CLASS_MAINSIGNALIN(siglop_class, t_siglop, x_f);
89 class_addmethod(siglop_class, (t_method)siglop_dsp, gensym("dsp"), 0);
90 class_addmethod(siglop_class, (t_method)siglop_ft1,
91 gensym("ft1"), A_FLOAT, 0);
92 class_addmethod(siglop_class, (t_method)siglop_clear, gensym("clear"), 0);