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"));
30 x
->x_ctl
= &x
->x_cspace
;
37 static void siglop_ft1(t_siglop
*x
, t_floatarg f
)
40 if (f
< 0.001) f
= 10;
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
)
53 static t_int
*siglop_perform(t_int
*w
)
55 t_sample
*in
= (t_sample
*)(w
[1]);
56 t_sample
*out
= (t_sample
*)(w
[2]);
57 t_lopctl
*c
= (t_lopctl
*)(w
[3]);
58 int n
= (t_int
)(w
[4]);
60 t_sample last
= c
->c_x
;
61 t_sample coef
= c
->c_coef
;
62 t_sample feedback
= ftofix(1) - coef
;
63 for (i
= 0; i
< n
; i
++)
64 last
= *out
++ = mult(coef
, *in
++) + mult(feedback
,last
);
65 if (PD_BADFLOAT(last
))
71 static void siglop_dsp(t_siglop
*x
, t_signal
**sp
)
73 x
->x_sr
= sp
[0]->s_sr
;
74 siglop_ft1(x
, x
->x_hz
);
75 dsp_add(siglop_perform
, 4,
76 sp
[0]->s_vec
, sp
[1]->s_vec
,
77 x
->x_ctl
, sp
[0]->s_n
);
81 void lop_tilde_setup(void)
83 siglop_class
= class_new(gensym("lop~"), (t_newmethod
)siglop_new
, 0,
84 sizeof(t_siglop
), 0, A_DEFFLOAT
, 0);
85 CLASS_MAINSIGNALIN(siglop_class
, t_siglop
, x_f
);
86 class_addmethod(siglop_class
, (t_method
)siglop_dsp
, gensym("dsp"), 0);
87 class_addmethod(siglop_class
, (t_method
)siglop_ft1
,
88 gensym("ft1"), A_FLOAT
, 0);
89 class_addmethod(siglop_class
, (t_method
)siglop_clear
, gensym("clear"), 0);
100 typedef struct siglop
110 t_class
*siglop_class
;
112 static void siglop_ft1(t_siglop
*x
, t_floatarg f
);
114 static void *siglop_new(t_floatarg f
)
116 t_siglop
*x
= (t_siglop
*)pd_new(siglop_class
);
117 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft1"));
118 outlet_new(&x
->x_obj
, gensym("signal"));
120 x
->x_ctl
= &x
->x_cspace
;
127 static void siglop_ft1(t_siglop
*x
, t_floatarg f
)
130 if (f
< 0.001) f
= 10;
132 coeff
= f
* (2 * 3.14159) / x
->x_sr
;
133 if (coeff
> 1) coeff
= 1;
134 x
->x_ctl
->c_coef
= ftofix(coeff
);
137 static void siglop_clear(t_siglop
*x
, t_floatarg q
)
143 static t_int
*siglop_perform(t_int
*w
)
145 t_sample
*in
= (t_sample
*)(w
[1]);
146 t_sample
*out
= (t_sample
*)(w
[2]);
147 t_lopctl
*c
= (t_lopctl
*)(w
[3]);
148 int n
= (t_int
)(w
[4]);
150 t_sample last
= c
->c_x
;
151 t_sample coef
= c
->c_coef
;
152 t_sample feedback
= ftofix(1) - coef
;
153 for (i
= 0; i
< n
; i
++)
154 last
= *out
++ = mult(coef
, *in
++) + mult(feedback
,last
);
155 if (PD_BADFLOAT(last
))
161 static void siglop_dsp(t_siglop
*x
, t_signal
**sp
)
163 x
->x_sr
= sp
[0]->s_sr
;
164 siglop_ft1(x
, x
->x_hz
);
165 dsp_add(siglop_perform
, 4,
166 sp
[0]->s_vec
, sp
[1]->s_vec
,
167 x
->x_ctl
, sp
[0]->s_n
);
171 void lop_tilde_setup(void)
173 siglop_class
= class_new(gensym("lop~"), (t_newmethod
)siglop_new
, 0,
174 sizeof(t_siglop
), 0, A_DEFFLOAT
, 0);
175 CLASS_MAINSIGNALIN(siglop_class
, t_siglop
, x_f
);
176 class_addmethod(siglop_class
, (t_method
)siglop_dsp
, gensym("dsp"), 0);
177 class_addmethod(siglop_class
, (t_method
)siglop_ft1
,
178 gensym("ft1"), A_FLOAT
, 0);
179 class_addmethod(siglop_class
, (t_method
)siglop_clear
, gensym("clear"), 0);