shithub: aubio

Download patch

ref: 483b883ece7193ea0fb0406408fa323539d288a4
parent: 8b884ef26f6dd0362468dea95f8d537cd9e3d743
author: Paul Brossier <piem@piem.org>
date: Tue Apr 9 08:54:52 EDT 2013

src/tempo/tempo.c: add get_last functions

--- a/src/tempo/tempo.c
+++ b/src/tempo/tempo.c
@@ -45,6 +45,10 @@
   uint_t winlen;                 /** dfframe bufsize */
   uint_t step;                   /** dfframe hopsize */ 
   uint_t samplerate;             /** sampling rate of the signal */ 
+  uint_t hop_size;               /** get hop_size */
+  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 */
 };
 
 /* execute tempo detection function on iput buffer */
@@ -85,12 +89,40 @@
       tempo->data[0] = o->out->data[i] - FLOOR(o->out->data[i]); /* set tactus */
       /* test for silence */
       if (aubio_silence_detection(input, o->silence)==1) {
-        tempo->data[1] = 0; /* unset onset */
+        //tempo->data[0] = 0; /* unset onset */
+      } else {
+        o->last_beat = o->total_frames + (uint_t)ROUND(tempo->data[0] * o->hop_size);
       }
     }
   }
+  o->total_frames += o->hop_size;
+  return;
 }
 
+uint_t aubio_tempo_get_last (aubio_tempo_t *o)
+{
+  return o->last_beat - o->delay;
+}
+
+smpl_t aubio_tempo_get_last_s (aubio_tempo_t *o)
+{
+  return aubio_tempo_get_last (o) / (smpl_t) (o->samplerate);
+}
+
+smpl_t aubio_tempo_get_last_ms (aubio_tempo_t *o)
+{
+  return aubio_tempo_get_last_s (o) / 1000.;
+}
+
+uint_t aubio_tempo_set_delay(aubio_tempo_t * o, uint_t delay) {
+  o->delay = delay;
+  return AUBIO_OK;
+}
+
+uint_t aubio_tempo_get_delay(aubio_tempo_t * o) {
+  return o->delay;
+}
+
 uint_t aubio_tempo_set_silence(aubio_tempo_t * o, smpl_t silence) {
   o->silence = silence;
   return AUBIO_OK;
@@ -114,6 +146,10 @@
   o->threshold = 0.3;
   o->silence = -90.;
   o->blockpos = 0;
+  o->total_frames = 0;
+  o->last_beat = 0;
+  o->delay = 0;
+  o->hop_size = hop_size;
   o->dfframe  = new_fvec(o->winlen);
   o->fftgrain = new_cvec(buf_size);
   o->out      = new_fvec(o->step);
--- a/src/tempo/tempo.h
+++ b/src/tempo/tempo.h
@@ -60,6 +60,27 @@
 */
 void aubio_tempo_do (aubio_tempo_t *o, fvec_t * input, fvec_t * tempo);
 
+/** get the time of the latest beat detected, in samples
+
+  \param o tempo detection object as returned by ::new_aubio_tempo
+
+*/
+uint_t aubio_tempo_get_last (aubio_tempo_t *o);
+
+/** get the time of the latest beat detected, in seconds
+
+  \param o tempo detection object as returned by ::new_aubio_tempo
+
+*/
+smpl_t aubio_tempo_get_last_s (aubio_tempo_t *o);
+
+/** get the time of the latest beat detected, in milliseconds
+
+  \param o tempo detection object as returned by ::new_aubio_tempo
+
+*/
+smpl_t aubio_tempo_get_last_ms (aubio_tempo_t *o);
+
 /** set tempo detection silence threshold
 
   \param o beat tracking object