Changeset 68b8233 for plugins/puredata
- Timestamp:
- Oct 16, 2009, 9:54:10 PM (15 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
- Children:
- d25bd12
- Parents:
- 970bced
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/puredata/aubioonset~.c
r970bced r68b8233 17 17 void aubioonset_tilde_setup (void); 18 18 19 typedef struct _aubioonset_tilde 19 typedef struct _aubioonset_tilde 20 20 { 21 22 t_float threshold; 23 t_int pos; /*frames%dspblocksize*/24 25 26 27 28 29 21 t_object x_obj; 22 t_float threshold; 23 t_int pos; /*frames%dspblocksize */ 24 t_int bufsize; 25 t_int hopsize; 26 aubio_onset_t *o; 27 fvec_t *in; 28 fvec_t *out; 29 t_outlet *onsetbang; 30 30 } t_aubioonset_tilde; 31 31 32 static t_int *aubioonset_tilde_perform(t_int *w) 32 static t_int * 33 aubioonset_tilde_perform (t_int * w) 33 34 { 34 t_aubioonset_tilde *x = (t_aubioonset_tilde *)(w[1]);35 t_sample *in = (t_sample *)(w[2]);36 int n = (int)(w[3]);37 38 for (j=0;j<n;j++) {39 40 fvec_write_sample(x->in, in[j], 0, x->pos);41 42 if (x->pos == x->hopsize-1) { 43 44 45 if (fvec_read_sample(x->out, 0, 0) > 0.) {46 outlet_bang(x->onsetbang);47 48 49 x->pos = -1;/* so it will be zero next j loop */50 51 52 53 return (w+4);35 t_aubioonset_tilde *x = (t_aubioonset_tilde *) (w[1]); 36 t_sample *in = (t_sample *) (w[2]); 37 int n = (int) (w[3]); 38 int j; 39 for (j = 0; j < n; j++) { 40 /* write input to datanew */ 41 fvec_write_sample (x->in, in[j], 0, x->pos); 42 /*time to do something */ 43 if (x->pos == x->hopsize - 1) { 44 /* block loop */ 45 aubio_onset_do (x->o, x->in, x->out); 46 if (fvec_read_sample (x->out, 0, 0) > 0.) { 47 outlet_bang (x->onsetbang); 48 } 49 /* end of block loop */ 50 x->pos = -1; /* so it will be zero next j loop */ 51 } 52 x->pos++; 53 } 54 return (w + 4); 54 55 } 55 56 56 static void aubioonset_tilde_dsp(t_aubioonset_tilde *x, t_signal **sp) 57 static void 58 aubioonset_tilde_dsp (t_aubioonset_tilde * x, t_signal ** sp) 57 59 { 58 dsp_add(aubioonset_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n);60 dsp_add (aubioonset_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); 59 61 } 60 62 61 static void aubioonset_tilde_debug(t_aubioonset_tilde *x) 63 static void 64 aubioonset_tilde_debug (t_aubioonset_tilde * x) 62 65 { 63 post("aubioonset~ bufsize:\t%d", x->bufsize);64 post("aubioonset~ hopsize:\t%d", x->hopsize);65 post("aubioonset~ threshold:\t%f", x->threshold);66 post("aubioonset~ audio in:\t%f", x->in->data[0][0]);67 post("aubioonset~ onset:\t%f", x->out->data[0][0]);66 post ("aubioonset~ bufsize:\t%d", x->bufsize); 67 post ("aubioonset~ hopsize:\t%d", x->hopsize); 68 post ("aubioonset~ threshold:\t%f", x->threshold); 69 post ("aubioonset~ audio in:\t%f", x->in->data[0][0]); 70 post ("aubioonset~ onset:\t%f", x->out->data[0][0]); 68 71 } 69 72 70 static void *aubioonset_tilde_new (t_floatarg f) 73 static void * 74 aubioonset_tilde_new (t_floatarg f) 71 75 { 72 t_aubioonset_tilde *x = 73 (t_aubioonset_tilde *)pd_new(aubioonset_tilde_class);76 t_aubioonset_tilde *x = 77 (t_aubioonset_tilde *) pd_new (aubioonset_tilde_class); 74 78 75 76 x->bufsize= 1024;77 x->hopsize= x->bufsize / 2;79 x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f; 80 x->bufsize = 1024; 81 x->hopsize = x->bufsize / 2; 78 82 79 80 x->bufsize, x->hopsize, 1, (uint_t)sys_getsr());81 x->in = (fvec_t *)new_fvec(x->hopsize,1);82 x->out = (fvec_t *)new_fvec(1,1);83 x->o = new_aubio_onset ("complex", 84 x->bufsize, x->hopsize, 1, (uint_t) sys_getsr ()); 85 x->in = (fvec_t *) new_fvec (x->hopsize, 1); 86 x->out = (fvec_t *) new_fvec (1, 1); 83 87 84 85 86 post(aubioonset_version);87 return (void *)x;88 floatinlet_new (&x->x_obj, &x->threshold); 89 x->onsetbang = outlet_new (&x->x_obj, &s_bang); 90 post (aubioonset_version); 91 return (void *) x; 88 92 } 89 93 90 void aubioonset_tilde_setup (void) 94 void 95 aubioonset_tilde_setup (void) 91 96 { 92 aubioonset_tilde_class = class_new (gensym ("aubioonset~"), 93 (t_newmethod)aubioonset_tilde_new, 94 0, sizeof (t_aubioonset_tilde), 95 CLASS_DEFAULT, A_DEFFLOAT, 0); 96 class_addmethod(aubioonset_tilde_class, 97 (t_method)aubioonset_tilde_dsp, 98 gensym("dsp"), 0); 99 class_addmethod(aubioonset_tilde_class, 100 (t_method)aubioonset_tilde_debug, 101 gensym("debug"), 0); 102 CLASS_MAINSIGNALIN(aubioonset_tilde_class, 103 t_aubioonset_tilde, threshold); 97 aubioonset_tilde_class = class_new (gensym ("aubioonset~"), 98 (t_newmethod) aubioonset_tilde_new, 99 0, sizeof (t_aubioonset_tilde), CLASS_DEFAULT, A_DEFFLOAT, 0); 100 class_addmethod (aubioonset_tilde_class, 101 (t_method) aubioonset_tilde_dsp, gensym ("dsp"), 0); 102 class_addmethod (aubioonset_tilde_class, 103 (t_method) aubioonset_tilde_debug, gensym ("debug"), 0); 104 CLASS_MAINSIGNALIN (aubioonset_tilde_class, t_aubioonset_tilde, threshold); 104 105 } 105
Note: See TracChangeset
for help on using the changeset viewer.