shithub: aubio

Download patch

ref: 26775a35207c11ff664339a16d661287099fd441
parent: 248da647c4011d8770733f1a2a3bea8b0752aa75
author: Paul Brossier <piem@piem.org>
date: Sun Mar 3 08:36:18 EST 2013

tests/src/onset/: improve examples

--- a/tests/src/onset/test-onset.c
+++ b/tests/src/onset/test-onset.c
@@ -1,22 +1,34 @@
 #include <aubio.h>
 
-int main(){
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        fvec_t * in       = new_fvec (win_s/4); /* input buffer */
-        fvec_t * out      = new_fvec (2);     /* input buffer */
-        aubio_onset_t * onset  = new_aubio_onset("complex", win_s, win_s/4, 44100.);
-        uint_t i = 0;
+int main ()
+{
+  // 1. allocate some memory
+  uint_t n = 0; // frame counter
+  uint_t win_s = 1024; // window size
+  uint_t hop_s = win_s / 4; // hop size
+  uint_t samplerate = 44100; // samplerate
+  // create some vectors
+  fvec_t * input = new_fvec (win_s/4); // input buffer
+  fvec_t * out = new_fvec (2); // input buffer
+  // create onset object
+  aubio_onset_t * onset = new_aubio_onset("complex", win_s, hop_s, samplerate);
 
-        while (i < 10) {
-          aubio_onset_do (onset,in,out);
-          i++;
-        };
+  // 2. do something with it
+  while (n < 10) {
+    // get `hop_s` new samples into `input`
+    // ...
+    // exectute onset detection
+    aubio_onset_do (onset, input, out);
+    // do something with output candidates
+    // ...
+    n++;
+  };
 
-        del_aubio_onset(onset);
-        del_fvec(in);
-        del_fvec(out);
-        aubio_cleanup();
+  // 3. clean up memory
+  del_aubio_onset(onset);
+  del_fvec(input);
+  del_fvec(out);
+  aubio_cleanup();
 
-        return 0;
+  return 0;
 }
--- a/tests/src/onset/test-peakpicker.c
+++ b/tests/src/onset/test-peakpicker.c
@@ -2,22 +2,22 @@
 
 #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 (1); /* input buffer */
-        aubio_peakpicker_t * o = new_aubio_peakpicker();
-        aubio_peakpicker_set_threshold (o, 0.3);
+int main ()
+{
+  uint_t win_s = 1024; // window size
+  fvec_t * in = new_fvec (win_s); // input buffer
+  fvec_t * out = new_fvec (1); // input buffer
+  aubio_peakpicker_t * o = new_aubio_peakpicker();
+  aubio_peakpicker_set_threshold (o, 0.3);
 
-        aubio_peakpicker_do(o, in, out);
-        aubio_peakpicker_do(o, in, out);
-        aubio_peakpicker_do(o, in, out);
-        aubio_peakpicker_do(o, in, out);
+  aubio_peakpicker_do(o, in, out);
+  aubio_peakpicker_do(o, in, out);
+  aubio_peakpicker_do(o, in, out);
+  aubio_peakpicker_do(o, in, out);
 
-        del_aubio_peakpicker(o);
-        del_fvec(out);
-        del_fvec(in);
-        return 0;
+  del_aubio_peakpicker(o);
+  del_fvec(out);
+  del_fvec(in);
+  return 0;
 }