5 #include "../src/m_pd.h"
6 #include <../src/m_fixed.h>
8 static t_class
*tabread_tilde_class
;
10 typedef struct _tabread_tilde
15 t_symbol
*x_arrayname
;
19 static void *tabread_tilde_new(t_symbol
*s
)
21 t_tabread_tilde
*x
= (t_tabread_tilde
*)pd_new(tabread_tilde_class
);
24 outlet_new(&x
->x_obj
, gensym("signal"));
29 static t_int
*tabread_tilde_perform(t_int
*w
)
31 t_tabread_tilde
*x
= (t_tabread_tilde
*)(w
[1]);
32 t_sample
*in
= (t_sample
*)(w
[2]);
33 t_sample
*out
= (t_sample
*)(w
[3]);
37 t_sample
*buf
= x
->x_vec
;
39 t_sample
*buf
= x
->x_vec
, *fp
;
43 maxindex
= x
->x_npoints
- 1;
46 for (i
= 0; i
< n
; i
++)
48 int index
= ((long long) mult((*in
++),ftofix(44.1)) >> fix1
);
51 else if (index
> maxindex
)
57 while (n
--) *out
++ = 0;
62 void tabread_tilde_set(t_tabread_tilde
*x
, t_symbol
*s
)
67 if (!(a
= (t_garray
*)pd_findbyclass(x
->x_arrayname
, garray_class
)))
70 error("tabread~: %s: no such array", x
->x_arrayname
->s_name
);
73 else if (!garray_getfloatarray(a
, &x
->x_npoints
, &x
->x_vec
))
75 error("%s: bad template for tabread~", x
->x_arrayname
->s_name
);
78 else garray_usedindsp(a
);
81 static void tabread_tilde_dsp(t_tabread_tilde
*x
, t_signal
**sp
)
83 tabread_tilde_set(x
, x
->x_arrayname
);
85 dsp_add(tabread_tilde_perform
, 4, x
,
86 sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[0]->s_n
);
90 static void tabread_tilde_free(t_tabread_tilde
*x
)
97 void tabread_tilde_setup(void)
99 tabread_tilde_class
= class_new(gensym("tabread~"),
100 (t_newmethod
)tabread_tilde_new
, (t_method
)tabread_tilde_free
,
101 sizeof(t_tabread_tilde
), 0, A_DEFSYM
, 0);
102 CLASS_MAINSIGNALIN(tabread_tilde_class
, t_tabread_tilde
, x_f
);
103 class_addmethod(tabread_tilde_class
, (t_method
)tabread_tilde_dsp
,
105 class_addmethod(tabread_tilde_class
, (t_method
)tabread_tilde_set
,
106 gensym("set"), A_SYMBOL
, 0);