2 #include "../src/m_pd.h"
3 #include <../src/m_fixed.h>
5 static t_class
*tabosc4_tilde_class
;
7 typedef struct _tabosc4_tilde
13 t_symbol
*x_arrayname
;
19 static void *tabosc4_tilde_new(t_symbol
*s
)
21 t_tabosc4_tilde
*x
= (t_tabosc4_tilde
*)pd_new(tabosc4_tilde_class
);
25 outlet_new(&x
->x_obj
, gensym("signal"));
26 inlet_new(&x
->x_obj
, &x
->x_obj
.ob_pd
, &s_float
, gensym("ft1"));
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]);
38 t_sample
*tab
= x
->x_vec
;
39 unsigned int phase
= x
->x_phase
;
43 int logp
= x
->x_lognpoints
;
49 phase
+= mult(conv
,(*in
++));
50 phase
&= (itofix(1) -1);
51 off
= fixtoi((long long)phase
<<logp
);
53 #ifdef NO_INTERPOLATION
56 frac
= phase
& ((1<<logp
)-1);
59 f2
= (off
== x
->x_fnpoints
) ?
61 mult(*(tab
+ off
+ 1),frac
);
63 *out
= mult(*(tab
+ off
),(itofix(1) - frac
)) + f2
;
72 while (n
--) *out
++ = 0;
77 void tabosc4_tilde_set(t_tabosc4_tilde
*x
, t_symbol
*s
)
83 int npoints
, pointsinarray
;
87 if (!(a
= (t_garray
*)pd_findbyclass(x
->x_arrayname
, garray_class
)))
90 pd_error(x
, "tabosc4~: %s: no such array", x
->x_arrayname
->s_name
);
93 else if (!garray_getfloatarray(a
, &pointsinarray
, &x
->x_vec
))
95 pd_error(x
, "%s: bad template for tabosc4~", x
->x_arrayname
->s_name
);
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
);
111 static void tabosc4_tilde_ft1(t_tabosc4_tilde
*x
, t_float 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
,
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);