Changeset 4cab19e
- Timestamp:
- Jul 22, 2006, 11:44:15 AM (18 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:
- 4e9101e
- Parents:
- fc5bc72
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
plugins/puredata/aubiotempo~.c
rfc5bc72 r4cab19e 11 11 #include <aubio.h> 12 12 13 char aubiotempo_version[] = "aubiotempo~ version 0. 1";13 char aubiotempo_version[] = "aubiotempo~ version 0.2"; 14 14 15 15 static t_class *aubiotempo_tilde_class; … … 19 19 typedef struct _aubiotempo_tilde 20 20 { 21 t_object x_obj; 22 t_float threshold; 23 t_float threshold2; 24 t_int pos; /*frames%dspblocksize*/ 25 t_int bufsize; 26 t_int hopsize; 27 t_int pos2; 28 t_int winlen; 29 t_int step; 30 aubio_onsetdetection_t *o; 31 aubio_pvoc_t * pv; 32 aubio_pickpeak_t * parms; 33 aubio_beattracking_t * bt; 34 fvec_t *out; 35 fvec_t *dfframe; 36 fvec_t *vec; 37 fvec_t *onset; 38 cvec_t *fftgrain; 39 t_outlet *tempobang; 40 t_outlet *onsetbang; 21 t_object x_obj; 22 t_float threshold; 23 t_float silence; 24 t_int pos; /*frames%dspblocksize*/ 25 t_int bufsize; 26 t_int hopsize; 27 aubio_tempo_t * t; 28 fvec_t *vec; 29 fvec_t *output; 30 t_outlet *tempobang; 31 t_outlet *onsetbang; 41 32 } t_aubiotempo_tilde; 42 33 43 34 static t_int *aubiotempo_tilde_perform(t_int *w) 44 35 { 45 t_aubiotempo_tilde *x = (t_aubiotempo_tilde *)(w[1]); 46 t_sample *in = (t_sample *)(w[2]); 47 int n = (int)(w[3]); 48 int winlen = x->winlen; 49 int step = x->step; 50 int j,i,isonset,istactus; 51 smpl_t * btoutput = x->out->data[0]; 52 for (j=0;j<n;j++) { 53 /* write input to datanew */ 54 fvec_write_sample(x->vec, in[j], 0, x->pos); 55 /*time for fft*/ 56 if (x->pos == x->hopsize-1) { 57 /* block loop */ 58 aubio_pvoc_do (x->pv,x->vec, x->fftgrain); 59 aubio_onsetdetection(x->o,x->fftgrain, x->onset); 60 if (x->pos2 == step -1 ) { 61 aubio_beattracking_do(x->bt,x->dfframe,x->out); 62 /* rotate dfframe */ 63 for (i = 0 ; i < winlen - step; i++ ) 64 x->dfframe->data[0][i] = x->dfframe->data[0][i+step]; 65 for (i = winlen - step ; i < winlen; i++ ) 66 x->dfframe->data[0][i] = 0.; 67 x->pos2 = -1; 68 } 69 x->pos2++; 70 isonset = aubio_peakpick_pimrt_wt(x->onset,x->parms,&(x->dfframe->data[0][winlen - step + x->pos2])); 71 /* end of second level loop */ 72 istactus = 0; 73 i=0; 74 for (i = 1; i < btoutput[0]; i++ ) { 75 /* test for silence */ 76 if (aubio_silence_detection(x->vec, x->threshold2)==1) { 77 isonset = 0; istactus = 0; 78 } else { 79 if (x->pos2 == btoutput[i]) { 80 outlet_bang(x->tempobang); 81 } 82 if (isonset) { 83 outlet_bang(x->onsetbang); 84 } 85 } 86 } 87 88 /* end of block loop */ 89 x->pos = -1; /* so it will be zero next j loop */ 90 } 91 x->pos++; 92 } 93 return (w+4); 36 t_aubiotempo_tilde *x = (t_aubiotempo_tilde *)(w[1]); 37 t_sample *in = (t_sample *)(w[2]); 38 int n = (int)(w[3]); 39 int j; 40 for (j=0;j<n;j++) { 41 /* write input to datanew */ 42 fvec_write_sample(x->vec, in[j], 0, x->pos); 43 /*time for fft*/ 44 if (x->pos == x->hopsize-1) { 45 /* block loop */ 46 aubio_tempo (x->t, x->vec, x->output); 47 if (x->output->data[0][0]) { 48 outlet_bang(x->tempobang); 49 } 50 if (x->output->data[0][1]) { 51 outlet_bang(x->onsetbang); 52 } 53 /* end of block loop */ 54 x->pos = -1; /* so it will be zero next j loop */ 55 } 56 x->pos++; 57 } 58 return (w+4); 94 59 } 95 60 96 61 static void aubiotempo_tilde_dsp(t_aubiotempo_tilde *x, t_signal **sp) 97 62 { 98 63 dsp_add(aubiotempo_tilde_perform, 3, x, sp[0]->s_vec, sp[0]->s_n); 99 64 } 100 65 101 66 static void aubiotempo_tilde_debug(t_aubiotempo_tilde *x) 102 67 { 103 post("aubiotempo~ bufsize:\t%d", x->bufsize); 104 post("aubiotempo~ hopsize:\t%d", x->hopsize); 105 post("aubiotempo~ threshold:\t%f", x->threshold); 106 post("aubiotempo~ audio in:\t%f", x->vec->data[0][0]); 107 post("aubiotempo~ onset:\t%f", x->onset->data[0][0]); 68 post("aubiotempo~ bufsize:\t%d", x->bufsize); 69 post("aubiotempo~ hopsize:\t%d", x->hopsize); 70 post("aubiotempo~ threshold:\t%f", x->threshold); 71 post("aubiotempo~ audio in:\t%f", x->vec->data[0][0]); 108 72 } 109 73 110 74 static void *aubiotempo_tilde_new (t_floatarg f) 111 75 { 112 113 76 t_aubiotempo_tilde *x = 77 (t_aubiotempo_tilde *)pd_new(aubiotempo_tilde_class); 114 78 115 x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f; 116 x->threshold2 = -70.; 117 /* should get from block~ size */ 118 x->bufsize = 1024; 119 x->hopsize = x->bufsize / 2; 120 x->winlen = 512*512/x->hopsize; 121 x->step = x->winlen/4; 79 x->threshold = (f < 1e-5) ? 0.1 : (f > 10.) ? 10. : f; 80 x->silence = -70.; 81 /* should get from block~ size */ 82 x->bufsize = 1024; 83 x->hopsize = x->bufsize / 2; 122 84 123 x->o = new_aubio_onsetdetection(aubio_onset_complex, x->bufsize, 1); 124 x->vec = (fvec_t *)new_fvec(x->hopsize,1); 125 x->pv = (aubio_pvoc_t *)new_aubio_pvoc(x->bufsize, x->hopsize, 1); 126 x->fftgrain = (cvec_t *)new_cvec(x->bufsize,1); 127 x->onset = (fvec_t *)new_fvec(1,1); 128 x->parms = new_aubio_peakpicker(x->threshold); 129 x->bt = (aubio_beattracking_t *)new_aubio_beattracking(x->winlen,1); 130 x->dfframe = (fvec_t *)new_fvec(x->winlen,1); 131 x->out = (fvec_t *)new_fvec(x->step,1); 85 x->t = new_aubio_tempo (aubio_onset_complex, x->bufsize, x->hopsize, 1); 86 aubio_tempo_set_silence(x->t,x->silence); 87 aubio_tempo_set_threshold(x->t,x->threshold); 88 x->output = (fvec_t *)new_fvec(2,1); 89 x->vec = (fvec_t *)new_fvec(x->hopsize,1); 132 90 133 floatinlet_new (&x->x_obj, &x->threshold); 134 x->tempobang = outlet_new (&x->x_obj, &s_bang); 135 x->onsetbang = outlet_new (&x->x_obj, &s_bang); 136 post(aubiotempo_version); 137 return (void *)x; 91 floatinlet_new (&x->x_obj, &x->threshold); 92 x->tempobang = outlet_new (&x->x_obj, &s_bang); 93 x->onsetbang = outlet_new (&x->x_obj, &s_bang); 94 post(aubiotempo_version); 95 return (void *)x; 96 } 97 98 static void *aubiotempo_tilde_del(t_aubiotempo_tilde *x) 99 { 100 if(x->t) del_aubio_tempo(x->t); 101 if(x->output) del_fvec(x->output); 102 if(x->vec) del_fvec(x->vec); 103 return 0; 138 104 } 139 105 140 106 void aubiotempo_tilde_setup (void) 141 107 { 142 aubiotempo_tilde_class = class_new (gensym ("aubiotempo~"), 143 (t_newmethod)aubiotempo_tilde_new, 144 0, sizeof (t_aubiotempo_tilde), 145 CLASS_DEFAULT, A_DEFFLOAT, 0); 146 class_addmethod(aubiotempo_tilde_class, 147 (t_method)aubiotempo_tilde_dsp, 148 gensym("dsp"), 0); 149 class_addmethod(aubiotempo_tilde_class, 150 (t_method)aubiotempo_tilde_debug, 151 gensym("debug"), 0); 152 CLASS_MAINSIGNALIN(aubiotempo_tilde_class, 153 t_aubiotempo_tilde, threshold); 108 aubiotempo_tilde_class = class_new (gensym ("aubiotempo~"), 109 (t_newmethod)aubiotempo_tilde_new, 110 (t_method)aubiotempo_tilde_del, 111 sizeof (t_aubiotempo_tilde), 112 CLASS_DEFAULT, A_DEFFLOAT, 0); 113 class_addmethod(aubiotempo_tilde_class, 114 (t_method)aubiotempo_tilde_dsp, 115 gensym("dsp"), 0); 116 class_addmethod(aubiotempo_tilde_class, 117 (t_method)aubiotempo_tilde_debug, 118 gensym("debug"), 0); 119 CLASS_MAINSIGNALIN(aubiotempo_tilde_class, 120 t_aubiotempo_tilde, threshold); 154 121 } 155 122
Note: See TracChangeset
for help on using the changeset viewer.