tests/src/temporal/: improve test examples
authorPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 03:54:28 +0000 (22:54 -0500)
committerPaul Brossier <piem@piem.org>
Sun, 3 Mar 2013 03:54:28 +0000 (22:54 -0500)
tests/src/temporal/test-biquad.c

index 6555cae32ae44778a795fce96aee60ee6b457390..4991f728cf4761c5bd167961bc3038c803eb9e6d 100644 (file)
@@ -1,15 +1,31 @@
 #include <aubio.h>
 
-int main(){
-        /* allocate some memory */
-        uint_t win_s      = 1024;                       /* window size */
-        fvec_t * in       = new_fvec (win_s); /* input buffer */
-        aubio_filter_t * o = new_aubio_filter_biquad(0.3,0.2,0.1,0.2,0.3);
-
-        aubio_filter_do_filtfilt(o,in,in);
-        aubio_filter_do(o,in);
-
-        del_aubio_filter(o);
-        del_fvec(in);
-        return 0;
+int main () {
+  uint_t win_s = 64; // window size
+
+  // create biquad filter with `b0`, `b1`, `b2`, `a1`, `a2`
+  aubio_filter_t * o = new_aubio_filter_biquad(0.3,0.2,0.1,0.2,0.3);
+
+  fvec_t * in_vec  = new_fvec (win_s); // input buffer
+  fvec_t * tmp_vec = new_fvec (win_s); // temporary buffer
+  fvec_t * out_vec = new_fvec (win_s); // output buffer
+
+  uint_t times = 100;
+  while ( times-- ) {
+    // copy to out, then filter out
+    aubio_filter_do_outplace(o, in_vec, out_vec);
+    // in-place filtering
+    aubio_filter_do(o, in_vec);
+    // in-place filtering
+    aubio_filter_do_filtfilt(o, in_vec, out_vec);
+    fvec_print(in_vec);
+  }
+
+  // memory clean-up, one for each new
+  del_aubio_filter(o);
+  del_fvec(in_vec);
+  del_fvec(tmp_vec);
+  del_fvec(out_vec);
+
+  return 0;
 }