Changeset 77db425


Ignore:
Timestamp:
Nov 26, 2013, 4:18:57 AM (6 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
2dbcafa
Parents:
18f14f9
Message:

src/tempo/tempo.c: fix for different samplerates

Files:
5 edited

Legend:

Unmodified
Added
Removed
  • src/tempo/beattracking.c

    r18f14f9 r77db425  
    3232struct _aubio_beattracking_t
    3333{
     34  uint_t hop_size;       /** length of one tempo detection function sample, in audio samples */
     35  uint_t samplerate;     /** samplerate of the original signal */
    3436  fvec_t *rwv;           /** rayleigh weighting for beat period in general model */
    3537  fvec_t *dfwv;          /** exponential weighting for beat alignment in general model */
     
    5557
    5658aubio_beattracking_t *
    57 new_aubio_beattracking (uint_t winlen)
     59new_aubio_beattracking (uint_t winlen, uint_t hop_size, uint_t samplerate)
    5860{
    5961
    6062  aubio_beattracking_t *p = AUBIO_NEW (aubio_beattracking_t);
    6163  uint_t i = 0;
    62   /* parameter for rayleigh weight vector - sets preferred tempo to
    63    * 120bpm [43] */
    64   smpl_t rayparam = 48. / 512. * winlen;
     64  p->hop_size = hop_size;
     65  p->samplerate = samplerate;
     66  /* default value for rayleigh weighting - sets preferred tempo to 120bpm */
     67  smpl_t rayparam = 60. * samplerate / 120. / hop_size;
    6568  smpl_t dfwvnorm = EXP ((LOG (2.0) / rayparam) * (winlen + 2));
    6669  /* length over which beat period is found [128] */
     
    415418aubio_beattracking_get_bpm (aubio_beattracking_t * bt)
    416419{
    417   if (bt->bp != 0 && bt->timesig != 0 && bt->counter == 0 && bt->flagstep == 0) {
    418     return 5168. / fvec_quadratic_peak_pos (bt->acfout, bt->bp);
     420  if (bt->bp != 0) {
     421    return 60. * bt->samplerate/ bt->bp / bt->hop_size;
    419422  } else {
    420423    return 0.;
  • src/tempo/beattracking.h

    r18f14f9 r77db425  
    5252
    5353*/
    54 aubio_beattracking_t * new_aubio_beattracking(uint_t hop_size);
     54aubio_beattracking_t * new_aubio_beattracking(uint_t winlen, uint_t hop_size,
     55    uint_t samplerate);
    5556
    5657/** track the beat
  • src/tempo/tempo.c

    r18f14f9 r77db425  
    142142  aubio_tempo_t * o = AUBIO_NEW(aubio_tempo_t);
    143143  o->samplerate = samplerate;
    144   o->winlen = SQR(512)/hop_size;
     144  /* length of observations, worth about 6 seconds */
     145  o->winlen = aubio_next_power_of_two(5.8 * samplerate / hop_size);
    145146  o->step = o->winlen/4;
    146147  o->blockpos = 0;
    147148  o->threshold = 0.3;
    148149  o->silence = -90.;
    149   o->blockpos = 0;
    150150  o->total_frames = 0;
    151151  o->last_beat = 0;
     
    160160  o->od       = new_aubio_specdesc(onset_mode,buf_size);
    161161  o->of       = new_fvec(1);
    162   o->bt       = new_aubio_beattracking(o->winlen);
     162  o->bt       = new_aubio_beattracking(o->winlen, o->hop_size, o->samplerate);
    163163  o->onset    = new_fvec(1);
    164164  /*if (usedoubled)    {
  • tests/src/tempo/test-beattracking.c

    r18f14f9 r77db425  
    1212
    1313  // create beattracking object
    14   aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
     14  aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s, 256, 44100);
    1515
    1616  smpl_t bpm, confidence;
  • tests/src/tempo/test-tempo.c

    r18f14f9 r77db425  
    99    PRINT_ERR("not enough arguments\n");
    1010    PRINT_MSG("read a wave file as a mono vector\n");
    11     PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]);
     11    PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]);
    1212    return err;
    1313  }
    1414  uint_t samplerate = 0;
    15   uint_t win_s = 1024; // window size
    16   uint_t hop_size = win_s / 4;
     15  if ( argc >= 3 ) samplerate = atoi(argv[2]);
     16  uint_t win_size = 1024; // window size
     17  if ( argc >= 4 ) win_size = atoi(argv[3]);
     18  uint_t hop_size = win_size / 4;
     19  if ( argc >= 5 ) hop_size = atoi(argv[4]);
    1720  uint_t n_frames = 0, read = 0;
    18   if ( argc == 3 ) samplerate = atoi(argv[2]);
    19   if ( argc == 4 ) hop_size = atoi(argv[3]);
    2021
    2122  char_t *source_path = argv[1];
     
    3031
    3132  // create tempo object
    32   aubio_tempo_t * o = new_aubio_tempo("default", win_s, hop_size, samplerate);
     33  aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate);
    3334
    3435  do {
Note: See TracChangeset for help on using the changeset viewer.