summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/vcf~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/vcf~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/vcf~.c119
1 files changed, 0 insertions, 119 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/vcf~.c b/apps/plugins/pdbox/PDa/intern/vcf~.c
index 1ff09812a1..e78993a567 100644
--- a/apps/plugins/pdbox/PDa/intern/vcf~.c
+++ b/apps/plugins/pdbox/PDa/intern/vcf~.c
@@ -117,122 +117,3 @@ void vcf_tilde_setup(void)
117 class_sethelpsymbol(sigvcf_class, gensym("lop~-help.pd")); 117 class_sethelpsymbol(sigvcf_class, gensym("lop~-help.pd"));
118} 118}
119 119
120#include <m_pd.h>
121#include <m_fixed.h>
122#include "cos_table.h"
123
124/* ---------------- vcf~ - 2-pole bandpass filter. ----------------- */
125/* GG: complex resonator with signal frequency control
126 this time using the bigger cos_table without interpolation
127 really have to switch to a separate fixpoint format sometime
128*/
129
130typedef struct vcfctl
131{
132 t_sample c_re;
133 t_sample c_im;
134 t_sample c_q;
135 t_sample c_isr;
136} t_vcfctl;
137
138typedef struct sigvcf
139{
140 t_object x_obj;
141 t_vcfctl x_cspace;
142 t_vcfctl *x_ctl;
143 float x_f;
144} t_sigvcf;
145
146t_class *sigvcf_class;
147
148static void *sigvcf_new(t_floatarg q)
149{
150 t_sigvcf *x = (t_sigvcf *)pd_new(sigvcf_class);
151 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
152 inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("ft1"));
153 outlet_new(&x->x_obj, gensym("signal"));
154 outlet_new(&x->x_obj, gensym("signal"));
155 x->x_ctl = &x->x_cspace;
156 x->x_cspace.c_re = 0;
157 x->x_cspace.c_im = 0;
158 x->x_cspace.c_q = ftofix(q);
159 x->x_cspace.c_isr = 0;
160 x->x_f = 0;
161 return (x);
162}
163
164static void sigvcf_ft1(t_sigvcf *x, t_floatarg f)
165{
166 x->x_ctl->c_q = (f > 0 ? ftofix(f) : 0);
167}
168
169static t_int *sigvcf_perform(t_int *w)
170{
171 t_sample *in1 = (t_sample *)(w[1]);
172 t_sample *in2 = (t_sample *)(w[2]);
173 t_sample *out1 = (t_sample *)(w[3]);
174 t_sample *out2 = (t_sample *)(w[4]);
175 t_vcfctl *c = (t_vcfctl *)(w[5]);
176 int n = (t_int)(w[6]);
177 int i;
178 t_sample re = c->c_re, re2;
179 t_sample im = c->c_im;
180 t_sample q = c->c_q;
181 t_sample qinv = (q > 0 ? idiv(ftofix(1.0),q) : 0);
182 t_sample ampcorrect = ftofix(2.0f) - idiv(ftofix(2.0f) , (q + ftofix(2.0f)));
183 t_sample isr = c->c_isr;
184 t_sample coefr, coefi;
185 t_sample *tab = cos_table;
186 t_sample oneminusr,cfindx,cf,r;
187
188 for (i = 0; i < n; i++)
189 {
190 cf = mult(*in2++,isr);
191 if (cf < 0) cf = 0;
192 cfindx = mult(cf,ftofix(0.15915494))>>(fix1-ILOGCOSTABSIZE); /* 1/2*PI */
193 r = (qinv > 0 ? ftofix(1.01) - mult(cf,qinv) : 0);
194
195 if (r < 0) r = 0;
196 oneminusr = ftofix(1.02f) - r; /* hand adapted */
197
198 /* r*cos(cf) */
199 coefr = mult(r,tab[cfindx]);
200
201 /* r*sin(cf) */
202 cfindx-=(ICOSTABSIZE>>2);
203 cfindx += cfindx < 0 ? ICOSTABSIZE:0;
204 coefi = mult(r,tab[cfindx]);
205
206 re2 = re;
207 *out1++ = re = mult(ampcorrect,mult(oneminusr,*in1++))
208 + mult(coefr,re2) - mult(coefi, im);
209 *out2++ = im = mult(coefi,re2) + mult(coefr,im);
210 }
211 c->c_re = re;
212 c->c_im = im;
213 return (w+7);
214}
215
216static void sigvcf_dsp(t_sigvcf *x, t_signal **sp)
217{
218 /* TODO sr is hardcoded */
219 x->x_ctl->c_isr = ftofix(0.0001424758);
220// idiv(ftofix(6.28318),ftofix(sp[0]->s_sr));
221 post("%f",fixtof(x->x_ctl->c_isr));
222 dsp_add(sigvcf_perform, 6,
223 sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,
224 x->x_ctl, sp[0]->s_n);
225
226}
227
228void vcf_tilde_setup(void)
229{
230 sigvcf_class = class_new(gensym("vcf~"), (t_newmethod)sigvcf_new, 0,
231 sizeof(t_sigvcf), 0, A_DEFFLOAT, 0);
232 CLASS_MAINSIGNALIN(sigvcf_class, t_sigvcf, x_f);
233 class_addmethod(sigvcf_class, (t_method)sigvcf_dsp, gensym("dsp"), 0);
234 class_addmethod(sigvcf_class, (t_method)sigvcf_ft1,
235 gensym("ft1"), A_FLOAT, 0);
236 class_sethelpsymbol(sigvcf_class, gensym("lop~-help.pd"));
237}
238