Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/tempo/tempo.c

    rce6f652 r95748a6  
    6565  sint_t blockpos;               /** current position in dfframe */
    6666  uint_t winlen;                 /** dfframe bufsize */
    67   uint_t step;                   /** dfframe hopsize */ 
    68   uint_t samplerate;             /** sampling rate of the signal */ 
     67  uint_t step;                   /** dfframe hopsize */
     68  uint_t samplerate;             /** sampling rate of the signal */
    6969  uint_t hop_size;               /** get hop_size */
    7070  uint_t total_frames;           /** total frames since beginning */
    7171  uint_t last_beat;              /** time of latest detected beat, in samples */
    7272  uint_t delay;                  /** delay to remove to last beat, in samples */
     73  uint_t last_tatum;             /** time of latest detected tatum, in samples */
     74  uint_t tatum_signature;        /** number of tatum between each beats */
    7375};
    7476
     
    9193    aubio_beattracking_do(o->bt,o->dfframe,o->out);
    9294    /* rotate dfframe */
    93     for (i = 0 ; i < winlen - step; i++ ) 
     95    for (i = 0 ; i < winlen - step; i++ )
    9496      o->dfframe->data[i] = o->dfframe->data[i+step];
    95     for (i = winlen - step ; i < winlen; i++ ) 
     97    for (i = winlen - step ; i < winlen; i++ )
    9698      o->dfframe->data[i] = 0.;
    9799    o->blockpos = -1;
     
    104106  /* end of second level loop */
    105107  tempo->data[0] = 0; /* reset tactus */
    106   i=0;
     108  //i=0;
    107109  for (i = 1; i < o->out->data[0]; i++ ) {
    108110    /* if current frame is a predicted tactus */
     
    114116      }
    115117      o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size);
     118      o->last_tatum = o->last_beat;
    116119    }
    117120  }
     
    215218    onset2 = new_fvec(1);
    216219  }*/
     220  o->last_tatum = 0;
     221  o->tatum_signature = 4;
    217222  return o;
    218223
     
    226231}
    227232
     233smpl_t aubio_tempo_get_period (aubio_tempo_t *o)
     234{
     235  return aubio_beattracking_get_period (o->bt);
     236}
     237
     238smpl_t aubio_tempo_get_period_s (aubio_tempo_t *o)
     239{
     240  return aubio_beattracking_get_period_s (o->bt);
     241}
     242
    228243smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) {
    229244  return aubio_beattracking_get_confidence(o->bt);
     245}
     246
     247uint_t aubio_tempo_was_tatum (aubio_tempo_t *o)
     248{
     249  uint_t last_tatum_distance = o->total_frames - o->last_tatum;
     250  smpl_t beat_period = aubio_tempo_get_period(o);
     251  smpl_t tatum_period = beat_period / o->tatum_signature;
     252  if (last_tatum_distance < o->hop_size) {
     253    o->last_tatum = o->last_beat;
     254    return 2;
     255  }
     256  else if (last_tatum_distance > tatum_period) {
     257    if ( last_tatum_distance + o->hop_size > beat_period ) {
     258      // next beat is too close, pass
     259      return 0;
     260    }
     261    o->last_tatum = o->total_frames;
     262    return 1;
     263  }
     264  return 0;
     265}
     266
     267smpl_t aubio_tempo_get_last_tatum (aubio_tempo_t *o) {
     268  return (smpl_t)o->last_tatum - o->delay;
     269}
     270
     271uint_t aubio_tempo_set_tatum_signature (aubio_tempo_t *o, uint_t signature) {
     272  if (signature < 1 || signature > 64) {
     273    return AUBIO_FAIL;
     274  } else {
     275    o->tatum_signature = signature;
     276    return AUBIO_OK;
     277  }
    230278}
    231279
Note: See TracChangeset for help on using the changeset viewer.