Changeset 56ef7e1
- Timestamp:
- Oct 18, 2009, 3:08:59 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:
- e5f49af
- Parents:
- 74516f7
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/mathutils.c
r74516f7 r56ef7e1 142 142 143 143 smpl_t 144 fvec_mean_channel (fvec_t * s, uint_t i) 145 { 146 uint_t j; 147 smpl_t tmp = 0.0; 148 for (j = 0; j < s->length; j++) 149 tmp += s->data[i][j]; 150 return tmp / (smpl_t) (s->length); 151 } 152 153 smpl_t 144 154 fvec_sum (fvec_t * s) 145 155 { … … 289 299 290 300 void fvec_adapt_thres(fvec_t * vec, fvec_t * tmp, 291 uint_t post, uint_t pre ) {292 uint_t length = vec->length, i= 0, j;301 uint_t post, uint_t pre, uint_t channel) { 302 uint_t length = vec->length, i=channel, j; 293 303 for (j=0;j<length;j++) { 294 vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j );304 vec->data[i][j] -= fvec_moving_thres(vec, tmp, post, pre, j, i); 295 305 } 296 306 } … … 298 308 smpl_t 299 309 fvec_moving_thres (fvec_t * vec, fvec_t * tmpvec, 300 uint_t post, uint_t pre, uint_t pos )301 { 302 smpl_t *medar = (smpl_t *) tmpvec->data[0];303 uint_t k;310 uint_t post, uint_t pre, uint_t pos, uint_t channel) 311 { 312 uint_t i = channel, k; 313 smpl_t *medar = (smpl_t *) tmpvec->data[i]; 304 314 uint_t win_length = post + pre + 1; 305 315 uint_t length = vec->length; … … 321 331 medar[k] = 0.; /* 0-padding at the end */ 322 332 } 323 return fvec_median (tmpvec);324 } 325 326 smpl_t fvec_median (fvec_t * input) {333 return fvec_median_channel (tmpvec, i); 334 } 335 336 smpl_t fvec_median_channel (fvec_t * input, uint_t channel) { 327 337 uint_t n = input->length; 328 smpl_t * arr = (smpl_t *) input->data[ 0];338 smpl_t * arr = (smpl_t *) input->data[channel]; 329 339 uint_t low, high ; 330 340 uint_t median; … … 375 385 } 376 386 377 smpl_t fvec_quadint (fvec_t * x,uint_t pos, uint_t span) {387 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t i) { 378 388 smpl_t s0, s1, s2; 379 uint_t x0 = (pos < span) ? pos : pos - span;380 uint_t x2 = (pos + span < x->length) ? pos + span: pos;381 if (x0 == pos) return (x->data[ 0][pos] <= x->data[0][x2]) ? pos : x2;382 if (x2 == pos) return (x->data[ 0][pos] <= x->data[0][x0]) ? pos : x0;383 s0 = x->data[ 0][x0];384 s1 = x->data[ 0][pos];385 s2 = x->data[ 0][x2];389 uint_t x0 = (pos < 1) ? pos : pos - 1; 390 uint_t x2 = (pos + 1 < x->length) ? pos + 1 : pos; 391 if (x0 == pos) return (x->data[i][pos] <= x->data[i][x2]) ? pos : x2; 392 if (x2 == pos) return (x->data[i][pos] <= x->data[i][x0]) ? pos : x0; 393 s0 = x->data[i][x0]; 394 s1 = x->data[i][pos]; 395 s2 = x->data[i][x2]; 386 396 return pos + 0.5 * (s2 - s0 ) / (s2 - 2.* s1 + s0); 387 397 } -
src/mathutils.h
r74516f7 r56ef7e1 60 60 /** compute the mean of a vector 61 61 62 \param s vector to compute normfrom62 \param s vector to compute mean from 63 63 64 64 \return the mean of v … … 66 66 */ 67 67 smpl_t fvec_mean (fvec_t * s); 68 69 /** compute the mean of a vector channel 70 71 \param s vector to compute mean from 72 \param i channel to compute mean from 73 74 \return the mean of v 75 76 */ 77 smpl_t fvec_mean_channel (fvec_t * s, uint_t i); 68 78 69 79 /** find the max of a vector … … 220 230 */ 221 231 smpl_t fvec_moving_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre, 222 uint_t pos );232 uint_t pos, uint_t channel); 223 233 224 234 /** apply adaptive threshold to a vector … … 233 243 234 244 */ 235 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre); 245 void fvec_adapt_thres (fvec_t * v, fvec_t * tmp, uint_t post, uint_t pre, 246 uint_t channel); 236 247 237 248 /** returns the median of a vector … … 246 257 247 258 \param v vector to get median from 259 \param channel channel to get median from 248 260 249 261 \return the median of v 250 262 251 263 */ 252 smpl_t fvec_median (fvec_t * v);264 smpl_t fvec_median_channel (fvec_t * v, uint_t channel); 253 265 254 266 /** finds exact peak index by quadratic interpolation*/ 255 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t span);267 smpl_t fvec_quadint (fvec_t * x, uint_t pos, uint_t channel); 256 268 257 269 /** Quadratic interpolation using Lagrange polynomial. -
src/onset/onset.c
r74516f7 r56ef7e1 37 37 smpl_t silence; /**< silence threhsold */ 38 38 uint_t minioi; /**< minimum inter onset interval */ 39 uint_t wasonset;/**< number of frames since last onset */39 fvec_t * wasonset; /**< number of frames since last onset */ 40 40 uint_t samplerate; /**< sampling rate of the input signal */ 41 41 }; … … 44 44 void aubio_onset_do (aubio_onset_t *o, fvec_t * input, fvec_t * onset) 45 45 { 46 uint_t isonset = 0; 47 uint_t wasonset = o->wasonset; 46 smpl_t isonset = 0; 47 smpl_t wasonset = 0; 48 uint_t i; 48 49 aubio_pvoc_do (o->pv,input, o->fftgrain); 49 50 aubio_onsetdetection_do (o->od,o->fftgrain, o->of); … … 52 53 onset->data[0][0] *= onset2->data[0][0]; 53 54 }*/ 54 isonset = aubio_peakpicker_do(o->pp, o->of); 55 aubio_peakpicker_do(o->pp, o->of, onset); 56 for (i = 0; i < input->channels; i++) { 57 isonset = onset->data[i][0]; 58 wasonset = o->wasonset->data[i][0]; 55 59 if (isonset > 0.) { 56 60 if (aubio_silence_detection(input, o->silence)==1) { … … 68 72 wasonset++; 69 73 } 70 o->wasonset = wasonset; 71 onset->data[0][0] = isonset; 74 o->wasonset->data[i][0] = wasonset; 75 onset->data[i][0] = isonset; 76 } 72 77 return; 73 78 } … … 98 103 o->minioi = 4; 99 104 o->silence = -70; 100 o->wasonset = 0;105 o->wasonset = new_fvec(1, channels); 101 106 o->samplerate = samplerate; 102 107 o->pv = new_aubio_pvoc(buf_size, hop_size, channels); 103 o->pp = new_aubio_peakpicker(o->threshold); 108 o->pp = new_aubio_peakpicker(channels); 109 aubio_peakpicker_set_threshold (o->pp, o->threshold); 104 110 o->od = new_aubio_onsetdetection(onset_mode,buf_size,channels); 105 111 o->fftgrain = new_cvec(buf_size,channels); … … 118 124 del_aubio_pvoc(o->pv); 119 125 del_fvec(o->of); 126 del_fvec(o->wasonset); 120 127 del_cvec(o->fftgrain); 121 128 AUBIO_FREE(o); -
src/onset/peakpick.c
r74516f7 r56ef7e1 53 53 fvec_t * scratch; 54 54 55 /** number of channels to analyse */ 56 uint_t channels; 57 55 58 /** \bug should be used to calculate filter coefficients */ 56 59 /* cutoff: low-pass filter cutoff [0.34, 1] */ … … 68 71 * is slightly more permissive than the offline one, and yelds to an increase 69 72 * of false positives. best */ 70 smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * onset) { 71 fvec_t * onset_keep = (fvec_t *)p->onset_keep; 72 fvec_t * onset_proc = (fvec_t *)p->onset_proc; 73 fvec_t * onset_peek = (fvec_t *)p->onset_peek; 74 fvec_t * scratch = (fvec_t *)p->scratch; 75 smpl_t mean = 0., median = 0.; 76 smpl_t isonset = 0.; 77 uint_t length = p->win_post + p->win_pre + 1; 78 uint_t i = 0, j; 73 void 74 aubio_peakpicker_do (aubio_peakpicker_t * p, fvec_t * onset, fvec_t * out) 75 { 76 fvec_t *onset_keep = p->onset_keep; 77 fvec_t *onset_proc = p->onset_proc; 78 fvec_t *onset_peek = p->onset_peek; 79 fvec_t *scratch = p->scratch; 80 smpl_t mean = 0., median = 0.; 81 uint_t length = p->win_post + p->win_pre + 1; 82 uint_t i, j = 0; 79 83 80 /* store onset in onset_keep */ 81 /* shift all elements but last, then write last*/82 /* for (i=0;i<channels;i++) {*/83 for (j=0;j<length-1;j++) {84 onset_keep->data[i][j] = onset_keep->data[i][j+1];85 86 87 onset_keep->data[i][length-1] = onset->data[i][0];88 onset_proc->data[i][length-1] = onset->data[i][0];89 /* } */ 84 for (i = 0; i < p->channels; i++) { 85 /* store onset in onset_keep */ 86 /* shift all elements but last, then write last */ 87 for (j = 0; j < length - 1; j++) { 88 onset_keep->data[i][j] = onset_keep->data[i][j + 1]; 89 onset_proc->data[i][j] = onset_keep->data[i][j]; 90 } 91 onset_keep->data[i][length - 1] = onset->data[i][0]; 92 onset_proc->data[i][length - 1] = onset->data[i][0]; 93 } 90 94 91 92 93 95 /* filter onset_proc */ 96 /** \bug filtfilt calculated post+pre times, should be only once !? */ 97 //aubio_biquad_do_filtfilt(p->biquad,onset_proc,scratch); 94 98 95 /* calculate mean and median for onset_proc */ 96 /* for (i=0;i<onset_proc->channels;i++) { */ 97 mean = fvec_mean(onset_proc); 98 /* copy to scratch */ 99 for (j = 0; j < length; j++) 100 scratch->data[i][j] = onset_proc->data[i][j]; 101 median = p->thresholdfn(scratch); 102 /* } */ 99 for (i = 0; i < p->channels; i++) { 100 /* calculate mean and median for onset_proc */ 101 mean = fvec_mean_channel (onset_proc, i); 102 /* copy to scratch */ 103 for (j = 0; j < length; j++) 104 scratch->data[i][j] = onset_proc->data[i][j]; 105 median = p->thresholdfn (scratch, i); 103 106 104 /* for (i=0;i<onset->channels;i++) { */ 105 /* shift peek array */ 106 for (j=0;j<3-1;j++) 107 onset_peek->data[i][j] = onset_peek->data[i][j+1]; 108 /* calculate new peek value */ 109 onset_peek->data[i][2] = 110 onset_proc->data[i][p->win_post] - median - mean * p->threshold; 111 /* } */ 112 //AUBIO_DBG("%f\n", onset_peek->data[0][2]); 113 isonset = (p->pickerfn)(onset_peek,1); 114 if (isonset) { //(isonset) { 115 isonset = fvec_quadint(onset_peek, 1, 1); 107 /* shift peek array */ 108 for (j = 0; j < 3 - 1; j++) 109 onset_peek->data[i][j] = onset_peek->data[i][j + 1]; 110 /* calculate new peek value */ 111 onset_peek->data[i][2] = 112 onset_proc->data[i][p->win_post] - median - mean * p->threshold; 113 out->data[i][0] = (p->pickerfn) (onset_peek, 1); 114 if (out->data[i][0]) { 115 out->data[i][0] = fvec_quadint (onset_peek, 1, i); 116 } 116 117 } 117 return isonset;118 118 } 119 119 … … 126 126 } 127 127 128 /** function added by Miguel Ramirez to return the onset detection amplitude in peakval */129 128 uint_t aubio_peakpicker_set_threshold(aubio_peakpicker_t * p, smpl_t threshold) { 130 129 p->threshold = threshold; 131 130 return AUBIO_OK; 132 131 } … … 145 144 } 146 145 147 aubio_peakpicker_t * new_aubio_peakpicker( smpl_t threshold) {146 aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels) { 148 147 aubio_peakpicker_t * t = AUBIO_NEW(aubio_peakpicker_t); 149 148 t->threshold = 0.1; /* 0.0668; 0.33; 0.082; 0.033; */ 150 if (threshold > 0. && threshold < 10.)151 t->threshold = threshold;152 149 t->win_post = 5; 153 150 t->win_pre = 1; 151 //channels = 1; 152 t->channels = channels; 154 153 155 t->thresholdfn = (aubio_thresholdfn_t)(fvec_median ); /* (fvec_mean); */154 t->thresholdfn = (aubio_thresholdfn_t)(fvec_median_channel); /* (fvec_mean); */ 156 155 t->pickerfn = (aubio_pickerfn_t)(fvec_peakpick); 157 156 158 t->scratch = new_fvec(t->win_post+t->win_pre+1, 1);159 t->onset_keep = new_fvec(t->win_post+t->win_pre+1, 1);160 t->onset_proc = new_fvec(t->win_post+t->win_pre+1, 1);161 t->onset_peek = new_fvec(3, 1);157 t->scratch = new_fvec(t->win_post+t->win_pre+1, channels); 158 t->onset_keep = new_fvec(t->win_post+t->win_pre+1, channels); 159 t->onset_proc = new_fvec(t->win_post+t->win_pre+1, channels); 160 t->onset_peek = new_fvec(3, channels); 162 161 163 162 /* cutoff: low-pass filter cutoff [0.34, 1] */ -
src/onset/peakpick.h
r74516f7 r56ef7e1 32 32 33 33 /** function pointer to thresholding function */ 34 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input );34 typedef smpl_t (*aubio_thresholdfn_t)(fvec_t *input, uint_t channel); 35 35 /** function pointer to peak-picking function */ 36 36 typedef uint_t (*aubio_pickerfn_t)(fvec_t *input, uint_t pos); … … 39 39 40 40 /** peak-picker creation function */ 41 aubio_peakpicker_t * new_aubio_peakpicker( smpl_t threshold);41 aubio_peakpicker_t * new_aubio_peakpicker(uint_t channels); 42 42 /** real time peak picking function */ 43 smpl_t aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * DF);43 void aubio_peakpicker_do(aubio_peakpicker_t * p, fvec_t * in, fvec_t * out); 44 44 /** get current peak value */ 45 45 smpl_t aubio_peakpicker_get_thresholded_input(aubio_peakpicker_t * p); -
src/pitch/pitchmcomb.c
r74516f7 r56ef7e1 167 167 /* skipped */ /* low pass filtering */ 168 168 /** \bug fvec_moving_thres may write out of bounds */ 169 fvec_adapt_thres(mag,tmp,p->win_post,p->win_pre ); /* adaptative threshold */169 fvec_adapt_thres(mag,tmp,p->win_post,p->win_pre,i); /* adaptative threshold */ 170 170 fvec_add(mag,-p->threshold); /* fixed threshold */ 171 171 { … … 277 277 count += ispeak; 278 278 spectral_peaks[count-1].bin = j; 279 spectral_peaks[count-1].ebin = fvec_quadint(X, j, 1) - 1.;279 spectral_peaks[count-1].ebin = fvec_quadint(X, j, i) - 1.; 280 280 } 281 281 } -
src/pitch/pitchyin.c
r74516f7 r56ef7e1 149 149 if(tau > 4 && (yin->data[c][period] < tol) && 150 150 (yin->data[c][period] < yin->data[c][period+1])) { 151 out->data[c][0] = fvec_quadint(yin,period, 1);151 out->data[c][0] = fvec_quadint(yin,period,c); 152 152 goto beach; 153 153 } 154 154 } 155 out->data[c][0] = fvec_quadint(yin,fvec_min_elem(yin), 1);155 out->data[c][0] = fvec_quadint(yin,fvec_min_elem(yin),c); 156 156 beach: 157 157 continue; -
src/pitch/pitchyinfft.c
r74516f7 r56ef7e1 132 132 /* additional check for (unlikely) octave doubling in higher frequencies */ 133 133 if (tau>35) { 134 output->data[i][0] = fvec_quadint(yin,tau, 1);134 output->data[i][0] = fvec_quadint(yin,tau,i); 135 135 } else { 136 136 /* should compare the minimum value of each interpolated peaks */ 137 137 halfperiod = FLOOR(tau/2+.5); 138 138 if (yin->data[0][halfperiod] < p->tol) 139 output->data[i][0] = fvec_quadint(yin,halfperiod, 1);139 output->data[i][0] = fvec_quadint(yin,halfperiod,i); 140 140 else 141 output->data[i][0] = fvec_quadint(yin,tau, 1);141 output->data[i][0] = fvec_quadint(yin,tau,i); 142 142 } 143 143 } else { -
src/tempo/beattracking.c
r74516f7 r56ef7e1 170 170 /* find non-zero Rayleigh period */ 171 171 maxindex = fvec_max_elem (bt->acfout); 172 bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex, 1) : 1;172 bt->rp = maxindex ? fvec_quadint (bt->acfout, maxindex, 0) : 1; 173 173 //rp = (maxindex==127) ? 43 : maxindex; //rayparam 174 174 bt->rp = (maxindex == bt->acfout->length - 1) ? bt->rayparam : maxindex; //rayparam … … 203 203 phase = step - bt->lastbeat; 204 204 } else { 205 phase = fvec_quadint (bt->phout, maxindex, 1);205 phase = fvec_quadint (bt->phout, maxindex, 0); 206 206 } 207 207 /* take back one frame delay */ … … 305 305 } 306 306 fvec_weight (acfout, bt->gwv); 307 gp = fvec_quadint (acfout, fvec_max_elem (acfout), 1);307 gp = fvec_quadint (acfout, fvec_max_elem (acfout), 0); 308 308 /* 309 309 while(gp<32) gp =gp*2; … … 409 409 { 410 410 if (bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) { 411 return 5168. / fvec_quadint (bt->acfout, bt->bp, 1);411 return 5168. / fvec_quadint (bt->acfout, bt->bp, 0); 412 412 } else { 413 413 return 0.; -
src/tempo/tempo.c
r74516f7 r56ef7e1 38 38 fvec_t * dfframe; /** peak picked detection function buffer */ 39 39 fvec_t * out; /** beat tactus candidates */ 40 fvec_t * onset; /** onset results */ 41 fvec_t * peek; /** thresholded onset function */ 40 42 smpl_t silence; /** silence parameter */ 41 43 smpl_t threshold; /** peak picking threshold */ … … 70 72 } 71 73 o->blockpos++; 72 tempo->data[0][1] = aubio_peakpicker_do (o->pp, o->of); 74 aubio_peakpicker_do (o->pp, o->of, o->onset); 75 tempo->data[0][1] = o->onset->data[0][0]; 73 76 o->dfframe->data[0][winlen - step + o->blockpos] = 74 77 aubio_peakpicker_get_thresholded_input(o->pp); … … 115 118 o->out = new_fvec(o->step,channels); 116 119 o->pv = new_aubio_pvoc(buf_size, hop_size, channels); 117 o->pp = new_aubio_peakpicker(o->threshold); 120 o->pp = new_aubio_peakpicker(channels); 121 aubio_peakpicker_set_threshold (o->pp, o->threshold); 118 122 o->od = new_aubio_onsetdetection(onset_mode,buf_size,channels); 119 123 o->of = new_fvec(1, channels); 120 124 o->bt = new_aubio_beattracking(o->winlen,channels); 125 o->onset = new_fvec(1, channels); 126 o->peek = new_fvec(3, channels); 121 127 /*if (usedoubled) { 122 128 o2 = new_aubio_onsetdetection(type_onset2,buffer_size,channels); … … 144 150 del_cvec(o->fftgrain); 145 151 del_fvec(o->dfframe); 152 del_fvec(o->onset); 153 del_fvec(o->peek); 146 154 AUBIO_FREE(o); 147 155 return; -
tests/src/test-peakpick.c
r74516f7 r56ef7e1 6 6 uint_t channels = 1; /* number of channel */ 7 7 fvec_t * in = new_fvec (win_s, channels); /* input buffer */ 8 aubio_peakpicker_t * o = new_aubio_peakpicker(0.3); 8 fvec_t * out = new_fvec (1, channels); /* input buffer */ 9 aubio_peakpicker_t * o = new_aubio_peakpicker(1); 10 aubio_peakpicker_set_threshold (o, 0.3); 9 11 10 aubio_peakpicker_do(o, in );11 aubio_peakpicker_do(o, in );12 aubio_peakpicker_do(o, in );13 aubio_peakpicker_do(o, in );12 aubio_peakpicker_do(o, in, out); 13 aubio_peakpicker_do(o, in, out); 14 aubio_peakpicker_do(o, in, out); 15 aubio_peakpicker_do(o, in, out); 14 16 15 17 del_aubio_peakpicker(o);
Note: See TracChangeset
for help on using the changeset viewer.