summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/extra/moog~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/extra/moog~.c')
-rw-r--r--apps/plugins/pdbox/PDa/extra/moog~.c366
1 files changed, 366 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/moog~.c b/apps/plugins/pdbox/PDa/extra/moog~.c
new file mode 100644
index 0000000000..ee7acc99aa
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/extra/moog~.c
@@ -0,0 +1,366 @@
1/* (C) Guenter Geiger <geiger@epy.co.at> */
2
3
4#include "math.h"
5#include <m_pd.h>
6
7/* ----------------------------- moog ----------------------------- */
8static t_class *moog_class;
9
10
11typedef struct _moog
12{
13 t_object x_obj;
14 t_pd in2;
15 t_sample x_1,x_2,x_3,x_4;
16 t_sample y_1,y_2,y_3,y_4;
17} t_moog;
18
19static void moog_reset(t_moog *x)
20{
21 x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
22 x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
23
24}
25
26
27
28static void *moog_new(t_symbol *s, int argc, t_atom *argv)
29{
30 if (argc > 1) post("moog~: extra arguments ignored");
31 {
32 t_moog *x = (t_moog *)pd_new(moog_class);
33 outlet_new(&x->x_obj, &s_signal);
34 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
35 inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
36 moog_reset(x);
37 return (x);
38 }
39
40
41}
42
43
44
45static t_sample calc_k(t_sample f,t_sample k) {
46 if (k>itofix(4)) k = itofix(4);
47 if (k < 0) k = 0;
48 if (f <= itofix(3800)) return k;
49 k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
50 return k;
51}
52
53t_int *moog_perform(t_int *w)
54{
55 t_moog* x = (t_moog*) (w[1]);
56 t_sample *in1 = (t_sample *)(w[2]);
57 t_sample *p = (t_sample *)(w[3]);
58 t_sample *k = (t_sample *)(w[4]);
59
60 t_sample *out = (t_sample *)(w[5]);
61 int n = (int)(w[6]);
62 t_sample in;
63 t_sample pt,pt1;
64
65 t_sample x1 = x->x_1;
66 t_sample x2 = x->x_2;
67 t_sample x3 = x->x_3;
68 t_sample x4 = x->x_4;
69 t_sample ys1 = x->y_1;
70 t_sample ys2 = x->y_2;
71 t_sample ys3 = x->y_3;
72 t_sample ys4 = x->y_4;
73
74
75 while (n--) {
76 if (*p > itofix(8140)) *p = itofix(8140);
77 *k = calc_k(*p,*k);
78 pt =*p;
79 pt1=mult((pt+1),ftofix(0.76923077));
80 in = *in1++ - mult(*k,ys4);
81 ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
82 x1 = in;
83 ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
84 x2 = ys1;
85 ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
86 x3 = ys2;
87 ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
88 x4 = ys3;
89 *out++ = ys4;
90 }
91
92
93 x->y_1 = ys1;
94 x->y_2 = ys2;
95 x->y_3 = ys3;
96 x->y_4 = ys4;
97 x->x_1 = x1;
98 x->x_2 = x2;
99 x->x_3 = x3;
100 x->x_4 = x4;
101
102 return (w+7);
103}
104
105
106#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
107
108t_int *moog_perf8(t_int *w)
109{
110 t_moog* x = (t_moog*) (w[1]);
111 t_sample *in1 = (t_sample *)(w[2]);
112 t_sample *p = (t_sample *)(w[3]);
113 t_sample *k = (t_sample *)(w[4]);
114 t_sample *out = (t_sample *)(w[5]);
115 int n = (int)(w[6]);
116
117 t_sample x1 = x->x_1;
118 t_sample x2 = x->x_2;
119 t_sample x3 = x->x_3;
120 t_sample x4 = x->x_4;
121 t_sample ys1 = x->y_1;
122 t_sample ys2 = x->y_2;
123 t_sample ys3 = x->y_3;
124 t_sample ys4 = x->y_4;
125
126 t_sample temp,temp2;
127 t_sample pt,pt1;
128 t_sample in;
129
130 while (n--) {
131 if (*p > itofix(8140)) *p = itofix(8140);
132 *k = calc_k(*p,*k);
133
134 pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
135 pt1=mult((pt+itofix(1)),ftofix(0.76923077));
136 in = *in1++ - mult(*k,ys4);
137 ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
138 x1 = in;
139 ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
140 x2 = ys1;
141 ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
142 x3 = ys2;
143 ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
144 x4 = ys3;
145 *out++ = ys4;
146
147 p++;k++;
148 }
149
150 x->y_1 = ys1;
151 x->y_2 = ys2;
152 x->y_3 = ys3;
153 x->y_4 = ys4;
154 x->x_1 = x1;
155 x->x_2 = x2;
156 x->x_3 = x3;
157 x->x_4 = x4;
158
159 return (w+7);
160}
161
162void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
163{
164 if (n&7)
165 dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
166 else
167 dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
168}
169
170static void moog_dsp(t_moog *x, t_signal **sp)
171{
172 dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
173}
174
175
176void moog_tilde_setup(void)
177{
178 moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
179 sizeof(t_moog), 0, A_GIMME, 0);
180 class_addmethod(moog_class, nullfn, gensym("signal"), 0);
181 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
182 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
183}
184/* (C) Guenter Geiger <geiger@epy.co.at> */
185
186
187#include "math.h"
188#include <m_pd.h>
189
190/* ----------------------------- moog ----------------------------- */
191static t_class *moog_class;
192
193
194typedef struct _moog
195{
196 t_object x_obj;
197 t_pd in2;
198 t_sample x_1,x_2,x_3,x_4;
199 t_sample y_1,y_2,y_3,y_4;
200} t_moog;
201
202static void moog_reset(t_moog *x)
203{
204 x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
205 x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
206
207}
208
209
210
211static void *moog_new(t_symbol *s, int argc, t_atom *argv)
212{
213 if (argc > 1) post("moog~: extra arguments ignored");
214 {
215 t_moog *x = (t_moog *)pd_new(moog_class);
216 outlet_new(&x->x_obj, &s_signal);
217 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
218 inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
219 moog_reset(x);
220 return (x);
221 }
222
223
224}
225
226
227
228static t_sample calc_k(t_sample f,t_sample k) {
229 if (k>itofix(4)) k = itofix(4);
230 if (k < 0) k = 0;
231 if (f <= itofix(3800)) return k;
232 k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
233 return k;
234}
235
236t_int *moog_perform(t_int *w)
237{
238 t_moog* x = (t_moog*) (w[1]);
239 t_sample *in1 = (t_sample *)(w[2]);
240 t_sample *p = (t_sample *)(w[3]);
241 t_sample *k = (t_sample *)(w[4]);
242
243 t_sample *out = (t_sample *)(w[5]);
244 int n = (int)(w[6]);
245 t_sample in;
246 t_sample pt,pt1;
247
248 t_sample x1 = x->x_1;
249 t_sample x2 = x->x_2;
250 t_sample x3 = x->x_3;
251 t_sample x4 = x->x_4;
252 t_sample ys1 = x->y_1;
253 t_sample ys2 = x->y_2;
254 t_sample ys3 = x->y_3;
255 t_sample ys4 = x->y_4;
256
257
258 while (n--) {
259 if (*p > itofix(8140)) *p = itofix(8140);
260 *k = calc_k(*p,*k);
261 pt =*p;
262 pt1=mult((pt+1),ftofix(0.76923077));
263 in = *in1++ - mult(*k,ys4);
264 ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
265 x1 = in;
266 ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
267 x2 = ys1;
268 ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
269 x3 = ys2;
270 ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
271 x4 = ys3;
272 *out++ = ys4;
273 }
274
275
276 x->y_1 = ys1;
277 x->y_2 = ys2;
278 x->y_3 = ys3;
279 x->y_4 = ys4;
280 x->x_1 = x1;
281 x->x_2 = x2;
282 x->x_3 = x3;
283 x->x_4 = x4;
284
285 return (w+7);
286}
287
288
289#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
290
291t_int *moog_perf8(t_int *w)
292{
293 t_moog* x = (t_moog*) (w[1]);
294 t_sample *in1 = (t_sample *)(w[2]);
295 t_sample *p = (t_sample *)(w[3]);
296 t_sample *k = (t_sample *)(w[4]);
297 t_sample *out = (t_sample *)(w[5]);
298 int n = (int)(w[6]);
299
300 t_sample x1 = x->x_1;
301 t_sample x2 = x->x_2;
302 t_sample x3 = x->x_3;
303 t_sample x4 = x->x_4;
304 t_sample ys1 = x->y_1;
305 t_sample ys2 = x->y_2;
306 t_sample ys3 = x->y_3;
307 t_sample ys4 = x->y_4;
308
309 t_sample temp,temp2;
310 t_sample pt,pt1;
311 t_sample in;
312
313 while (n--) {
314 if (*p > itofix(8140)) *p = itofix(8140);
315 *k = calc_k(*p,*k);
316
317 pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
318 pt1=mult((pt+itofix(1)),ftofix(0.76923077));
319 in = *in1++ - mult(*k,ys4);
320 ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
321 x1 = in;
322 ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
323 x2 = ys1;
324 ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
325 x3 = ys2;
326 ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
327 x4 = ys3;
328 *out++ = ys4;
329
330 p++;k++;
331 }
332
333 x->y_1 = ys1;
334 x->y_2 = ys2;
335 x->y_3 = ys3;
336 x->y_4 = ys4;
337 x->x_1 = x1;
338 x->x_2 = x2;
339 x->x_3 = x3;
340 x->x_4 = x4;
341
342 return (w+7);
343}
344
345void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
346{
347 if (n&7)
348 dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
349 else
350 dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
351}
352
353static void moog_dsp(t_moog *x, t_signal **sp)
354{
355 dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
356}
357
358
359void moog_tilde_setup(void)
360{
361 moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
362 sizeof(t_moog), 0, A_GIMME, 0);
363 class_addmethod(moog_class, nullfn, gensym("signal"), 0);
364 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
365 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
366}