summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabosc4~.c
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2009-05-22 21:58:48 +0000
commit513389b4c1bc8afe4b2dc9947c534bfeb105e3da (patch)
tree10e673b35651ac567fed2eda0c679c7ade64cbc6 /apps/plugins/pdbox/PDa/intern/tabosc4~.c
parent95fa7f6a2ef466444fbe3fe87efc6d5db6b77b36 (diff)
downloadrockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.tar.gz
rockbox-513389b4c1bc8afe4b2dc9947c534bfeb105e3da.zip
Add FS #10214. Initial commit of the original PDa code for the GSoC Pure Data plugin project of Wincent Balin. Stripped some non-sourcefiles and added a rockbox readme that needs a bit more info from Wincent. Is added to CATEGORIES and viewers, but not yet to SUBDIRS (ie doesn't build yet)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@21044 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabosc4~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabosc4~.c264
1 files changed, 264 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabosc4~.c b/apps/plugins/pdbox/PDa/intern/tabosc4~.c
new file mode 100644
index 0000000000..ec8ed84f31
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/tabosc4~.c
@@ -0,0 +1,264 @@
1
2#include <m_pd.h>
3#include <m_fixed.h>
4
5static t_class *tabosc4_tilde_class;
6
7typedef struct _tabosc4_tilde
8{
9 t_object x_obj;
10 int x_fnpoints;
11 int x_lognpoints;
12 t_sample *x_vec;
13 t_symbol *x_arrayname;
14 t_sample x_f;
15 unsigned int x_phase;
16 t_sample x_conv;
17} t_tabosc4_tilde;
18
19static void *tabosc4_tilde_new(t_symbol *s)
20{
21 t_tabosc4_tilde *x = (t_tabosc4_tilde *)pd_new(tabosc4_tilde_class);
22 x->x_arrayname = s;
23 x->x_vec = 0;
24 x->x_fnpoints = 512;
25 outlet_new(&x->x_obj, gensym("signal"));
26 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
27 x->x_f = 0;
28 post("new done");
29 return (x);
30}
31
32static t_int *tabosc4_tilde_perform(t_int *w)
33{
34 t_tabosc4_tilde *x = (t_tabosc4_tilde *)(w[1]);
35 t_sample *in = (t_sample *)(w[2]);
36 t_sample *out = (t_sample *)(w[3]);
37 int n = (int)(w[4]);
38 t_sample *tab = x->x_vec;
39 unsigned int phase = x->x_phase;
40 int conv = x->x_conv;
41 int off;
42 int frac;
43 int logp = x->x_lognpoints;
44
45 if (!tab) goto zero;
46
47 while (n--) {
48 t_sample f2;
49 phase+= mult(conv ,(*in++));
50 phase &= (itofix(1) -1);
51 off = fixtoi((long long)phase<<logp);
52
53#ifdef NO_INTERPOLATION
54 *out = *(tab+off);
55#else
56 frac = phase & ((1<<logp)-1);
57 frac <<= (fix1-logp);
58
59 f2 = (off == x->x_fnpoints) ?
60 mult(*(tab),frac) :
61 mult(*(tab + off + 1),frac);
62
63 *out = mult(*(tab + off),(itofix(1) - frac)) + f2;
64#endif
65 out++;
66 }
67 x->x_phase = phase;
68
69 return (w+5);
70
71zero:
72 while (n--) *out++ = 0;
73
74 return (w+5);
75}
76
77void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s)
78{
79 t_garray *a;
80 int npoints, pointsinarray;
81 x->x_arrayname = s;
82
83 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
84 {
85 if (*s->s_name)
86 pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
87 x->x_vec = 0;
88 }
89 else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec))
90 {
91 pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
92 x->x_vec = 0;
93 }
94 else
95 {
96 int i;
97 x->x_fnpoints = pointsinarray;
98 x->x_lognpoints = ilog2(pointsinarray);
99 post("tabosc~: using %d (log %d) points of array",x->x_fnpoints,x->x_lognpoints);
100
101 garray_usedindsp(a);
102 }
103}
104
105static void tabosc4_tilde_ft1(t_tabosc4_tilde *x, t_float f)
106{
107 x->x_phase = f;
108}
109
110static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp)
111{
112 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
113 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
114
115 tabosc4_tilde_set(x, x->x_arrayname);
116 dsp_add(tabosc4_tilde_perform, 4, x,
117 sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
118}
119
120void tabosc4_tilde_setup(void)
121{
122 tabosc4_tilde_class = class_new(gensym("tabosc4~"),
123 (t_newmethod)tabosc4_tilde_new, 0,
124 sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
125 CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f);
126 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp,
127 gensym("dsp"), 0);
128 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set,
129 gensym("set"), A_SYMBOL, 0);
130 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1,
131 gensym("ft1"), A_FLOAT, 0);
132}
133
134#include <m_pd.h>
135#include <m_fixed.h>
136
137static t_class *tabosc4_tilde_class;
138
139typedef struct _tabosc4_tilde
140{
141 t_object x_obj;
142 int x_fnpoints;
143 int x_lognpoints;
144 t_sample *x_vec;
145 t_symbol *x_arrayname;
146 t_sample x_f;
147 unsigned int x_phase;
148 t_sample x_conv;
149} t_tabosc4_tilde;
150
151static void *tabosc4_tilde_new(t_symbol *s)
152{
153 t_tabosc4_tilde *x = (t_tabosc4_tilde *)pd_new(tabosc4_tilde_class);
154 x->x_arrayname = s;
155 x->x_vec = 0;
156 x->x_fnpoints = 512;
157 outlet_new(&x->x_obj, gensym("signal"));
158 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
159 x->x_f = 0;
160 post("new done");
161 return (x);
162}
163
164static t_int *tabosc4_tilde_perform(t_int *w)
165{
166 t_tabosc4_tilde *x = (t_tabosc4_tilde *)(w[1]);
167 t_sample *in = (t_sample *)(w[2]);
168 t_sample *out = (t_sample *)(w[3]);
169 int n = (int)(w[4]);
170 t_sample *tab = x->x_vec;
171 unsigned int phase = x->x_phase;
172 int conv = x->x_conv;
173 int off;
174 int frac;
175 int logp = x->x_lognpoints;
176
177 if (!tab) goto zero;
178
179 while (n--) {
180 t_sample f2;
181 phase+= mult(conv ,(*in++));
182 phase &= (itofix(1) -1);
183 off = fixtoi((long long)phase<<logp);
184
185#ifdef NO_INTERPOLATION
186 *out = *(tab+off);
187#else
188 frac = phase & ((1<<logp)-1);
189 frac <<= (fix1-logp);
190
191 f2 = (off == x->x_fnpoints) ?
192 mult(*(tab),frac) :
193 mult(*(tab + off + 1),frac);
194
195 *out = mult(*(tab + off),(itofix(1) - frac)) + f2;
196#endif
197 out++;
198 }
199 x->x_phase = phase;
200
201 return (w+5);
202
203zero:
204 while (n--) *out++ = 0;
205
206 return (w+5);
207}
208
209void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s)
210{
211 t_garray *a;
212 int npoints, pointsinarray;
213 x->x_arrayname = s;
214
215 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
216 {
217 if (*s->s_name)
218 pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
219 x->x_vec = 0;
220 }
221 else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec))
222 {
223 pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
224 x->x_vec = 0;
225 }
226 else
227 {
228 int i;
229 x->x_fnpoints = pointsinarray;
230 x->x_lognpoints = ilog2(pointsinarray);
231 post("tabosc~: using %d (log %d) points of array",x->x_fnpoints,x->x_lognpoints);
232
233 garray_usedindsp(a);
234 }
235}
236
237static void tabosc4_tilde_ft1(t_tabosc4_tilde *x, t_float f)
238{
239 x->x_phase = f;
240}
241
242static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp)
243{
244 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
245 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
246
247 tabosc4_tilde_set(x, x->x_arrayname);
248 dsp_add(tabosc4_tilde_perform, 4, x,
249 sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
250}
251
252void tabosc4_tilde_setup(void)
253{
254 tabosc4_tilde_class = class_new(gensym("tabosc4~"),
255 (t_newmethod)tabosc4_tilde_new, 0,
256 sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
257 CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f);
258 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp,
259 gensym("dsp"), 0);
260 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set,
261 gensym("set"), A_SYMBOL, 0);
262 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1,
263 gensym("ft1"), A_FLOAT, 0);
264}