summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/intern/tabosc4~.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/intern/tabosc4~.c')
-rw-r--r--apps/plugins/pdbox/PDa/intern/tabosc4~.c131
1 files changed, 0 insertions, 131 deletions
diff --git a/apps/plugins/pdbox/PDa/intern/tabosc4~.c b/apps/plugins/pdbox/PDa/intern/tabosc4~.c
index ec8ed84f31..f9b6ad0ac3 100644
--- a/apps/plugins/pdbox/PDa/intern/tabosc4~.c
+++ b/apps/plugins/pdbox/PDa/intern/tabosc4~.c
@@ -131,134 +131,3 @@ void tabosc4_tilde_setup(void)
131 gensym("ft1"), A_FLOAT, 0); 131 gensym("ft1"), A_FLOAT, 0);
132} 132}
133 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}