shithub: aubio

Download patch

ref: 95748a62ec9ac31b5b05607402f8bc10be87e012
parent: 810b3b6462a5b725a015d12f4c592b851ac57efa
author: Paul Brossier <piem@piem.org>
date: Mon Nov 2 18:15:31 EST 2015

src/tempo/tempo.{c,h}: add tatum, a subdivision of the beat period, default to 4

--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -70,6 +70,8 @@
   uint_t total_frames;           /** total frames since beginning */
   uint_t last_beat;              /** time of latest detected beat, in samples */
   uint_t delay;                  /** delay to remove to last beat, in samples */
+  uint_t last_tatum;             /** time of latest detected tatum, in samples */
+  uint_t tatum_signature;        /** number of tatum between each beats */
 };
 
 /* execute tempo detection function on iput buffer */
@@ -113,6 +115,7 @@
         tempo->data[0] = 0; // unset beat if silent
       }
       o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size);
+      o->last_tatum = o->last_beat;
     }
   }
   o->total_frames += o->hop_size;
@@ -214,6 +217,8 @@
     o2 = new_aubio_specdesc(type_onset2,buffer_size);
     onset2 = new_fvec(1);
   }*/
+  o->last_tatum = 0;
+  o->tatum_signature = 4;
   return o;
 
 beach:
@@ -237,6 +242,39 @@
 
 smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) {
   return aubio_beattracking_get_confidence(o->bt);
+}
+
+uint_t aubio_tempo_was_tatum (aubio_tempo_t *o)
+{
+  uint_t last_tatum_distance = o->total_frames - o->last_tatum;
+  smpl_t beat_period = aubio_tempo_get_period(o);
+  smpl_t tatum_period = beat_period / o->tatum_signature;
+  if (last_tatum_distance < o->hop_size) {
+    o->last_tatum = o->last_beat;
+    return 2;
+  }
+  else if (last_tatum_distance > tatum_period) {
+    if ( last_tatum_distance + o->hop_size > beat_period ) {
+      // next beat is too close, pass
+      return 0;
+    }
+    o->last_tatum = o->total_frames;
+    return 1;
+  }
+  return 0;
+}
+
+smpl_t aubio_tempo_get_last_tatum (aubio_tempo_t *o) {
+  return (smpl_t)o->last_tatum - o->delay;
+}
+
+uint_t aubio_tempo_set_tatum_signature (aubio_tempo_t *o, uint_t signature) {
+  if (signature < 1 || signature > 64) {
+    return AUBIO_FAIL;
+  } else {
+    o->tatum_signature = signature;
+    return AUBIO_OK;
+  }
 }
 
 void del_aubio_tempo (aubio_tempo_t *o)
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -160,6 +160,30 @@
 */
 smpl_t aubio_tempo_get_confidence(aubio_tempo_t * o);
 
+/* set number of tatum per beat
+
+   \param o beat tracking object
+   \param signature number of tatum per beat (between 1 and 64)
+
+*/
+uint_t aubio_tempo_set_tatum_signature(aubio_tempo_t *o, uint_t signature);
+
+/* check whether a tatum was detected in the current frame
+
+   \param o beat tracking object
+
+   \return 2 if a beat was detected, 1 if a tatum was detected, 0 otherwise
+
+*/
+uint_t aubio_tempo_was_tatum(aubio_tempo_t *o);
+
+/* get position of last_tatum, in samples
+
+   \param o beat tracking object
+
+*/
+smpl_t aubio_tempo_get_last_tatum(aubio_tempo_t *o);
+
 /** delete tempo detection object
 
   \param o beat tracking object