shithub: aubio

Download patch

ref: e34b0101944dbd29c994deeabc481d7aa0032b9f
parent: 203c551c7a66307c45e1887a2d3194893b2feecd
author: Paul Brossier <piem@piem.org>
date: Fri Oct 5 13:10:56 EDT 2007

beattracking.{c,h},tempo.{c,h}: add aubio_beattracking_get_confidence

--- a/examples/tests/test-beattracking.c
+++ b/examples/tests/test-beattracking.c
@@ -12,12 +12,17 @@
 
         uint_t i = 0;
 
-        smpl_t curtempo;
+        smpl_t curtempo, curtempoconf;
 
         while (i < 10) {
           aubio_beattracking_do(tempo,in,out);
           curtempo = aubio_beattracking_get_bpm(tempo);
           if (curtempo != 0.) {
+            fprintf(stdout,"%f\n",curtempo);
+            return 1;
+          }
+          curtempoconf = aubio_beattracking_get_confidence(tempo);
+          if (curtempoconf != 0.) {
             fprintf(stdout,"%f\n",curtempo);
             return 1;
           }
--- a/examples/tests/test-tempo.c
+++ b/examples/tests/test-tempo.c
@@ -9,7 +9,7 @@
         aubio_tempo_t * o  = new_aubio_tempo(aubio_onset_complex, win_s, win_s/4, channels);
         uint_t i = 0;
 
-        smpl_t curtempo;
+        smpl_t curtempo, curtempoconf;
 
         while (i < 1000) {
           aubio_tempo(o,in,out);
@@ -16,6 +16,12 @@
           curtempo = aubio_tempo_get_bpm(o);
           if (curtempo != 0.) {
             fprintf(stdout,"%f\n",curtempo);
+            return 1;
+          }
+          curtempoconf = aubio_beattracking_get_confidence(o);
+          if (curtempoconf != 0.) {
+            fprintf(stdout,"%f\n",curtempo);
+            return 1;
           }
           i++;
         };
--- a/src/beattracking.c
+++ b/src/beattracking.c
@@ -460,3 +460,8 @@
           return 0.;
         }
 }
+
+smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt) {
+        if (bt->gp) return vec_max(bt->acfout);
+        else return 0.;
+}
--- a/src/beattracking.h
+++ b/src/beattracking.h
@@ -68,6 +68,15 @@
 
 */
 smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * bt);
+/** get current tempo confidence 
+
+  \param bt beat tracking object
+
+  Returns the confidence with which the tempo has been observed, 0 if no
+  consistent value is found.
+
+*/
+smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * bt);
 /** delete beat tracking object
 
   \param p beat tracking object
--- a/src/tempo.c
+++ b/src/tempo.c
@@ -127,6 +127,10 @@
   return aubio_beattracking_get_bpm(o->bt);
 }
 
+smpl_t aubio_tempo_get_confidence(aubio_tempo_t *o) {
+  return aubio_beattracking_get_confidence(o->bt);
+}
+
 void del_aubio_tempo (aubio_tempo_t *o)
 {
   del_aubio_onsetdetection(o->od);
--- a/src/tempo.h
+++ b/src/tempo.h
@@ -58,6 +58,16 @@
 */
 smpl_t aubio_tempo_get_bpm(aubio_tempo_t * bt);
 
+/** get current tempo confidence
+
+  \param bt beat tracking object
+
+  Returns the confidence with which the tempo has been observed, 0 if no
+  consistent value is found.
+
+*/
+smpl_t aubio_tempo_get_confidence(aubio_tempo_t * bt);
+
 /** delete tempo detection object */
 void del_aubio_tempo(aubio_tempo_t * o);
 
--- a/swig/aubio.i
+++ b/swig/aubio.i
@@ -257,6 +257,8 @@
 aubio_beattracking_t * new_aubio_beattracking(uint_t winlen, uint_t channels);
 void aubio_beattracking_do(aubio_beattracking_t * bt, fvec_t * dfframes, fvec_t * out);
 void del_aubio_beattracking(aubio_beattracking_t * p);
+smpl_t aubio_beattracking_get_bpm(aubio_beattracking_t * p);
+smpl_t aubio_beattracking_get_confidence(aubio_beattracking_t * p);