Changeset 35f73b8c


Ignore:
Timestamp:
Mar 15, 2013, 11:48:10 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:
7e9e311
Parents:
f5e0a54
Message:

src/onset/: remove wasonset, add getters and setters, improve doc

Location:
src/onset
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/onset/onset.c

    rf5e0a54 r35f73b8c  
    3939  uint_t minioi;                /**< minimum inter onset interval */
    4040  uint_t delay;                 /**< constant delay, in samples, removed from detected onset times */
    41   fvec_t * wasonset;            /**< number of blocks since last onset */
    4241  uint_t samplerate;            /**< sampling rate of the input signal */
    4342  uint_t hop_size;              /**< number of samples between two runs */
     
    5150{
    5251  smpl_t isonset = 0;
    53   smpl_t wasonset = 0;
    5452  aubio_pvoc_do (o->pv,input, o->fftgrain);
    5553  aubio_specdesc_do (o->od,o->fftgrain, o->of);
    5654  aubio_peakpicker_do(o->pp, o->of, onset);
    5755  isonset = onset->data[0];
    58   wasonset = o->wasonset->data[0];
    5956  if (isonset > 0.) {
    6057    if (aubio_silence_detection(input, o->silence)==1) {
    6158      isonset  = 0;
    62       wasonset++;
    6359    } else {
    64       if (wasonset > o->minioi) {
    65         wasonset = 0;
    66         o->last_onset = o->total_frames + isonset * o->hop_size;
     60      uint_t new_onset = o->total_frames + isonset * o->hop_size;
     61      if (o->last_onset + o->minioi < new_onset) {
     62        o->last_onset = new_onset;
    6763      } else {
    6864        isonset  = 0;
    69         wasonset++;
    7065      }
    7166    }
    7267  } else {
    73     if (wasonset == -1 && aubio_silence_detection(input, o->silence) == 0) {
    74       //AUBIO_MSG("beginning of file is not silent, marking as onset\n",
    75       //  wasonset, aubio_silence_detection(input, o->silence));
     68    // we are at the beginning of the file, and we don't find silence
     69    if (o->total_frames == 0 && aubio_silence_detection(input, o->silence) == 0) {
     70      //AUBIO_DBG ("beginning of file is not silent, marking as onset\n");
    7671      isonset = o->delay / o->hop_size;
    7772      o->last_onset = o->delay;
    78       wasonset = 0;
    7973    }
    80     wasonset++;
    8174  }
    82   o->wasonset->data[0] = wasonset;
    83   //onset->data[0] = isonset * o->hop_size - o->delay;
    8475  onset->data[0] = isonset;
    85   // also keep a copy of the offset for use in get_last_onset
    8676  o->total_frames += o->hop_size;
    8777  return;
     
    10393}
    10494
    105 smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
    106   return o->of->data[0];
    107 }
    108 
    109 smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
    110   fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
    111   return thresholded->data[0];
    112 }
    113 
    11495uint_t aubio_onset_set_silence(aubio_onset_t * o, smpl_t silence) {
    11596  o->silence = silence;
     
    124105
    125106uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi) {
    126   o->minioi = FLOOR(minioi / 1000. * o->samplerate / o->hop_size);
     107  o->minioi = minioi;
    127108  return AUBIO_OK;
    128109}
     
    130111uint_t aubio_onset_get_minioi(aubio_onset_t * o) {
    131112  return o->minioi;
     113}
     114
     115uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi) {
     116  return aubio_onset_set_minioi (o, minioi * o->samplerate);
     117}
     118
     119smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o) {
     120  return aubio_onset_get_minioi (o) / (smpl_t) o->samplerate;
     121}
     122
     123uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi) {
     124  return aubio_onset_set_minioi_s (o, minioi / 1000.);
     125}
     126
     127smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o) {
     128  return aubio_onset_get_minioi_s (o) * 1000.;
    132129}
    133130
     
    157154}
    158155
     156smpl_t aubio_onset_get_descriptor(aubio_onset_t * o) {
     157  return o->of->data[0];
     158}
     159
     160smpl_t aubio_onset_get_thresholded_descriptor(aubio_onset_t * o) {
     161  fvec_t * thresholded = aubio_peakpicker_get_thresholded_input(o->pp);
     162  return thresholded->data[0];
     163}
     164
    159165/* Allocate memory for an onset detection */
    160166aubio_onset_t * new_aubio_onset (char_t * onset_mode,
     
    163169  aubio_onset_t * o = AUBIO_NEW(aubio_onset_t);
    164170  /** set some default parameter */
     171  o->samplerate = samplerate;
     172  o->hop_size = hop_size;
    165173  o->last_onset = 0;
    166174  o->threshold = 0.3;
    167175  o->delay     = 4.3 * hop_size;
    168   o->minioi    = 5;
     176  o->minioi    = 5 * hop_size;
    169177  o->silence   = -70;
    170   o->wasonset  = new_fvec(1);
    171   o->wasonset->data[0] = -1.;
    172178  o->total_frames = 0;
    173   o->samplerate = samplerate;
    174   o->hop_size = hop_size;
    175   o->pv = new_aubio_pvoc(buf_size, hop_size);
     179  o->pv = new_aubio_pvoc(buf_size, o->hop_size);
    176180  o->pp = new_aubio_peakpicker();
    177181  aubio_peakpicker_set_threshold (o->pp, o->threshold);
     
    179183  o->fftgrain = new_cvec(buf_size);
    180184  o->of = new_fvec(1);
    181   /*if (usedoubled)    {
    182     o2 = new_aubio_specdesc(onset_type2,buffer_size);
    183     onset2 = new_fvec(1);
    184   }*/
    185185  return o;
    186186}
     
    192192  del_aubio_pvoc(o->pv);
    193193  del_fvec(o->of);
    194   del_fvec(o->wasonset);
    195194  del_cvec(o->fftgrain);
    196195  AUBIO_FREE(o);
  • src/onset/onset.h

    rf5e0a54 r35f73b8c  
    2020
    2121/** \file
    22  
     22
    2323  Onset detection object
    2424
     
    4949
    5050/** create onset detection object
    51  
     51
    5252  \param method onset detection type as specified in specdesc.h
    5353  \param buf_size buffer size for phase vocoder
    5454  \param hop_size hop size for phase vocoder
    55   \param samplerate sampling rate of the input signal 
    56 
    57 */
    58 aubio_onset_t * new_aubio_onset (char_t * method, 
     55  \param samplerate sampling rate of the input signal
     56
     57*/
     58aubio_onset_t * new_aubio_onset (char_t * method,
    5959    uint_t buf_size, uint_t hop_size, uint_t samplerate);
    6060
    6161/** execute onset detection
    6262
    63   \param o onset detection object as returned by new_aubio_onset
     63  \param o onset detection object as returned by ::new_aubio_onset
    6464  \param input new audio vector of length hop_size
    65   \param onset output vector, 1 if onset is found, 0 otherwise
     65  \param onset output vector of length 1, containing 0 if no onset was found,
     66  and a value equal or greater than 1 otherwise
     67
     68  When no onset was detected, the first element of the output vector `onset`
     69  is set to 0.
     70
     71  When an onset is found, the first element of the output vector `onset` is set
     72  to `offset = 1 + a` where `a` is a number in the range`[0, 1]`.
     73
     74  The final onset detection time, in samples, can be obtained with
     75  ::aubio_onset_get_last_onset. It can also be derived from `offset` as
     76  follows:
     77
     78  \code
     79    t = total_frames + offset * hop_size - delay
     80  \endcode
     81
     82  where `total_frames` is the total number of frames processed so far, and
     83  `delay` is the current delay of the onset object, as returned by
     84  ::aubio_onset_get_delay.
    6685
    6786*/
     
    7089/** get the time of the latest onset detected, in samples
    7190
    72   \param o onset detection object as returned by new_aubio_onset
     91  \param o onset detection object as returned by ::new_aubio_onset
    7392
    7493*/
     
    7796/** get the time of the latest onset detected, in seconds
    7897
    79   \param o onset detection object as returned by new_aubio_onset
     98  \param o onset detection object as returned by ::new_aubio_onset
    8099
    81100*/
     
    84103/** get the time of the latest onset detected, in milliseconds
    85104
    86   \param o onset detection object as returned by new_aubio_onset
     105  \param o onset detection object as returned by ::new_aubio_onset
    87106
    88107*/
     
    91110/** set onset detection silence threshold
    92111
    93   \param o onset detection object as returned by new_aubio_onset
     112  \param o onset detection object as returned by ::new_aubio_onset
    94113  \param silence new silence detection threshold
    95114
     
    99118/** get onset detection function
    100119
    101   \param o onset detection object as returned by new_aubio_onset
     120  \param o onset detection object as returned by ::new_aubio_onset
    102121  \return the current value of the descriptor
    103122
     
    107126/** get thresholded onset detection function
    108127
    109   \param o onset detection object as returned by new_aubio_onset
     128  \param o onset detection object as returned by ::new_aubio_onset
    110129  \return the value of the thresholded descriptor
    111130
     
    113132smpl_t aubio_onset_get_thresholded_descriptor ( aubio_onset_t *o);
    114133
    115 /** set onset detection peak picking threshold 
    116 
    117   \param o onset detection object as returned by new_aubio_onset
     134/** set onset detection peak picking threshold
     135
     136  \param o onset detection object as returned by ::new_aubio_onset
    118137  \param threshold new peak-picking threshold
    119138
     
    121140uint_t aubio_onset_set_threshold(aubio_onset_t * o, smpl_t threshold);
    122141
    123 /** set minimum inter onset interval
    124 
    125   \param o onset detection object as returned by new_aubio_onset
     142/** set minimum inter onset interval in samples
     143
     144  \param o onset detection object as returned by ::new_aubio_onset
     145  \param minioi minimum interval between two consecutive onsets (in
     146  samples)
     147
     148*/
     149uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
     150
     151/** set minimum inter onset interval in seconds
     152
     153  \param o onset detection object as returned by ::new_aubio_onset
     154  \param minioi minimum interval between two consecutive onsets (in
     155  seconds)
     156
     157*/
     158uint_t aubio_onset_set_minioi_s(aubio_onset_t * o, smpl_t minioi);
     159
     160/** set minimum inter onset interval in milliseconds
     161
     162  \param o onset detection object as returned by ::new_aubio_onset
    126163  \param minioi minimum interval between two consecutive onsets (in
    127164  milliseconds)
    128165
    129166*/
    130 uint_t aubio_onset_set_minioi(aubio_onset_t * o, uint_t minioi);
     167uint_t aubio_onset_set_minioi_ms(aubio_onset_t * o, smpl_t minioi);
     168
     169/** set minimum inter onset interval in samples
     170
     171  \param o onset detection object as returned by ::new_aubio_onset
     172  \param delay constant system delay to take back from detection time
     173  (in samples)
     174
     175*/
     176uint_t aubio_onset_set_delay(aubio_onset_t * o, uint_t delay);
     177
     178/** set minimum inter onset interval in seconds
     179
     180  \param o onset detection object as returned by ::new_aubio_onset
     181  \param delay constant system delay to take back from detection time
     182  (in seconds)
     183
     184*/
     185uint_t aubio_onset_set_delay_s(aubio_onset_t * o, smpl_t delay);
     186
     187/** set minimum inter onset interval in milliseconds
     188
     189  \param o onset detection object as returned by ::new_aubio_onset
     190  \param delay constant system delay to take back from detection time
     191  (in milliseconds)
     192
     193*/
     194uint_t aubio_onset_set_delay_ms(aubio_onset_t * o, smpl_t delay);
     195
     196/** get minimum inter onset interval in samples
     197
     198  \param o onset detection object as returned by ::new_aubio_onset
     199  \return minimum interval between two consecutive onsets (in
     200  samples)
     201
     202*/
     203uint_t aubio_onset_get_minioi(aubio_onset_t * o);
     204
     205/** get minimum inter onset interval in seconds
     206
     207  \param o onset detection object as returned by ::new_aubio_onset
     208  \return minimum interval between two consecutive onsets (in
     209  seconds)
     210
     211*/
     212smpl_t aubio_onset_get_minioi_s(aubio_onset_t * o);
     213
     214/** get minimum inter onset interval in milliseconds
     215
     216  \param o onset detection object as returned by ::new_aubio_onset
     217  \return minimum interval between two consecutive onsets (in
     218  milliseconds)
     219
     220*/
     221smpl_t aubio_onset_get_minioi_ms(aubio_onset_t * o);
     222
     223/** get minimum inter onset interval in samples
     224
     225  \param o onset detection object as returned by ::new_aubio_onset
     226  \return constant system delay to take back from detection time
     227  (in samples)
     228
     229*/
     230uint_t aubio_onset_get_delay(aubio_onset_t * o);
     231
     232/** get minimum inter onset interval in seconds
     233
     234  \param o onset detection object as returned by ::new_aubio_onset
     235  \return constant system delay to take back from detection time
     236  (in seconds)
     237
     238*/
     239smpl_t aubio_onset_get_delay_s(aubio_onset_t * o);
     240
     241/** get minimum inter onset interval in milliseconds
     242
     243  \param o onset detection object as returned by ::new_aubio_onset
     244  \return constant system delay to take back from detection time
     245  (in milliseconds)
     246
     247*/
     248smpl_t aubio_onset_get_delay_ms(aubio_onset_t * o);
    131249
    132250/** delete onset detection object
    133251
    134   \param o onset detection object to delete 
     252  \param o onset detection object to delete
    135253
    136254*/
Note: See TracChangeset for help on using the changeset viewer.