From: Paul Brossier Date: Tue, 11 Oct 2016 10:13:56 +0000 (+0200) Subject: src/aubiosampler~.c: add set method X-Git-Url: https://git.aubio.org/?a=commitdiff_plain;h=e1c2a05f7647227c28d34f47e919680545e240ac;p=pd-aubio.git src/aubiosampler~.c: add set method --- diff --git a/src/aubiosampler~.c b/src/aubiosampler~.c index 92b8222..c3bb76d 100644 --- a/src/aubiosampler~.c +++ b/src/aubiosampler~.c @@ -33,6 +33,8 @@ typedef struct _aubiosampler_tilde { t_object x_obj; aubio_sampler_t *o; + t_symbol *x_arrayname; + fvec_t *table; t_inlet *inlet_s; t_inlet *inlet_t; t_outlet *outlet; @@ -42,6 +44,8 @@ typedef struct _aubiosampler_tilde smpl_t transpose; } t_aubiosampler_tilde; +static void * aubiosampler_tilde_set_table (t_aubiosampler_tilde *x, t_symbol *s); + static t_int * aubiosampler_tilde_perform (t_int * w) { @@ -62,6 +66,8 @@ aubiosampler_tilde_perform (t_int * w) output_vec.data = out; output_vec.length = s_n; + aubio_sampler_set_stretch(x->o, x->stretch); + aubio_sampler_set_transpose(x->o, x->transpose); aubio_sampler_do(x->o, &output_vec, &read); /* signal the end of file with a bang */ @@ -81,6 +87,7 @@ aubiosampler_tilde_tick(t_aubiosampler_tilde * x) static void aubiosampler_tilde_dsp (t_aubiosampler_tilde * x, t_signal ** sp) { + //if (x->x_arrayname) aubiosampler_tilde_set_table(x, x->x_arrayname); dsp_add (aubiosampler_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); } @@ -92,6 +99,7 @@ aubiosampler_tilde_new (t_symbol *s, int argc, t_atom *argv) x->stretch = 1.; x->o = new_aubio_sampler(sys_getblksize(), sys_getsr()); if (!x->o) return NULL; + x->table = NULL; x->inlet_s = floatinlet_new (&x->x_obj, &x->stretch); x->inlet_t = floatinlet_new (&x->x_obj, &x->transpose); x->outlet = outlet_new(&x->x_obj, gensym("signal")); @@ -120,6 +128,42 @@ aubiosampler_tilde_seek (t_aubiosampler_tilde *x, t_floatarg f) { } } +static void * +aubiosampler_tilde_set_table (t_aubiosampler_tilde *x, t_symbol *s) { + t_garray *a; + x->x_arrayname = s; + uint_t length; t_word *data; + if (!(a = (t_garray *)pd_findbyclass(x->x_arrayname, garray_class))) { + if (*s->s_name) + pd_error(x, "aubiosampler~: %s: no such array", x->x_arrayname->s_name); + //x->table = NULL; + } else if (!garray_getfloatwords(a, &length, &data)) { + //} else if (!garray_getfloatwords(a, &x->table->length, (t_word **)&x->table->data)) { + pd_error(x, "aubiosampler~: bad template %s", x->x_arrayname->s_name); + //x->table = NULL; + } else { + post("aubiosampler~: table set to %s (%d long)", x->x_arrayname->s_name, + length); +#if 0 + x->table.length = length * 2; + x->table.data = (smpl_t*)data; + //pd_error(x, "aubiosampler~: table set to %s (%d long)", x->x_arrayname->s_name, + // x->table->length); + aubio_sampler_set_table(x->o, &x->table); +#else + fvec_t *newtable = new_fvec(length), *oldtable = x->table; + uint_t i; + for (i = 0; i < length; i++) { + newtable->data[i] = data[i].w_float; + } + x->table = newtable; + aubio_sampler_set_table(x->o, x->table); + if (oldtable) del_fvec(oldtable); +#endif + garray_usedindsp(a); + } +} + void aubiosampler_tilde_float(t_aubiosampler_tilde *x, t_floatarg f) { if (f == 3) { @@ -161,6 +205,8 @@ aubiosampler_tilde_setup (void) (t_method)aubiosampler_tilde_open, gensym ("open"), A_GIMME, 0); class_addmethod (aubiosampler_tilde_class, (t_method)aubiosampler_tilde_seek, gensym ("seek"), A_DEFFLOAT, 0); + class_addmethod(aubiosampler_tilde_class, + (t_method)aubiosampler_tilde_set_table, gensym("set"), A_SYMBOL, 0); class_addmethod (aubiosampler_tilde_class, (t_method)aubiosampler_tilde_dsp, gensym ("dsp"), A_CANT, 0); }