Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabread~.c
blobfe142c71b64a1507bd7c87e74d54d88e4911a222
1 #ifndef ROCKBOX
2 #define FIXEDPOINT
3 #endif
5 #include "../src/m_pd.h"
6 #include <../src/m_fixed.h>
8 static t_class *tabread_tilde_class;
10 typedef struct _tabread_tilde
12 t_object x_obj;
13 int x_npoints;
14 t_sample *x_vec;
15 t_symbol *x_arrayname;
16 float x_f;
17 } t_tabread_tilde;
19 static void *tabread_tilde_new(t_symbol *s)
21 t_tabread_tilde *x = (t_tabread_tilde *)pd_new(tabread_tilde_class);
22 x->x_arrayname = s;
23 x->x_vec = 0;
24 outlet_new(&x->x_obj, gensym("signal"));
25 x->x_f = 0;
26 return (x);
29 static t_int *tabread_tilde_perform(t_int *w)
31 t_tabread_tilde *x = (t_tabread_tilde *)(w[1]);
32 t_sample *in = (t_sample *)(w[2]);
33 t_sample *out = (t_sample *)(w[3]);
34 int n = (int)(w[4]);
35 int maxindex;
36 #ifdef ROCKBOX
37 t_sample *buf = x->x_vec;
38 #else
39 t_sample *buf = x->x_vec, *fp;
40 #endif
41 int i;
43 maxindex = x->x_npoints - 1;
44 if (!buf) goto zero;
46 for (i = 0; i < n; i++)
48 int index = ((long long) mult((*in++),ftofix(44.1)) >> fix1);
49 if (index < 0)
50 index = 0;
51 else if (index > maxindex)
52 index = maxindex;
53 *out++ = buf[index];
55 return (w+5);
56 zero:
57 while (n--) *out++ = 0;
59 return (w+5);
62 void tabread_tilde_set(t_tabread_tilde *x, t_symbol *s)
64 t_garray *a;
66 x->x_arrayname = s;
67 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
69 if (*s->s_name)
70 error("tabread~: %s: no such array", x->x_arrayname->s_name);
71 x->x_vec = 0;
73 else if (!garray_getfloatarray(a, &x->x_npoints, &x->x_vec))
75 error("%s: bad template for tabread~", x->x_arrayname->s_name);
76 x->x_vec = 0;
78 else garray_usedindsp(a);
81 static void tabread_tilde_dsp(t_tabread_tilde *x, t_signal **sp)
83 tabread_tilde_set(x, x->x_arrayname);
85 dsp_add(tabread_tilde_perform, 4, x,
86 sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
90 static void tabread_tilde_free(t_tabread_tilde *x)
92 #ifdef ROCKBOX
93 (void) x;
94 #endif
97 void tabread_tilde_setup(void)
99 tabread_tilde_class = class_new(gensym("tabread~"),
100 (t_newmethod)tabread_tilde_new, (t_method)tabread_tilde_free,
101 sizeof(t_tabread_tilde), 0, A_DEFSYM, 0);
102 CLASS_MAINSIGNALIN(tabread_tilde_class, t_tabread_tilde, x_f);
103 class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_dsp,
104 gensym("dsp"), 0);
105 class_addmethod(tabread_tilde_class, (t_method)tabread_tilde_set,
106 gensym("set"), A_SYMBOL, 0);