6 static t_class
*tabread4_tilde_class
;
8 typedef struct _tabread4_tilde
13 t_symbol
*x_arrayname
;
17 static void *tabread4_tilde_new(t_symbol
*s
)
19 t_tabread4_tilde
*x
= (t_tabread4_tilde
*)pd_new(tabread4_tilde_class
);
22 outlet_new(&x
->x_obj
, gensym("signal"));
27 static t_int
*tabread4_tilde_perform(t_int
*w
)
29 t_tabread4_tilde
*x
= (t_tabread4_tilde
*)(w
[1]);
30 t_sample
*in
= (t_sample
*)(w
[2]);
31 t_sample
*out
= (t_sample
*)(w
[3]);
34 t_sample
*buf
= x
->x_vec
, *fp
;
37 maxindex
= x
->x_npoints
- 3;
41 for (i
= 0; i
< n
; i
++)
43 t_time findex
= ((long long) mult((*in
++),ftofix(44.1)));
44 int index
= fixtoi(findex
);
46 // post("%d: index %d f %lld",index,findex,*in);
50 else if (index
> maxindex
)
51 index
= maxindex
, frac
= 1;
52 else frac
= findex
- itofix(index
);
54 *out
++ = fp
[0] + mult(frac
,fp
[1]-fp
[0]);
58 while (n
--) *out
++ = 0;
63 void tabread4_tilde_set(t_tabread4_tilde
*x
, t_symbol
*s
)
68 if (!(a
= (t_garray
*)pd_findbyclass(x
->x_arrayname
, garray_class
)))
71 error("tabread4~: %s: no such array", x
->x_arrayname
->s_name
);
74 else if (!garray_getfloatarray(a
, &x
->x_npoints
, &x
->x_vec
))
76 error("%s: bad template for tabread4~", x
->x_arrayname
->s_name
);
79 else garray_usedindsp(a
);
82 static void tabread4_tilde_dsp(t_tabread4_tilde
*x
, t_signal
**sp
)
84 tabread4_tilde_set(x
, x
->x_arrayname
);
86 dsp_add(tabread4_tilde_perform
, 4, x
,
87 sp
[0]->s_vec
, sp
[1]->s_vec
, sp
[0]->s_n
);
91 static void tabread4_tilde_free(t_tabread4_tilde
*x
)
98 void tabread4_tilde_setup(void)
100 tabread4_tilde_class
= class_new(gensym("tabread4~"),
101 (t_newmethod
)tabread4_tilde_new
, (t_method
)tabread4_tilde_free
,
102 sizeof(t_tabread4_tilde
), 0, A_DEFSYM
, 0);
103 CLASS_MAINSIGNALIN(tabread4_tilde_class
, t_tabread4_tilde
, x_f
);
104 class_addmethod(tabread4_tilde_class
, (t_method
)tabread4_tilde_dsp
,
106 class_addmethod(tabread4_tilde_class
, (t_method
)tabread4_tilde_set
,
107 gensym("set"), A_SYMBOL
, 0);