Changeset b201912 for src/onset/onset.c
- Timestamp:
- Apr 11, 2017, 1:49:44 AM (7 years ago)
- Branches:
- sampler
- Children:
- 04d0c89
- Parents:
- fbafd2c (diff), b762f8d (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/onset/onset.c
rfbafd2c rb201912 24 24 #include "spectral/specdesc.h" 25 25 #include "spectral/phasevoc.h" 26 #include "spectral/awhitening.h" 26 27 #include "onset/peakpicker.h" 27 28 #include "mathutils.h" 28 29 #include "onset/onset.h" 30 31 void aubio_onset_default_parameters (aubio_onset_t *o, const char_t * method); 29 32 30 33 /** structure to store object state */ … … 43 46 uint_t total_frames; /**< total number of frames processed since the beginning */ 44 47 uint_t last_onset; /**< last detected onset location, in frames */ 48 49 uint_t apply_compression; 50 smpl_t lambda_compression; 51 uint_t apply_awhitening; /**< apply adaptive spectral whitening */ 52 aubio_spectral_whitening_t *spectral_whitening; 45 53 }; 46 54 … … 50 58 smpl_t isonset = 0; 51 59 aubio_pvoc_do (o->pv,input, o->fftgrain); 60 /* 61 if (apply_filtering) { 62 } 63 */ 64 if (o->apply_awhitening) { 65 aubio_spectral_whitening_do(o->spectral_whitening, o->fftgrain); 66 } 67 if (o->apply_compression) { 68 cvec_logmag(o->fftgrain, o->lambda_compression); 69 } 52 70 aubio_specdesc_do (o->od, o->fftgrain, o->desc); 53 71 aubio_peakpicker_do(o->pp, o->desc, onset); … … 58 76 isonset = 0; 59 77 } else { 78 // we have an onset 60 79 uint_t new_onset = o->total_frames + (uint_t)ROUND(isonset * o->hop_size); 80 // check if last onset time was more than minioi ago 61 81 if (o->last_onset + o->minioi < new_onset) { 62 //AUBIO_DBG ("accepted detection, marking as onset\n"); 63 o->last_onset = new_onset; 82 // start of file: make sure (new_onset - delay) >= 0 83 if (o->last_onset > 0 && o->delay > new_onset) { 84 isonset = 0; 85 } else { 86 //AUBIO_DBG ("accepted detection, marking as onset\n"); 87 o->last_onset = MAX(o->delay, new_onset); 88 } 64 89 } else { 65 90 //AUBIO_DBG ("doubled onset, not marking as onset\n"); … … 100 125 } 101 126 127 uint_t aubio_onset_set_awhitening (aubio_onset_t *o, uint_t enable) 128 { 129 o->apply_awhitening = enable == 1 ? 1 : 0; 130 return AUBIO_OK; 131 } 132 133 smpl_t aubio_onset_get_awhitening (aubio_onset_t *o) 134 { 135 return o->apply_awhitening; 136 } 137 138 uint_t aubio_onset_set_compression (aubio_onset_t *o, smpl_t lambda) 139 { 140 if (lambda < 0.) { 141 return AUBIO_FAIL; 142 } 143 o->lambda_compression = lambda; 144 o->apply_compression = (o->lambda_compression > 0.) ? 1 : 0; 145 return AUBIO_OK; 146 } 147 148 smpl_t aubio_onset_get_compression (aubio_onset_t *o) 149 { 150 return o->apply_compression ? o->lambda_compression : 0; 151 } 152 102 153 uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) { 103 154 o->silence = silence; … … 209 260 o->fftgrain = new_cvec(buf_size); 210 261 o->desc = new_fvec(1); 211 212 /* set some default parameter */ 213 aubio_onset_set_threshold (o, 0.3); 214 aubio_onset_set_delay(o, 4.3 * hop_size); 215 aubio_onset_set_minioi_ms(o, 20.); 216 aubio_onset_set_silence(o, -70.); 262 o->spectral_whitening = new_aubio_spectral_whitening(buf_size, hop_size, samplerate); 217 263 218 264 /* initialize internal variables */ 219 o->last_onset = 0; 220 o->total_frames = 0; 265 aubio_onset_set_default_parameters (o, onset_mode); 266 267 aubio_onset_reset(o); 221 268 return o; 222 269 … … 229 276 } 230 277 278 void aubio_onset_reset (aubio_onset_t *o) { 279 o->last_onset = 0; 280 o->total_frames = 0; 281 } 282 283 uint_t aubio_onset_set_default_parameters (aubio_onset_t * o, const char_t * onset_mode) 284 { 285 uint_t ret = AUBIO_OK; 286 /* set some default parameter */ 287 aubio_onset_set_threshold (o, 0.3); 288 aubio_onset_set_delay (o, 4.3 * o->hop_size); 289 aubio_onset_set_minioi_ms (o, 50.); 290 aubio_onset_set_silence (o, -70.); 291 // disable spectral whitening 292 aubio_onset_set_awhitening (o, 0); 293 // disable logarithmic magnitude 294 aubio_onset_set_compression (o, 0.); 295 296 /* method specific optimisations */ 297 if (strcmp (onset_mode, "energy") == 0) { 298 } else if (strcmp (onset_mode, "hfc") == 0 || strcmp (onset_mode, "default") == 0) { 299 aubio_onset_set_threshold (o, 0.058); 300 aubio_onset_set_compression (o, 1.); 301 } else if (strcmp (onset_mode, "complexdomain") == 0 302 || strcmp (onset_mode, "complex") == 0) { 303 aubio_onset_set_delay (o, 4.6 * o->hop_size); 304 aubio_onset_set_threshold (o, 0.15); 305 aubio_onset_set_awhitening(o, 1); 306 aubio_onset_set_compression (o, 1.); 307 } else if (strcmp (onset_mode, "phase") == 0) { 308 o->apply_compression = 0; 309 aubio_onset_set_awhitening (o, 0); 310 } else if (strcmp (onset_mode, "mkl") == 0) { 311 aubio_onset_set_threshold (o, 0.05); 312 aubio_onset_set_awhitening(o, 1); 313 aubio_onset_set_compression (o, 0.02); 314 } else if (strcmp (onset_mode, "kl") == 0) { 315 aubio_onset_set_threshold (o, 0.35); 316 aubio_onset_set_awhitening(o, 1); 317 aubio_onset_set_compression (o, 0.02); 318 } else if (strcmp (onset_mode, "specflux") == 0) { 319 aubio_onset_set_threshold (o, 0.18); 320 aubio_onset_set_awhitening(o, 1); 321 aubio_spectral_whitening_set_relax_time(o->spectral_whitening, 100); 322 aubio_spectral_whitening_set_floor(o->spectral_whitening, 1.); 323 aubio_onset_set_compression (o, 10.); 324 } else if (strcmp (onset_mode, "specdiff") == 0) { 325 } else if (strcmp (onset_mode, "old_default") == 0) { 326 // used to reproduce results obtained with the previous version 327 aubio_onset_set_threshold (o, 0.3); 328 aubio_onset_set_minioi_ms (o, 20.); 329 aubio_onset_set_compression (o, 0.); 330 } else { 331 AUBIO_WRN("onset: unknown spectral descriptor type %s, " 332 "using default parameters.\n", onset_mode); 333 ret = AUBIO_FAIL; 334 } 335 return ret; 336 } 337 231 338 void del_aubio_onset (aubio_onset_t *o) 232 339 { 340 del_aubio_spectral_whitening(o->spectral_whitening); 233 341 del_aubio_specdesc(o->od); 234 342 del_aubio_peakpicker(o->pp);
Note: See TracChangeset
for help on using the changeset viewer.