Changeset f5e0a54 for src/onset/onset.c


Ignore:
Timestamp:
Mar 15, 2013, 10:24:00 PM (12 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, pitchshift, sampler, timestretch, yinfft+
Children:
35f73b8c
Parents:
376946a
Message:

src/onset/onset.c: add get_last_onset

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    r376946a rf5e0a54  
    3131struct _aubio_onset_t {
    3232  aubio_pvoc_t * pv;            /**< phase vocoder */
    33   aubio_specdesc_t * od;  /**< onset detection */
     33  aubio_specdesc_t * od;        /**< onset description function */
    3434  aubio_peakpicker_t * pp;      /**< peak picker */
    3535  cvec_t * fftgrain;            /**< phase vocoder output */
     
    3838  smpl_t silence;               /**< silence threhsold */
    3939  uint_t minioi;                /**< minimum inter onset interval */
    40   fvec_t * wasonset;            /**< number of frames since last onset */
     40  uint_t delay;                 /**< constant delay, in samples, removed from detected onset times */
     41  fvec_t * wasonset;            /**< number of blocks since last onset */
    4142  uint_t samplerate;            /**< sampling rate of the input signal */
    42   uint_t hop_size;              /**< number of samples between two runs */
     43  uint_t hop_size;              /**< number of samples between two runs */
     44
     45  uint_t total_frames;          /**< total number of frames processed since the beginning */
     46  uint_t last_onset;            /**< last detected onset location, in frames */
    4347};
    4448
     
    6064      if (wasonset > o->minioi) {
    6165        wasonset = 0;
     66        o->last_onset = o->total_frames + isonset * o->hop_size;
    6267      } else {
    6368        isonset  = 0;
     
    6974      //AUBIO_MSG("beginning of file is not silent, marking as onset\n",
    7075      //  wasonset, aubio_silence_detection(input, o->silence));
    71       isonset = 4;
     76      isonset = o->delay / o->hop_size;
     77      o->last_onset = o->delay;
    7278      wasonset = 0;
    7379    }
     
    7581  }
    7682  o->wasonset->data[0] = wasonset;
     83  //onset->data[0] = isonset * o->hop_size - o->delay;
    7784  onset->data[0] = isonset;
     85  // also keep a copy of the offset for use in get_last_onset
     86  o->total_frames += o->hop_size;
    7887  return;
    7988}
    8089
     90smpl_t aubio_onset_get_last_onset (aubio_onset_t *o)
     91{
     92  return o->last_onset - o->delay;
     93}
     94
     95smpl_t aubio_onset_get_last_onset_s (aubio_onset_t *o)
     96{
     97  return aubio_onset_get_last_onset (o) / (smpl_t) (o->samplerate);
     98}
     99
     100smpl_t aubio_onset_get_last_onset_ms (aubio_onset_t *o)
     101{
     102  return aubio_onset_get_last_onset_s (o) / 1000.;
     103}
     104
    81105smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
    82     return o->of->data[0];
     106  return o->of->data[0];
    83107}
    84108
    85109smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
    86     fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    87     return thresholded->data[0];
     110  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
     111  return thresholded->data[0];
    88112}
    89113
     
    104128}
    105129
     130uint_t aubio_onset_get_minioi(aubio_onset_t * o) {
     131  return o->minioi;
     132}
     133
     134uint_t aubio_onset_set_delay(aubio_onset_t * o, uint_t delay) {
     135  o->delay = delay;
     136  return AUBIO_OK;
     137}
     138
     139uint_t aubio_onset_get_delay(aubio_onset_t * o) {
     140  return o->delay;
     141}
     142
     143uint_t aubio_onset_set_delay_s(aubio_onset_t * o, smpl_t delay) {
     144  return aubio_onset_set_delay (o, delay * o->samplerate);
     145}
     146
     147smpl_t aubio_onset_get_delay_s(aubio_onset_t * o) {
     148  return aubio_onset_get_delay (o) / (smpl_t) o->samplerate;
     149}
     150
     151uint_t aubio_onset_set_delay_ms(aubio_onset_t * o, smpl_t delay) {
     152  return aubio_onset_set_delay_s (o, delay / 1000.);
     153}
     154
     155smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o) {
     156  return aubio_onset_get_delay_s (o) * 1000.;
     157}
     158
    106159/* Allocate memory for an onset detection */
    107160aubio_onset_t * new_aubio_onset (char_t * onset_mode,
     
    110163  aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
    111164  /** set some default parameter */
     165  o->last_onset = 0;
    112166  o->threshold = 0.3;
    113   o->minioi    = 4;
     167  o->delay     = 4.3 * hop_size;
     168  o->minioi    = 5;
    114169  o->silence   = -70;
    115170  o->wasonset  = new_fvec(1);
    116171  o->wasonset->data[0] = -1.;
     172  o->total_frames = 0;
    117173  o->samplerate = samplerate;
    118174  o->hop_size = hop_size;
Note: See TracChangeset for help on using the changeset viewer.