summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabwrite~.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/tabwrite~.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/tabwrite~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabwrite~.c264
1 files changed, 264 insertions, 0 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabwrite~.c b/apps/plugins/pdbox/PDa/intern/tabwrite~.c
new file mode 100644
index 0000000000..47a49cd833
--- /dev/null
+++ b/apps/plugins/pdbox/PDa/intern/tabwrite~.c
@@ -0,0 +1,264 @@
1
2#include <m_pd.h>
3#include <m_fixed.h>
4
5static t_class *tabwrite_tilde_class;
6
7typedef struct _tabwrite_tilde
8{
9 t_object x_obj;
10 int x_phase;
11 int x_nsampsintab;
12 t_sample *x_vec;
13 t_symbol *x_arrayname;
14 t_clock *x_clock;
15 float x_f;
16} t_tabwrite_tilde;
17
18static void tabwrite_tilde_tick(t_tabwrite_tilde *x);
19
20static void *tabwrite_tilde_new(t_symbol *s)
21{
22 t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class);
23 x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick);
24 x->x_phase = 0x7fffffff;
25 x->x_arrayname = s;
26 x->x_f = 0;
27 return (x);
28}
29
30static t_int *tabwrite_tilde_perform(t_int *w)
31{
32 t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
33 t_sample *in = (t_sample *)(w[2]);
34 int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
35 if (!x->x_vec) goto bad;
36
37 if (endphase > phase)
38 {
39 int nxfer = endphase - phase;
40 t_sample *fp = x->x_vec + phase;
41 if (nxfer > n) nxfer = n;
42 phase += nxfer;
43 while (nxfer--)
44 {
45 t_sample f = *in++;
46 *fp++ = f;
47 }
48 if (phase >= endphase)
49 {
50 clock_delay(x->x_clock, 0);
51 phase = 0x7fffffff;
52 }
53 x->x_phase = phase;
54 }
55bad:
56 return (w+4);
57}
58
59void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
60{
61 t_garray *a;
62
63 x->x_arrayname = s;
64 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
65 {
66 if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
67 x->x_arrayname->s_name);
68 x->x_vec = 0;
69 }
70 else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
71 {
72 error("%s: bad template for tabwrite~", x->x_arrayname->s_name);
73 x->x_vec = 0;
74 }
75 else garray_usedindsp(a);
76}
77
78static void tabwrite_tilde_dsp(t_tabwrite_tilde *x, t_signal **sp)
79{
80 tabwrite_tilde_set(x, x->x_arrayname);
81 dsp_add(tabwrite_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
82}
83
84static void tabwrite_tilde_bang(t_tabwrite_tilde *x)
85{
86 x->x_phase = 0;
87}
88
89static void tabwrite_tilde_float(t_tabwrite_tilde *x,t_float n)
90{
91 if (n < x->x_nsampsintab)
92 x->x_phase = n;
93 else
94 x->x_phase = 0;
95}
96
97static void tabwrite_tilde_stop(t_tabwrite_tilde *x)
98{
99 if (x->x_phase != 0x7fffffff)
100 {
101 tabwrite_tilde_tick(x);
102 x->x_phase = 0x7fffffff;
103 }
104}
105
106static void tabwrite_tilde_tick(t_tabwrite_tilde *x)
107{
108 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
109 if (!a) bug("tabwrite_tilde_tick");
110 else garray_redraw(a);
111}
112
113static void tabwrite_tilde_free(t_tabwrite_tilde *x)
114{
115 clock_free(x->x_clock);
116}
117
118void tabwrite_tilde_setup(void)
119{
120 tabwrite_tilde_class = class_new(gensym("tabwrite~"),
121 (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free,
122 sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
123 CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f);
124 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp,
125 gensym("dsp"), 0);
126 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set,
127 gensym("set"), A_SYMBOL, 0);
128 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop,
129 gensym("stop"), 0);
130 class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang);
131 class_addfloat(tabwrite_tilde_class, tabwrite_tilde_float);
132}
133
134#include <m_pd.h>
135#include <m_fixed.h>
136
137static t_class *tabwrite_tilde_class;
138
139typedef struct _tabwrite_tilde
140{
141 t_object x_obj;
142 int x_phase;
143 int x_nsampsintab;
144 t_sample *x_vec;
145 t_symbol *x_arrayname;
146 t_clock *x_clock;
147 float x_f;
148} t_tabwrite_tilde;
149
150static void tabwrite_tilde_tick(t_tabwrite_tilde *x);
151
152static void *tabwrite_tilde_new(t_symbol *s)
153{
154 t_tabwrite_tilde *x = (t_tabwrite_tilde *)pd_new(tabwrite_tilde_class);
155 x->x_clock = clock_new(x, (t_method)tabwrite_tilde_tick);
156 x->x_phase = 0x7fffffff;
157 x->x_arrayname = s;
158 x->x_f = 0;
159 return (x);
160}
161
162static t_int *tabwrite_tilde_perform(t_int *w)
163{
164 t_tabwrite_tilde *x = (t_tabwrite_tilde *)(w[1]);
165 t_sample *in = (t_sample *)(w[2]);
166 int n = (int)(w[3]), phase = x->x_phase, endphase = x->x_nsampsintab;
167 if (!x->x_vec) goto bad;
168
169 if (endphase > phase)
170 {
171 int nxfer = endphase - phase;
172 t_sample *fp = x->x_vec + phase;
173 if (nxfer > n) nxfer = n;
174 phase += nxfer;
175 while (nxfer--)
176 {
177 t_sample f = *in++;
178 *fp++ = f;
179 }
180 if (phase >= endphase)
181 {
182 clock_delay(x->x_clock, 0);
183 phase = 0x7fffffff;
184 }
185 x->x_phase = phase;
186 }
187bad:
188 return (w+4);
189}
190
191void tabwrite_tilde_set(t_tabwrite_tilde *x, t_symbol *s)
192{
193 t_garray *a;
194
195 x->x_arrayname = s;
196 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
197 {
198 if (*s->s_name) pd_error(x, "tabwrite~: %s: no such array",
199 x->x_arrayname->s_name);
200 x->x_vec = 0;
201 }
202 else if (!garray_getfloatarray(a, &x->x_nsampsintab, &x->x_vec))
203 {
204 error("%s: bad template for tabwrite~", x->x_arrayname->s_name);
205 x->x_vec = 0;
206 }
207 else garray_usedindsp(a);
208}
209
210static void tabwrite_tilde_dsp(t_tabwrite_tilde *x, t_signal **sp)
211{
212 tabwrite_tilde_set(x, x->x_arrayname);
213 dsp_add(tabwrite_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);
214}
215
216static void tabwrite_tilde_bang(t_tabwrite_tilde *x)
217{
218 x->x_phase = 0;
219}
220
221static void tabwrite_tilde_float(t_tabwrite_tilde *x,t_float n)
222{
223 if (n < x->x_nsampsintab)
224 x->x_phase = n;
225 else
226 x->x_phase = 0;
227}
228
229static void tabwrite_tilde_stop(t_tabwrite_tilde *x)
230{
231 if (x->x_phase != 0x7fffffff)
232 {
233 tabwrite_tilde_tick(x);
234 x->x_phase = 0x7fffffff;
235 }
236}
237
238static void tabwrite_tilde_tick(t_tabwrite_tilde *x)
239{
240 t_garray *a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class);
241 if (!a) bug("tabwrite_tilde_tick");
242 else garray_redraw(a);
243}
244
245static void tabwrite_tilde_free(t_tabwrite_tilde *x)
246{
247 clock_free(x->x_clock);
248}
249
250void tabwrite_tilde_setup(void)
251{
252 tabwrite_tilde_class = class_new(gensym("tabwrite~"),
253 (t_newmethod)tabwrite_tilde_new, (t_method)tabwrite_tilde_free,
254 sizeof(t_tabwrite_tilde), 0, A_DEFSYM, 0);
255 CLASS_MAINSIGNALIN(tabwrite_tilde_class, t_tabwrite_tilde, x_f);
256 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_dsp,
257 gensym("dsp"), 0);
258 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_set,
259 gensym("set"), A_SYMBOL, 0);
260 class_addmethod(tabwrite_tilde_class, (t_method)tabwrite_tilde_stop,
261 gensym("stop"), 0);
262 class_addbang(tabwrite_tilde_class, tabwrite_tilde_bang);
263 class_addfloat(tabwrite_tilde_class, tabwrite_tilde_float);
264}