2 #include "../src/m_pd.h"
3 #include <../src/m_fixed.h>
6 /* ------------------------ cos~ ----------------------------- */
7 #define FRAC ((1<<(fix1-ILOGCOSTABSIZE))-1)
9 static t_class
*cos_class
;
17 static void *cos_new(void)
19 t_cos
*x
= (t_cos
*)pd_new(cos_class
);
20 outlet_new(&x
->x_obj
, gensym("signal"));
25 static t_int
*cos_perform(t_int
*w
)
27 t_sample
*in
= (t_sample
*)(w
[1]);
28 t_sample
*out
= (t_sample
*)(w
[2]);
30 t_sample
*tab
= cos_table
;
37 phase
&= ((1<<fix1
)-1);
38 off
= fixtoi((long long)phase
<<ILOGCOSTABSIZE
);
40 frac
= phase
&(itofix(1)-1);
41 *out
= mult(*(tab
+ off
),itofix(1) - frac
) +
42 mult(*(tab
+ off
+ 1),frac
);
48 static void cos_dsp(t_cos
*x
, t_signal
**sp
)
53 dsp_add(cos_perform
, 3, sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[0]->s_n
);
57 void cos_tilde_setup(void)
59 cos_class
= class_new(gensym("cos~"), (t_newmethod
)cos_new
, 0,
60 sizeof(t_cos
), 0, A_DEFFLOAT
, 0);
61 CLASS_MAINSIGNALIN(cos_class
, t_cos
, x_f
);
62 class_addmethod(cos_class
, (t_method
)cos_dsp
, gensym("dsp"), 0);
63 class_sethelpsymbol(cos_class
, gensym("osc~-help.pd"));