1 #include "../src/m_pd.h"
2 #include <../src/m_fixed.h>
5 /* ---------------- vcf~ - 2-pole bandpass filter. ----------------- */
6 /* GG: complex resonator with signal frequency control
7 this time using the bigger cos_table without interpolation
8 really have to switch to a separate fixpoint format sometime
27 t_class
*sigvcf_class
;
29 static void *sigvcf_new(t_floatarg q
)
31 t_sigvcf
*x
= (t_sigvcf
*)pd_new(sigvcf_class
);
32 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, &s_signal
, &s_signal
);
33 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, gensym("float"), gensym("ft1"));
34 outlet_new(&x
->x_obj
, gensym("signal"));
35 outlet_new(&x
->x_obj
, gensym("signal"));
36 x
->x_ctl
= &x
->x_cspace
;
39 x
->x_cspace
.c_q
= ftofix(q
);
40 x
->x_cspace
.c_isr
= 0;
45 static void sigvcf_ft1(t_sigvcf
*x
, t_floatarg f
)
47 x
->x_ctl
->c_q
= (f
> 0 ? ftofix(f
) : 0);
50 static t_int
*sigvcf_perform(t_int
*w
)
52 t_sample
*in1
= (t_sample
*)(w
[1]);
53 t_sample
*in2
= (t_sample
*)(w
[2]);
54 t_sample
*out1
= (t_sample
*)(w
[3]);
55 t_sample
*out2
= (t_sample
*)(w
[4]);
56 t_vcfctl
*c
= (t_vcfctl
*)(w
[5]);
57 int n
= (t_int
)(w
[6]);
59 t_sample re
= c
->c_re
, re2
;
60 t_sample im
= c
->c_im
;
62 t_sample qinv
= (q
> 0 ? idiv(ftofix(1.0),q
) : 0);
63 t_sample ampcorrect
= ftofix(2.0f
) - idiv(ftofix(2.0f
) , (q
+ ftofix(2.0f
)));
64 t_sample isr
= c
->c_isr
;
65 t_sample coefr
, coefi
;
66 t_sample
*tab
= cos_table
;
67 t_sample oneminusr
,cfindx
,cf
,r
;
69 for (i
= 0; i
< n
; i
++)
71 cf
= mult(*in2
++,isr
);
73 cfindx
= mult(cf
,ftofix(0.15915494))>>(fix1
-ILOGCOSTABSIZE
); /* 1/2*PI */
74 r
= (qinv
> 0 ? ftofix(1.01) - mult(cf
,qinv
) : 0);
77 oneminusr
= ftofix(1.02f
) - r
; /* hand adapted */
80 coefr
= mult(r
,tab
[cfindx
]);
83 cfindx
-=(ICOSTABSIZE
>>2);
84 cfindx
+= cfindx
< 0 ? ICOSTABSIZE
:0;
85 coefi
= mult(r
,tab
[cfindx
]);
88 *out1
++ = re
= mult(ampcorrect
,mult(oneminusr
,*in1
++))
89 + mult(coefr
,re2
) - mult(coefi
, im
);
90 *out2
++ = im
= mult(coefi
,re2
) + mult(coefr
,im
);
97 static void sigvcf_dsp(t_sigvcf
*x
, t_signal
**sp
)
99 /* TODO sr is hardcoded */
100 x
->x_ctl
->c_isr
= ftofix(0.0001424758);
101 // idiv(ftofix(6.28318),ftofix(sp[0]->s_sr));
102 post("%f",fixtof(x
->x_ctl
->c_isr
));
103 dsp_add(sigvcf_perform
, 6,
104 sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[2]->s_vec
, sp
[3]->s_vec
,
105 x
->x_ctl
, sp
[0]->s_n
);
109 void vcf_tilde_setup(void)
111 sigvcf_class
= class_new(gensym("vcf~"), (t_newmethod
)sigvcf_new
, 0,
112 sizeof(t_sigvcf
), 0, A_DEFFLOAT
, 0);
113 CLASS_MAINSIGNALIN(sigvcf_class
, t_sigvcf
, x_f
);
114 class_addmethod(sigvcf_class
, (t_method
)sigvcf_dsp
, gensym("dsp"), 0);
115 class_addmethod(sigvcf_class
, (t_method
)sigvcf_ft1
,
116 gensym("ft1"), A_FLOAT
, 0);
117 class_sethelpsymbol(sigvcf_class
, gensym("lop~-help.pd"));