shithub: aubio

Download patch

ref: 954724740c9d378ea1974c59a6b2f0870a66931e
parent: 6938a20076f6383268da0641675124f6cdff5411
author: Paul Brossier <piem@piem.org>
date: Sun Mar 3 08:38:32 EST 2013

tests/src/tempo/: improve examples

--- a/tests/src/tempo/test-beattracking.c
+++ b/tests/src/tempo/test-beattracking.c
@@ -1,41 +1,38 @@
 #define AUBIO_UNSTABLE 1
 
-#include <stdio.h>
 #include <aubio.h>
 
-int main(){
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        fvec_t * in       = new_fvec (win_s); /* input buffer */
-        fvec_t * out      = new_fvec (win_s/4);     /* input buffer */
-  
-        /* allocate fft and other memory space */
-        aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
+int main ()
+{
+  uint_t i = 0;
+  uint_t win_s = 1024; // window size
+  fvec_t * in = new_fvec (win_s); // input buffer
+  fvec_t * out = new_fvec (2); // output beat position
 
-        uint_t i = 0;
+  // create beattracking object
+  aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s);
 
-        smpl_t curtempo, curtempoconf;
+  smpl_t bpm, confidence;
 
-        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;
-          }
-          i++;
-        };
+  while (i < 10) {
+    // put some fresh data in feature vector
+    // ...
 
-        del_aubio_beattracking(tempo);
-        del_fvec(in);
-        del_fvec(out);
-        aubio_cleanup();
+    aubio_beattracking_do(tempo,in,out);
+    // do something  with the beats
+    // ...
 
-        return 0;
+    // get bpm and confidence
+    bpm = aubio_beattracking_get_bpm(tempo);
+    confidence = aubio_beattracking_get_confidence(tempo);
+    i++;
+  };
+
+  del_aubio_beattracking(tempo);
+  del_fvec(in);
+  del_fvec(out);
+  aubio_cleanup();
+
+  return 0;
 }
 
--- a/tests/src/tempo/test-tempo.c
+++ b/tests/src/tempo/test-tempo.c
@@ -1,35 +1,37 @@
-#include <stdio.h>
 #include <aubio.h>
 
-int main(){
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        fvec_t * in       = new_fvec (win_s); /* input buffer */
-        fvec_t * out      = new_fvec (2);     /* input buffer */
-        aubio_tempo_t * o  = new_aubio_tempo("complex", win_s, win_s/4, 44100.);
-        uint_t i = 0;
+int main ()
+{
+  uint_t i = 0;
+  uint_t win_s = 1024; // window size
+  fvec_t * in = new_fvec (win_s); // input vector
+  fvec_t * out = new_fvec (2); // output beat position
 
-        smpl_t curtempo, curtempoconf;
+  // create tempo object
+  aubio_tempo_t * o = new_aubio_tempo("complex", win_s, win_s/4, 44100.);
 
-        while (i < 1000) {
-          aubio_tempo_do(o,in,out);
-          curtempo = aubio_tempo_get_bpm(o);
-          if (curtempo != 0.) {
-            fprintf(stdout,"%f\n",curtempo);
-            return 1;
-          }
-          curtempoconf = aubio_tempo_get_confidence(o);
-          if (curtempoconf != 0.) {
-            fprintf(stdout,"%f\n",curtempo);
-            return 1;
-          }
-          i++;
-        };
+  smpl_t bpm, confidence;
 
-        del_aubio_tempo(o);
-        del_fvec(in);
-        del_fvec(out);
-        aubio_cleanup();
+  while (i < 1000) {
+    // put some fresh data in input vector
+    // ...
 
-        return 0;
+    // execute tempo
+    aubio_tempo_do(o,in,out);
+    // do something with the beats
+    // ...
+
+    // get bpm and confidence
+    bpm = aubio_tempo_get_bpm(o);
+    confidence = aubio_tempo_get_confidence(o);
+
+    i++;
+  };
+
+  del_aubio_tempo(o);
+  del_fvec(in);
+  del_fvec(out);
+  aubio_cleanup();
+
+  return 0;
 }