Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / tabosc4~.c
blobd017e5ba5797ec25c927656763783b20e0f21b48
2 #include "../src/m_pd.h"
3 #include <../src/m_fixed.h>
5 static t_class *tabosc4_tilde_class;
7 typedef struct _tabosc4_tilde
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;
19 static void *tabosc4_tilde_new(t_symbol *s)
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);
32 static t_int *tabosc4_tilde_perform(t_int *w)
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;
45 if (!tab) goto zero;
47 while (n--) {
48 t_sample f2;
49 phase+= mult(conv ,(*in++));
50 phase &= (itofix(1) -1);
51 off = fixtoi((long long)phase<<logp);
53 #ifdef NO_INTERPOLATION
54 *out = *(tab+off);
55 #else
56 frac = phase & ((1<<logp)-1);
57 frac <<= (fix1-logp);
59 f2 = (off == x->x_fnpoints) ?
60 mult(*(tab),frac) :
61 mult(*(tab + off + 1),frac);
63 *out = mult(*(tab + off),(itofix(1) - frac)) + f2;
64 #endif
65 out++;
67 x->x_phase = phase;
69 return (w+5);
71 zero:
72 while (n--) *out++ = 0;
74 return (w+5);
77 void tabosc4_tilde_set(t_tabosc4_tilde *x, t_symbol *s)
79 t_garray *a;
80 #ifdef ROCKBOX
81 int pointsinarray;
82 #else
83 int npoints, pointsinarray;
84 #endif
85 x->x_arrayname = s;
87 if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class)))
89 if (*s->s_name)
90 pd_error(x, "tabosc4~: %s: no such array", x->x_arrayname->s_name);
91 x->x_vec = 0;
93 else if (!garray_getfloatarray(a, &pointsinarray, &x->x_vec))
95 pd_error(x, "%s: bad template for tabosc4~", x->x_arrayname->s_name);
96 x->x_vec = 0;
98 else
100 #ifndef ROCKBOX
101 int i;
102 #endif
103 x->x_fnpoints = pointsinarray;
104 x->x_lognpoints = ilog2(pointsinarray);
105 post("tabosc~: using %d (log %d) points of array",x->x_fnpoints,x->x_lognpoints);
107 garray_usedindsp(a);
111 static void tabosc4_tilde_ft1(t_tabosc4_tilde *x, t_float f)
113 x->x_phase = f;
116 static void tabosc4_tilde_dsp(t_tabosc4_tilde *x, t_signal **sp)
118 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
119 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
121 tabosc4_tilde_set(x, x->x_arrayname);
122 dsp_add(tabosc4_tilde_perform, 4, x,
123 sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
126 void tabosc4_tilde_setup(void)
128 tabosc4_tilde_class = class_new(gensym("tabosc4~"),
129 (t_newmethod)tabosc4_tilde_new, 0,
130 sizeof(t_tabosc4_tilde), 0, A_DEFSYM, 0);
131 CLASS_MAINSIGNALIN(tabosc4_tilde_class, t_tabosc4_tilde, x_f);
132 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_dsp,
133 gensym("dsp"), 0);
134 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_set,
135 gensym("set"), A_SYMBOL, 0);
136 class_addmethod(tabosc4_tilde_class, (t_method)tabosc4_tilde_ft1,
137 gensym("ft1"), A_FLOAT, 0);