{
t_object x_obj;
t_float threshold;
+ char_t *method;
t_int pos; /*frames%dspblocksize */
t_int bufsize;
t_int hopsize;
aubio_onset_t *o;
fvec_t *in;
fvec_t *out;
+ t_inlet *inlet;
t_outlet *onsetbang;
} t_aubioonset_tilde;
static void
aubioonset_tilde_debug (t_aubioonset_tilde * x)
{
- post ("aubioonset~ bufsize:\t%d", x->bufsize);
- post ("aubioonset~ hopsize:\t%d", x->hopsize);
- post ("aubioonset~ threshold:\t%f", x->threshold);
- post ("aubioonset~ audio in:\t%f", x->in->data[0]);
- post ("aubioonset~ onset:\t%f", x->out->data[0]);
+ post ("%s method: %s threshold: %.3f bufsize: %d hopsize: %d",
+ aubioonset_version, x->method, x->threshold, x->bufsize, x->hopsize);
}
static void *
-aubioonset_tilde_new (t_floatarg f)
+aubioonset_tilde_new (t_symbol *s, int argc, t_atom *argv)
{
- t_aubioonset_tilde *x =
- (t_aubioonset_tilde *) pd_new (aubioonset_tilde_class);
+ t_aubioonset_tilde *x = (t_aubioonset_tilde *)pd_new(aubioonset_tilde_class);
- x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f;
+ x->threshold = -1;
x->bufsize = 1024;
+ x->method = "default";
+
+ if (argc >= 3) {
+ if (argv[2].a_type == A_FLOAT) {
+ x->bufsize = (uint_t)(argv[2].a_w.w_float);
+ }
+ argc--;
+ }
+
x->hopsize = x->bufsize / 2;
- x->o = new_aubio_onset ("complex",
+ if (argc == 3) {
+ if (argv[3].a_type == A_FLOAT) {
+ x->hopsize = (uint_t)(argv[3].a_w.w_float);
+ }
+ argc--;
+ }
+
+ // process 2 remaining arguments
+ // (can be 'method threshold' or 'threshold method')
+ while (argc > 0) {
+ if (argv->a_type == A_FLOAT) {
+ t_sample f = argv->a_w.w_float;
+ x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f;
+ } else if (argv->a_type == A_SYMBOL) {
+ x->method = argv->a_w.w_symbol->s_name;
+ }
+ argc--;
+ argv++;
+ }
+
+ x->o = new_aubio_onset (x->method,
x->bufsize, x->hopsize, (uint_t) sys_getsr ());
+
+ if (x->o == NULL) return NULL;
+
+ if (x->threshold != -1) {
+ aubio_onset_set_threshold(x->o, x->threshold);
+ }
+ x->threshold = aubio_onset_get_threshold(x->o);
+
x->in = (fvec_t *) new_fvec (x->hopsize);
x->out = (fvec_t *) new_fvec (1);
- floatinlet_new (&x->x_obj, &x->threshold);
+ x->inlet = floatinlet_new (&x->x_obj, &x->threshold);
x->onsetbang = outlet_new (&x->x_obj, &s_bang);
- post (aubioonset_version);
return (void *) x;
}
void
+aubioonset_tilde_del (t_aubioonset_tilde *x)
+{
+ inlet_free(x->inlet);
+ outlet_free(x->onsetbang);
+ del_aubio_onset(x->o);
+ del_fvec(x->in);
+ del_fvec(x->out);
+}
+
+void
aubioonset_tilde_setup (void)
{
aubioonset_tilde_class = class_new (gensym ("aubioonset~"),
(t_newmethod) aubioonset_tilde_new,
- 0, sizeof (t_aubioonset_tilde), CLASS_DEFAULT, A_DEFFLOAT, 0);
+ (t_method) aubioonset_tilde_del,
+ sizeof (t_aubioonset_tilde), CLASS_DEFAULT, A_GIMME, 0);
class_addmethod (aubioonset_tilde_class,
(t_method) aubioonset_tilde_dsp, gensym ("dsp"), 0);
class_addmethod (aubioonset_tilde_class,