- Timestamp:
- Dec 4, 2009, 1:34:44 AM (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:
- d95ff38
- Parents:
- 66fb3ea
- Location:
- src/onset
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/onset/onset.c
r66fb3ea r0b9a02a 48 48 smpl_t isonset = 0; 49 49 smpl_t wasonset = 0; 50 uint_t i;51 50 aubio_pvoc_do (o->pv,input, o->fftgrain); 52 51 aubio_specdesc_do (o->od,o->fftgrain, o->of); 53 /*if (usedoubled) {54 aubio_specdesc_do (o2,fftgrain, onset2);55 onset->data[0][0] *= onset2->data[0][0];56 }*/57 52 aubio_peakpicker_do(o->pp, o->of, onset); 58 for (i = 0; i < input->channels; i++) { 59 isonset = onset->data[i][0]; 60 wasonset = o->wasonset->data[i][0]; 53 isonset = onset->data[0]; 54 wasonset = o->wasonset->data[0]; 61 55 if (isonset > 0.) { 62 56 if (aubio_silence_detection(input, o->silence)==1) { … … 74 68 wasonset++; 75 69 } 76 o->wasonset->data[i][0] = wasonset; 77 onset->data[i][0] = isonset; 78 } 70 o->wasonset->data[0] = wasonset; 71 onset->data[0] = isonset; 79 72 return; 80 73 } … … 98 91 /* Allocate memory for an onset detection */ 99 92 aubio_onset_t * new_aubio_onset (char_t * onset_mode, 100 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate)93 uint_t buf_size, uint_t hop_size, uint_t samplerate) 101 94 { 102 95 aubio_onset_t * o = AUBIO_NEW(aubio_onset_t); … … 105 98 o->minioi = 4; 106 99 o->silence = -70; 107 o->wasonset = new_fvec(1 , channels);100 o->wasonset = new_fvec(1); 108 101 o->samplerate = samplerate; 109 102 o->hop_size = hop_size; 110 o->pv = new_aubio_pvoc(buf_size, hop_size , channels);111 o->pp = new_aubio_peakpicker( channels);103 o->pv = new_aubio_pvoc(buf_size, hop_size); 104 o->pp = new_aubio_peakpicker(); 112 105 aubio_peakpicker_set_threshold (o->pp, o->threshold); 113 o->od = new_aubio_specdesc(onset_mode,buf_size ,channels);114 o->fftgrain = new_cvec(buf_size ,channels);115 o->of = new_fvec(1 , channels);106 o->od = new_aubio_specdesc(onset_mode,buf_size); 107 o->fftgrain = new_cvec(buf_size); 108 o->of = new_fvec(1); 116 109 /*if (usedoubled) { 117 o2 = new_aubio_specdesc(onset_type2,buffer_size ,channels);118 onset2 = new_fvec(1 , channels);110 o2 = new_aubio_specdesc(onset_type2,buffer_size); 111 onset2 = new_fvec(1); 119 112 }*/ 120 113 return o; -
src/onset/onset.h
r66fb3ea r0b9a02a 50 50 \param buf_size buffer size for phase vocoder 51 51 \param hop_size hop size for phase vocoder 52 \param channels number of channels53 52 \param samplerate sampling rate of the input signal 54 53 55 54 */ 56 55 aubio_onset_t * new_aubio_onset (char_t * method, 57 uint_t buf_size, uint_t hop_size, uint_t channels, uint_tsamplerate);56 uint_t buf_size, uint_t hop_size, uint_t samplerate); 58 57 59 58 /** execute onset detection -
src/onset/peakpicker.c
r66fb3ea r0b9a02a 28 28 29 29 /** function pointer to thresholding function */ 30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input , uint_t channel);30 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input); 31 31 /** function pointer to peak-picking function */ 32 32 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); … … 69 69 fvec_t *scratch; 70 70 71 /** number of channels to analyse */72 uint_t channels;73 74 71 /** \bug should be used to calculate filter coefficients */ 75 72 /* cutoff: low-pass filter cutoff [0.34, 1] */ … … 97 94 smpl_t mean = 0., median = 0.; 98 95 uint_t length = p->win_post + p->win_pre + 1; 99 uint_t i, j = 0; 100 101 for (i = 0; i < p->channels; i++) { 102 /* store onset in onset_keep */ 103 /* shift all elements but last, then write last */ 104 for (j = 0; j < length - 1; j++) { 105 onset_keep->data[i][j] = onset_keep->data[i][j + 1]; 106 onset_proc->data[i][j] = onset_keep->data[i][j]; 107 } 108 onset_keep->data[i][length - 1] = onset->data[i][0]; 109 onset_proc->data[i][length - 1] = onset->data[i][0]; 96 uint_t j = 0; 97 98 /* store onset in onset_keep */ 99 /* shift all elements but last, then write last */ 100 for (j = 0; j < length - 1; j++) { 101 onset_keep->data[j] = onset_keep->data[j + 1]; 102 onset_proc->data[j] = onset_keep->data[j]; 110 103 } 104 onset_keep->data[length - 1] = onset->data[0]; 105 onset_proc->data[length - 1] = onset->data[0]; 111 106 112 107 /* filter onset_proc */ … … 114 109 aubio_filter_do_filtfilt (p->biquad, onset_proc, scratch); 115 110 116 for (i = 0; i < p->channels; i++) { 117 /* calculate mean and median for onset_proc */ 118 mean = fvec_mean_channel (onset_proc, i); 119 /* copy to scratch */ 120 for (j = 0; j < length; j++) 121 scratch->data[i][j] = onset_proc->data[i][j]; 122 median = p->thresholdfn (scratch, i); 123 124 /* shift peek array */ 125 for (j = 0; j < 3 - 1; j++) 126 onset_peek->data[i][j] = onset_peek->data[i][j + 1]; 127 /* calculate new tresholded value */ 128 thresholded->data[i][0] = 129 onset_proc->data[i][p->win_post] - median - mean * p->threshold; 130 onset_peek->data[i][2] = thresholded->data[i][0]; 131 out->data[i][0] = (p->pickerfn) (onset_peek, 1); 132 if (out->data[i][0]) { 133 out->data[i][0] = fvec_quadint (onset_peek, 1, i); 134 } 111 /* calculate mean and median for onset_proc */ 112 mean = fvec_mean (onset_proc); 113 /* copy to scratch */ 114 for (j = 0; j < length; j++) 115 scratch->data[j] = onset_proc->data[j]; 116 median = p->thresholdfn (scratch); 117 118 /* shift peek array */ 119 for (j = 0; j < 3 - 1; j++) 120 onset_peek->data[j] = onset_peek->data[j + 1]; 121 /* calculate new tresholded value */ 122 thresholded->data[0] = 123 onset_proc->data[p->win_post] - median - mean * p->threshold; 124 onset_peek->data[2] = thresholded->data[0]; 125 out->data[0] = (p->pickerfn) (onset_peek, 1); 126 if (out->data[0]) { 127 out->data[0] = fvec_quadint (onset_peek, 1); 135 128 } 136 129 } … … 173 166 174 167 aubio_peakpicker_t * 175 new_aubio_peakpicker ( uint_t channels)168 new_aubio_peakpicker () 176 169 { 177 170 aubio_peakpicker_t *t = AUBIO_NEW (aubio_peakpicker_t); … … 179 172 t->win_post = 5; 180 173 t->win_pre = 1; 181 //channels = 1; 182 t->channels = channels; 183 184 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median_channel); /* (fvec_mean); */ 174 175 t->thresholdfn = (aubio_thresholdfn_t) (fvec_median); /* (fvec_mean); */ 185 176 t->pickerfn = (aubio_pickerfn_t) (fvec_peakpick); 186 177 187 t->scratch = new_fvec (t->win_post + t->win_pre + 1 , channels);188 t->onset_keep = new_fvec (t->win_post + t->win_pre + 1 , channels);189 t->onset_proc = new_fvec (t->win_post + t->win_pre + 1 , channels);190 t->onset_peek = new_fvec (3 , channels);191 t->thresholded = new_fvec (1 , channels);178 t->scratch = new_fvec (t->win_post + t->win_pre + 1); 179 t->onset_keep = new_fvec (t->win_post + t->win_pre + 1); 180 t->onset_proc = new_fvec (t->win_post + t->win_pre + 1); 181 t->onset_peek = new_fvec (3); 182 t->thresholded = new_fvec (1); 192 183 193 184 /* cutoff: low-pass filter with cutoff reduced frequency at 0.34 … … 195 186 */ 196 187 t->biquad = new_aubio_filter_biquad (0.15998789, 0.31997577, 0.15998789, 197 -0.59488894, 0.23484048 , channels);188 -0.59488894, 0.23484048); 198 189 199 190 return t; -
src/onset/peakpicker.h
r66fb3ea r0b9a02a 36 36 37 37 /** peak-picker creation function */ 38 aubio_peakpicker_t * new_aubio_peakpicker( uint_t channels);38 aubio_peakpicker_t * new_aubio_peakpicker(); 39 39 /** real time peak picking function */ 40 40 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out);
Note: See TracChangeset
for help on using the changeset viewer.