3 #include "../src/m_pd.h"
4 #include <../src/m_fixed.h>
7 /* ------------------------ osc~ ----------------------------- */
10 static t_class
*osc_class
;
12 static t_class
*osc_class
, *scalarosc_class
;
20 t_sample x_f
; /* frequency if scalar */
23 static void *osc_new(t_floatarg f
)
25 t_osc
*x
= (t_osc
*)pd_new(osc_class
);
27 outlet_new(&x
->x_obj
, gensym("signal"));
28 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, &s_float
, gensym("ft1"));
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]);
41 t_sample
*tab
= cos_table
;
42 unsigned int phase
= x
->x_phase
;
47 phase
+= mult(conv
,(*in
++));
48 phase
&= (itofix(1) -1);
49 off
= fixtoi((long long)phase
<<ILOGCOSTABSIZE
);
51 #ifdef NO_INTERPOLATION
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
);
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);