Fix pdbox makefile to actually take part in dependency generation
[kugel-rb.git] / apps / plugins / pdbox / PDa / intern / osc~.c
blob70bc7301b81a4d3a5da224d140155a75052c7501
3 #include "../src/m_pd.h"
4 #include <../src/m_fixed.h>
5 #include "cos_table.h"
7 /* ------------------------ osc~ ----------------------------- */
9 #ifdef ROCKBOX
10 static t_class *osc_class;
11 #else
12 static t_class *osc_class, *scalarosc_class;
13 #endif
15 typedef struct _osc
17 t_object x_obj;
18 unsigned int x_phase;
19 t_sample x_conv;
20 t_sample x_f; /* frequency if scalar */
21 } t_osc;
23 static void *osc_new(t_floatarg f)
25 t_osc *x = (t_osc *)pd_new(osc_class);
26 x->x_f = ftofix(f);
27 outlet_new(&x->x_obj, gensym("signal"));
28 inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_float, gensym("ft1"));
29 x->x_phase = 0;
30 x->x_conv = 0;
31 return (x);
35 static t_int *osc_perform(t_int *w)
37 t_osc *x = (t_osc *)(w[1]);
38 t_sample *in = (t_sample *)(w[2]);
39 t_sample *out = (t_sample *)(w[3]);
40 int n = (int)(w[4]);
41 t_sample *tab = cos_table;
42 unsigned int phase = x->x_phase;
43 int conv = x->x_conv;
44 int off;
45 int frac;
46 while (n--) {
47 phase+= mult(conv ,(*in++));
48 phase &= (itofix(1) -1);
49 off = fixtoi((long long)phase<<ILOGCOSTABSIZE);
51 #ifdef NO_INTERPOLATION
52 *out = *(tab+off);
53 #else
54 // frac = phase & (itofix(1)-1);
55 frac = phase & ((1<<ILOGCOSTABSIZE)-1);
56 frac <<= (fix1-ILOGCOSTABSIZE);
57 *out = mult(*(tab + off),(itofix(1) - frac)) +
58 mult(*(tab + off + 1),frac);
59 #endif
60 out++;
62 x->x_phase = phase;
64 return (w+5);
67 static void osc_dsp(t_osc *x, t_signal **sp)
69 post("samplerate %f",sp[0]->s_sr);
70 x->x_conv = ftofix(1000.)/sp[0]->s_sr;
71 post("conf %d",x->x_conv);
72 x->x_conv = mult(x->x_conv + 500,ftofix(0.001));
73 post("conf %d",x->x_conv);
74 dsp_add(osc_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, sp[0]->s_n);
77 static void osc_ft1(t_osc *x, t_float f)
79 x->x_phase = ftofix(f); /* *2 ??? */
82 void osc_tilde_setup(void)
84 osc_class = class_new(gensym("osc~"), (t_newmethod)osc_new, 0,
85 sizeof(t_osc), 0, A_DEFFLOAT, 0);
86 CLASS_MAINSIGNALIN(osc_class, t_osc, x_f);
87 class_addmethod(osc_class, (t_method)osc_dsp, gensym("dsp"), 0);
88 class_addmethod(osc_class, (t_method)osc_ft1, gensym("ft1"), A_FLOAT, 0);