26 static void sigbp_docoef(t_sigbp
*x
, t_floatarg f
, t_floatarg q
);
28 static void *sigbp_new(t_floatarg f
, t_floatarg q
)
30 t_sigbp
*x
= (t_sigbp
*)pd_new(sigbp_class
);
31 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft1"));
32 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft2"));
33 outlet_new(&x
->x_obj
, gensym("signal"));
35 x
->x_ctl
= &x
->x_cspace
;
38 sigbp_docoef(x
, f
, q
);
43 static float sigbp_qcos(float f
)
45 if (f
>= -(0.5f
*3.14159f
) && f
<= 0.5f
*3.14159f
)
48 return (((g
*g
*g
* (-1.0f
/720.0f
) + g
*g
*(1.0f
/24.0f
)) - g
*0.5) + 1);
53 static void sigbp_docoef(t_sigbp
*x
, t_floatarg f
, t_floatarg q
)
55 float r
, oneminusr
, omega
;
56 if (f
< 0.001) f
= 10;
60 omega
= f
* (2.0f
* 3.14159f
) / x
->x_sr
;
61 if (q
< 0.001) oneminusr
= 1.0f
;
62 else oneminusr
= omega
/q
;
63 if (oneminusr
> 1.0f
) oneminusr
= 1.0f
;
65 x
->x_ctl
->c_coef1
= ftofix(2.0f
* sigbp_qcos(omega
) * r
);
66 x
->x_ctl
->c_coef2
= ftofix(- r
* r
);
67 x
->x_ctl
->c_gain
= ftofix(2 * oneminusr
* (oneminusr
+ r
* omega
));
68 /* post("r %f, omega %f, coef1 %f, coef2 %f",
69 r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
72 static void sigbp_ft1(t_sigbp
*x
, t_floatarg f
)
74 sigbp_docoef(x
, f
, x
->x_q
);
77 static void sigbp_ft2(t_sigbp
*x
, t_floatarg q
)
79 sigbp_docoef(x
, x
->x_freq
, q
);
82 static void sigbp_clear(t_sigbp
*x
, t_floatarg q
)
84 x
->x_ctl
->c_x1
= x
->x_ctl
->c_x2
= 0;
87 static t_int
*sigbp_perform(t_int
*w
)
89 t_sample
*in
= (t_sample
*)(w
[1]);
90 t_sample
*out
= (t_sample
*)(w
[2]);
91 t_bpctl
*c
= (t_bpctl
*)(w
[3]);
92 int n
= (t_int
)(w
[4]);
94 t_sample last
= c
->c_x1
;
95 t_sample prev
= c
->c_x2
;
96 t_sample coef1
= c
->c_coef1
;
97 t_sample coef2
= c
->c_coef2
;
98 t_sample gain
= c
->c_gain
;
99 for (i
= 0; i
< n
; i
++)
101 t_sample output
= *in
++ + mult(coef1
,last
) + mult(coef2
,prev
);
102 *out
++ = mult(gain
,output
);
106 if (PD_BADFLOAT(last
))
108 if (PD_BADFLOAT(prev
))
115 static void sigbp_dsp(t_sigbp
*x
, t_signal
**sp
)
117 x
->x_sr
= sp
[0]->s_sr
;
118 sigbp_docoef(x
, x
->x_freq
, x
->x_q
);
119 dsp_add(sigbp_perform
, 4,
120 sp
[0]->s_vec
, sp
[1]->s_vec
,
121 x
->x_ctl
, sp
[0]->s_n
);
125 void bp_tilde_setup(void)
127 sigbp_class
= class_new(gensym("bp~"), (t_newmethod
)sigbp_new
, 0,
128 sizeof(t_sigbp
), 0, A_DEFFLOAT
, A_DEFFLOAT
, 0);
129 CLASS_MAINSIGNALIN(sigbp_class
, t_sigbp
, x_f
);
130 class_addmethod(sigbp_class
, (t_method
)sigbp_dsp
, gensym("dsp"), 0);
131 class_addmethod(sigbp_class
, (t_method
)sigbp_ft1
,
132 gensym("ft1"), A_FLOAT
, 0);
133 class_addmethod(sigbp_class
, (t_method
)sigbp_ft2
,
134 gensym("ft2"), A_FLOAT
, 0);
135 class_addmethod(sigbp_class
, (t_method
)sigbp_clear
, gensym("clear"), 0);
136 class_sethelpsymbol(sigbp_class
, gensym("lop~-help.pd"));
162 t_class
*sigbp_class
;
164 static void sigbp_docoef(t_sigbp
*x
, t_floatarg f
, t_floatarg q
);
166 static void *sigbp_new(t_floatarg f
, t_floatarg q
)
168 t_sigbp
*x
= (t_sigbp
*)pd_new(sigbp_class
);
169 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft1"));
170 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft2"));
171 outlet_new(&x
->x_obj
, gensym("signal"));
173 x
->x_ctl
= &x
->x_cspace
;
174 x
->x_cspace
.c_x1
= 0;
175 x
->x_cspace
.c_x2
= 0;
176 sigbp_docoef(x
, f
, q
);
181 static float sigbp_qcos(float f
)
183 if (f
>= -(0.5f
*3.14159f
) && f
<= 0.5f
*3.14159f
)
186 return (((g
*g
*g
* (-1.0f
/720.0f
) + g
*g
*(1.0f
/24.0f
)) - g
*0.5) + 1);
191 static void sigbp_docoef(t_sigbp
*x
, t_floatarg f
, t_floatarg q
)
193 float r
, oneminusr
, omega
;
194 if (f
< 0.001) f
= 10;
198 omega
= f
* (2.0f
* 3.14159f
) / x
->x_sr
;
199 if (q
< 0.001) oneminusr
= 1.0f
;
200 else oneminusr
= omega
/q
;
201 if (oneminusr
> 1.0f
) oneminusr
= 1.0f
;
202 r
= 1.0f
- oneminusr
;
203 x
->x_ctl
->c_coef1
= ftofix(2.0f
* sigbp_qcos(omega
) * r
);
204 x
->x_ctl
->c_coef2
= ftofix(- r
* r
);
205 x
->x_ctl
->c_gain
= ftofix(2 * oneminusr
* (oneminusr
+ r
* omega
));
206 /* post("r %f, omega %f, coef1 %f, coef2 %f",
207 r, omega, x->x_ctl->c_coef1, x->x_ctl->c_coef2); */
210 static void sigbp_ft1(t_sigbp
*x
, t_floatarg f
)
212 sigbp_docoef(x
, f
, x
->x_q
);
215 static void sigbp_ft2(t_sigbp
*x
, t_floatarg q
)
217 sigbp_docoef(x
, x
->x_freq
, q
);
220 static void sigbp_clear(t_sigbp
*x
, t_floatarg q
)
222 x
->x_ctl
->c_x1
= x
->x_ctl
->c_x2
= 0;
225 static t_int
*sigbp_perform(t_int
*w
)
227 t_sample
*in
= (t_sample
*)(w
[1]);
228 t_sample
*out
= (t_sample
*)(w
[2]);
229 t_bpctl
*c
= (t_bpctl
*)(w
[3]);
230 int n
= (t_int
)(w
[4]);
232 t_sample last
= c
->c_x1
;
233 t_sample prev
= c
->c_x2
;
234 t_sample coef1
= c
->c_coef1
;
235 t_sample coef2
= c
->c_coef2
;
236 t_sample gain
= c
->c_gain
;
237 for (i
= 0; i
< n
; i
++)
239 t_sample output
= *in
++ + mult(coef1
,last
) + mult(coef2
,prev
);
240 *out
++ = mult(gain
,output
);
244 if (PD_BADFLOAT(last
))
246 if (PD_BADFLOAT(prev
))
253 static void sigbp_dsp(t_sigbp
*x
, t_signal
**sp
)
255 x
->x_sr
= sp
[0]->s_sr
;
256 sigbp_docoef(x
, x
->x_freq
, x
->x_q
);
257 dsp_add(sigbp_perform
, 4,
258 sp
[0]->s_vec
, sp
[1]->s_vec
,
259 x
->x_ctl
, sp
[0]->s_n
);
263 void bp_tilde_setup(void)
265 sigbp_class
= class_new(gensym("bp~"), (t_newmethod
)sigbp_new
, 0,
266 sizeof(t_sigbp
), 0, A_DEFFLOAT
, A_DEFFLOAT
, 0);
267 CLASS_MAINSIGNALIN(sigbp_class
, t_sigbp
, x_f
);
268 class_addmethod(sigbp_class
, (t_method
)sigbp_dsp
, gensym("dsp"), 0);
269 class_addmethod(sigbp_class
, (t_method
)sigbp_ft1
,
270 gensym("ft1"), A_FLOAT
, 0);
271 class_addmethod(sigbp_class
, (t_method
)sigbp_ft2
,
272 gensym("ft2"), A_FLOAT
, 0);
273 class_addmethod(sigbp_class
, (t_method
)sigbp_clear
, gensym("clear"), 0);
274 class_sethelpsymbol(sigbp_class
, gensym("lop~-help.pd"));