Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabread4~.c
blobee17b159c5fc3e946f659a9eae734c2c594640d8
2 #include "../src/m_pd.h"
3 #include <../src/m_fixed.h>
6 static t_class *tabread4_tilde_class;
8 typedef struct _tabread4_tilde
10 t_object x_obj;
11 int x_npoints;
12 t_sample *x_vec;
13 t_symbol *x_arrayname;
14 float x_f;
15 } t_tabread4_tilde;
17 static void *tabread4_tilde_new(t_symbol *s)
19 t_tabread4_tilde *x = (t_tabread4_tilde *)pd_new(tabread4_tilde_class);
20 x->x_arrayname = s;
21 x->x_vec = 0;
22 outlet_new(&x->x_obj, gensym("signal"));
23 x->x_f = 0;
24 return (x);
27 static t_int *tabread4_tilde_perform(t_int *w)
29 t_tabread4_tilde *x = (t_tabread4_tilde *)(w[1]);
30 t_sample *in = (t_sample *)(w[2]);
31 t_sample *out = (t_sample *)(w[3]);
32 int n = (int)(w[4]);
33 int maxindex;
34 t_sample *buf = x->x_vec, *fp;
35 int i;
37 maxindex = x->x_npoints - 3;
39 if (!buf) goto zero;
41 for (i = 0; i < n; i++)
43 t_time findex = ((long long) mult((*in++),ftofix(44.1)));
44 int index = fixtoi(findex);
45 t_sample frac;
46 // post("%d: index %d f %lld",index,findex,*in);
48 if (index < 1)
49 index = 1, frac = 0;
50 else if (index > maxindex)
51 index = maxindex, frac = 1;
52 else frac = findex - itofix(index);
53 fp = buf + index;
54 *out++ = fp[0] + mult(frac,fp[1]-fp[0]);
56 return (w+5);
57 zero:
58 while (n--) *out++ = 0;
60 return (w+5);
63 void tabread4_tilde_set(t_tabread4_tilde *x, t_symbol *s)
65 t_garray *a;
67 x->x_arrayname = s;
68 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
70 if (*s->s_name)
71 error("tabread4~: %s: no such array", x->x_arrayname->s_name);
72 x->x_vec = 0;
74 else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
76 error("%s: bad template for tabread4~", x->x_arrayname->s_name);
77 x->x_vec = 0;
79 else garray_usedindsp(a);
82 static void tabread4_tilde_dsp(t_tabread4_tilde *x, t_signal **sp)
84 tabread4_tilde_set(x, x->x_arrayname);
86 dsp_add(tabread4_tilde_perform, 4, x,
87 sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
91 static void tabread4_tilde_free(t_tabread4_tilde *x)
93 #ifdef ROCKBOX
94 (void) x;
95 #endif
98 void tabread4_tilde_setup(void)
100 tabread4_tilde_class = class_new(gensym("tabread4~"),
101 (t_newmethod)tabread4_tilde_new, (t_method)tabread4_tilde_free,
102 sizeof(t_tabread4_tilde), 0, A_DEFSYM, 0);
103 CLASS_MAINSIGNALIN(tabread4_tilde_class, t_tabread4_tilde, x_f);
104 class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_dsp,
105 gensym("dsp"), 0);
106 class_addmethod(tabread4_tilde_class, (t_method)tabread4_tilde_set,
107 gensym("set"), A_SYMBOL, 0);