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~.c376
1 files changed, 193 insertions, 183 deletions
diff --git a/apps/plugins/pdbox/PDa/extra/moog~.c b/apps/plugins/pdbox/PDa/extra/moog~.c
index 48d4dfe932..29525db2ef 100644
--- a/apps/plugins/pdbox/PDa/extra/moog~.c
+++ b/apps/plugins/pdbox/PDa/extra/moog~.c
@@ -1,184 +1,194 @@
1/* (C) Guenter Geiger <geiger@epy.co.at> */ 1/* (C) Guenter Geiger <geiger@epy.co.at> */
2 2
3 3
4#include "math.h" 4#include "math.h"
5#include <m_pd.h> 5#ifdef ROCKBOX
6 6#include "m_pd.h"
7/* ----------------------------- moog ----------------------------- */ 7#else
8static t_class *moog_class; 8#include <m_pd.h>
9 9#endif
10 10
11typedef struct _moog 11/* ----------------------------- moog ----------------------------- */
12{ 12static t_class *moog_class;
13 t_object x_obj; 13
14 t_pd in2; 14
15 t_sample x_1,x_2,x_3,x_4; 15typedef struct _moog
16 t_sample y_1,y_2,y_3,y_4; 16{
17} t_moog; 17 t_object x_obj;
18 18 t_pd in2;
19static void moog_reset(t_moog *x) 19 t_sample x_1,x_2,x_3,x_4;
20{ 20 t_sample y_1,y_2,y_3,y_4;
21 x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0; 21} t_moog;
22 x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0; 22
23 23static void moog_reset(t_moog *x)
24} 24{
25 25 x->x_1 = x->x_2 = x->x_3 = x->x_4 = 0;
26 26 x->y_1 = x->y_2 = x->y_3 = x->y_4 = 0;
27 27
28static void *moog_new(t_symbol *s, int argc, t_atom *argv) 28}
29{ 29
30 if (argc > 1) post("moog~: extra arguments ignored"); 30
31 { 31
32 t_moog *x = (t_moog *)pd_new(moog_class); 32static void *moog_new(t_symbol *s, int argc, t_atom *argv)
33 outlet_new(&x->x_obj, &s_signal); 33{
34 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal); 34#ifdef ROCKBOX
35 inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal); 35 (void) s;
36 moog_reset(x); 36 (void) argv;
37 return (x); 37#endif
38 } 38 if (argc > 1) post("moog~: extra arguments ignored");
39 39 {
40 40 t_moog *x = (t_moog *)pd_new(moog_class);
41} 41 outlet_new(&x->x_obj, &s_signal);
42 42 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
43 43 inlet_new(&x->x_obj, &x->in2, &s_signal, &s_signal);
44 44 moog_reset(x);
45static t_sample calc_k(t_sample f,t_sample k) { 45 return (x);
46 if (k>itofix(4)) k = itofix(4); 46 }
47 if (k < 0) k = 0; 47
48 if (f <= itofix(3800)) return k; 48
49 k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300)))); 49}
50 return k; 50
51} 51
52 52
53t_int *moog_perform(t_int *w) 53static t_sample calc_k(t_sample f,t_sample k) {
54{ 54 if (k>itofix(4)) k = itofix(4);
55 t_moog* x = (t_moog*) (w[1]); 55 if (k < 0) k = 0;
56 t_sample *in1 = (t_sample *)(w[2]); 56 if (f <= itofix(3800)) return k;
57 t_sample *p = (t_sample *)(w[3]); 57 k = k - mult(0.5,(f-idiv(itofix(3800),itofix(4300))));
58 t_sample *k = (t_sample *)(w[4]); 58 return k;
59 59}
60 t_sample *out = (t_sample *)(w[5]); 60
61 int n = (int)(w[6]); 61t_int *moog_perform(t_int *w)
62 t_sample in; 62{
63 t_sample pt,pt1; 63 t_moog* x = (t_moog*) (w[1]);
64 64 t_sample *in1 = (t_sample *)(w[2]);
65 t_sample x1 = x->x_1; 65 t_sample *p = (t_sample *)(w[3]);
66 t_sample x2 = x->x_2; 66 t_sample *k = (t_sample *)(w[4]);
67 t_sample x3 = x->x_3; 67
68 t_sample x4 = x->x_4; 68 t_sample *out = (t_sample *)(w[5]);
69 t_sample ys1 = x->y_1; 69 int n = (int)(w[6]);
70 t_sample ys2 = x->y_2; 70 t_sample in;
71 t_sample ys3 = x->y_3; 71 t_sample pt,pt1;
72 t_sample ys4 = x->y_4; 72
73 73 t_sample x1 = x->x_1;
74 74 t_sample x2 = x->x_2;
75 while (n--) { 75 t_sample x3 = x->x_3;
76 if (*p > itofix(8140)) *p = itofix(8140); 76 t_sample x4 = x->x_4;
77 *k = calc_k(*p,*k); 77 t_sample ys1 = x->y_1;
78 pt =*p; 78 t_sample ys2 = x->y_2;
79 pt1=mult((pt+1),ftofix(0.76923077)); 79 t_sample ys3 = x->y_3;
80 in = *in1++ - mult(*k,ys4); 80 t_sample ys4 = x->y_4;
81 ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1); 81
82 x1 = in; 82
83 ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2); 83 while (n--) {
84 x2 = ys1; 84 if (*p > itofix(8140)) *p = itofix(8140);
85 ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3); 85 *k = calc_k(*p,*k);
86 x3 = ys2; 86 pt =*p;
87 ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4); 87 pt1=mult((pt+1),ftofix(0.76923077));
88 x4 = ys3; 88 in = *in1++ - mult(*k,ys4);
89 *out++ = ys4; 89 ys1 = mult(pt1,in) + mult(0.3,x1) - mult(pt,ys1);
90 } 90 x1 = in;
91 91 ys2 = mult(pt1,ys1) + mult(0.3,x2) - mult(pt,ys2);
92 92 x2 = ys1;
93 x->y_1 = ys1; 93 ys3 = mult(pt1,ys2) + mult(0.3,x3) - mult(pt,ys3);
94 x->y_2 = ys2; 94 x3 = ys2;
95 x->y_3 = ys3; 95 ys4 = mult(pt1,ys3) + mult(0.3,x4) - mult(pt,ys4);
96 x->y_4 = ys4; 96 x4 = ys3;
97 x->x_1 = x1; 97 *out++ = ys4;
98 x->x_2 = x2; 98 }
99 x->x_3 = x3; 99
100 x->x_4 = x4; 100
101 101 x->y_1 = ys1;
102 return (w+7); 102 x->y_2 = ys2;
103} 103 x->y_3 = ys3;
104 104 x->y_4 = ys4;
105 105 x->x_1 = x1;
106#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x)) 106 x->x_2 = x2;
107 107 x->x_3 = x3;
108t_int *moog_perf8(t_int *w) 108 x->x_4 = x4;
109{ 109
110 t_moog* x = (t_moog*) (w[1]); 110 return (w+7);
111 t_sample *in1 = (t_sample *)(w[2]); 111}
112 t_sample *p = (t_sample *)(w[3]); 112
113 t_sample *k = (t_sample *)(w[4]); 113
114 t_sample *out = (t_sample *)(w[5]); 114#define CLIP(x) x = ((x) > 1.0 ? (1.0) : (x))
115 int n = (int)(w[6]); 115
116 116t_int *moog_perf8(t_int *w)
117 t_sample x1 = x->x_1; 117{
118 t_sample x2 = x->x_2; 118 t_moog* x = (t_moog*) (w[1]);
119 t_sample x3 = x->x_3; 119 t_sample *in1 = (t_sample *)(w[2]);
120 t_sample x4 = x->x_4; 120 t_sample *p = (t_sample *)(w[3]);
121 t_sample ys1 = x->y_1; 121 t_sample *k = (t_sample *)(w[4]);
122 t_sample ys2 = x->y_2; 122 t_sample *out = (t_sample *)(w[5]);
123 t_sample ys3 = x->y_3; 123 int n = (int)(w[6]);
124 t_sample ys4 = x->y_4; 124
125 125 t_sample x1 = x->x_1;
126 t_sample temp,temp2; 126 t_sample x2 = x->x_2;
127 t_sample pt,pt1; 127 t_sample x3 = x->x_3;
128 t_sample in; 128 t_sample x4 = x->x_4;
129 129 t_sample ys1 = x->y_1;
130 while (n--) { 130 t_sample ys2 = x->y_2;
131 if (*p > itofix(8140)) *p = itofix(8140); 131 t_sample ys3 = x->y_3;
132 *k = calc_k(*p,*k); 132 t_sample ys4 = x->y_4;
133 133
134 pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f); 134#ifndef ROCKBOX
135 pt1=mult((pt+itofix(1)),ftofix(0.76923077)); 135 t_sample temp,temp2;
136 in = *in1++ - mult(*k,ys4); 136#endif
137 ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1); 137 t_sample pt,pt1;
138 x1 = in; 138 t_sample in;
139 ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2); 139
140 x2 = ys1; 140 while (n--) {
141 ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3); 141 if (*p > itofix(8140)) *p = itofix(8140);
142 x3 = ys2; 142 *k = calc_k(*p,*k);
143 ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4); 143
144 x4 = ys3; 144 pt =mult(*p, ftofix(0.01*0.0140845)) - ftofix(0.9999999f);
145 *out++ = ys4; 145 pt1=mult((pt+itofix(1)),ftofix(0.76923077));
146 146 in = *in1++ - mult(*k,ys4);
147 p++;k++; 147 ys1 = mult(pt1,(in + mult(ftofix(0.3),x1))) - mult(pt,ys1);
148 } 148 x1 = in;
149 149 ys2 = mult(pt1,(ys1 + mult(0.3,x2))) - mult(pt,ys2);
150 x->y_1 = ys1; 150 x2 = ys1;
151 x->y_2 = ys2; 151 ys3 = mult(pt1,(ys2 + mult(0.3,x3))) - mult(pt,ys3);
152 x->y_3 = ys3; 152 x3 = ys2;
153 x->y_4 = ys4; 153 ys4 = mult(pt1,(ys3 + mult(0.3,x4))) - mult(pt,ys4);
154 x->x_1 = x1; 154 x4 = ys3;
155 x->x_2 = x2; 155 *out++ = ys4;
156 x->x_3 = x3; 156
157 x->x_4 = x4; 157 p++;k++;
158 158 }
159 return (w+7); 159
160} 160 x->y_1 = ys1;
161 161 x->y_2 = ys2;
162void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n) 162 x->y_3 = ys3;
163{ 163 x->y_4 = ys4;
164 if (n&7) 164 x->x_1 = x1;
165 dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n); 165 x->x_2 = x2;
166 else 166 x->x_3 = x3;
167 dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n); 167 x->x_4 = x4;
168} 168
169 169 return (w+7);
170static void moog_dsp(t_moog *x, t_signal **sp) 170}
171{ 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); 172void dsp_add_moog(t_moog *x, t_sample *in1, t_sample *in2, t_sample *in3, t_sample *out, int n)
173} 173{
174 174 if (n&7)
175 175 dsp_add(moog_perform, 6,(t_int)x, in1,in2,in3, out, n);
176void moog_tilde_setup(void) 176 else
177{ 177 dsp_add(moog_perf8, 6,(t_int) x, in1, in2, in3, out, n);
178 moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0, 178}
179 sizeof(t_moog), 0, A_GIMME, 0); 179
180 class_addmethod(moog_class, nullfn, gensym("signal"), 0); 180static void moog_dsp(t_moog *x, t_signal **sp)
181 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0); 181{
182 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL); 182 dsp_add_moog(x,sp[0]->s_vec, sp[1]->s_vec, sp[2]->s_vec, sp[3]->s_vec,sp[0]->s_n);
183} 183}
184
185
186void moog_tilde_setup(void)
187{
188 moog_class = class_new(gensym("moog~"), (t_newmethod)moog_new, 0,
189 sizeof(t_moog), 0, A_GIMME, 0);
190 class_addmethod(moog_class, nullfn, gensym("signal"), 0);
191 class_addmethod(moog_class, (t_method)moog_reset, gensym("reset"), 0);
192 class_addmethod(moog_class, (t_method)moog_dsp, gensym("dsp"), A_NULL);
193}
184 194