From 26775a35207c11ff664339a16d661287099fd441 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 3 Mar 2013 13:36:18 -0500 Subject: [PATCH] tests/src/onset/: improve examples --- tests/src/onset/test-onset.c | 44 ++++++++++++++++++++----------- tests/src/onset/test-peakpicker.c | 30 ++++++++++----------- 2 files changed, 43 insertions(+), 31 deletions(-) diff --git a/tests/src/onset/test-onset.c b/tests/src/onset/test-onset.c index fd2ab2e4..a454fd76 100644 --- a/tests/src/onset/test-onset.c +++ b/tests/src/onset/test-onset.c @@ -1,22 +1,34 @@ #include -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; } diff --git a/tests/src/onset/test-peakpicker.c b/tests/src/onset/test-peakpicker.c index 0afce6fc..41130823 100644 --- a/tests/src/onset/test-peakpicker.c +++ b/tests/src/onset/test-peakpicker.c @@ -2,22 +2,22 @@ #include -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; } -- 2.26.2