Changeset 3502119 for src/onset/onset.c


Ignore:
Timestamp:
Apr 5, 2017, 11:49:57 AM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, sampler
Children:
c3b1a7d
Parents:
0eca01f (diff), c82859f (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.
Message:

Merge branch 'awhitening'

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    r0eca01f r3502119  
    2424#include "spectral/specdesc.h"
    2525#include "spectral/phasevoc.h"
     26#include "spectral/awhitening.h"
    2627#include "onset/peakpicker.h"
    2728#include "mathutils.h"
    2829#include "onset/onset.h"
     30
     31void aubio_onset_default_parameters (aubio_onset_t *o, const char_t * method);
    2932
    3033/** structure to store object state */
     
    4346  uint_t total_frames;          /**< total number of frames processed since the beginning */
    4447  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;
    4553};
    4654
     
    5058  smpl_t isonset = 0;
    5159  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  }
    5270  aubio_specdesc_do (o->od, o->fftgrain, o->desc);
    5371  aubio_peakpicker_do(o->pp, o->desc, onset);
     
    5876      isonset  = 0;
    5977    } else {
     78      // we have an onset
    6079      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
    6181      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        }
    6489      } else {
    6590        //AUBIO_DBG ("doubled onset, not marking as onset\n");
     
    100125}
    101126
     127uint_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
     133smpl_t aubio_onset_get_awhitening (aubio_onset_t *o)
     134{
     135  return o->apply_awhitening;
     136}
     137
     138uint_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
     148smpl_t aubio_onset_get_compression (aubio_onset_t *o)
     149{
     150  return o->apply_compression ? o->lambda_compression : 0;
     151}
     152
    102153uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) {
    103154  o->silence = silence;
     
    209260  o->fftgrain = new_cvec(buf_size);
    210261  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);
    217263
    218264  /* 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);
    221268  return o;
    222269
     
    229276}
    230277
     278void aubio_onset_reset (aubio_onset_t *o) {
     279  o->last_onset = 0;
     280  o->total_frames = 0;
     281}
     282
     283uint_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
    231338void del_aubio_onset (aubio_onset_t *o)
    232339{
     340  del_aubio_spectral_whitening(o->spectral_whitening);
    233341  del_aubio_specdesc(o->od);
    234342  del_aubio_peakpicker(o->pp);
Note: See TracChangeset for help on using the changeset viewer.