shithub: aubio

Download patch

ref: 4e9101e57e11a07c747c8aa35fa22d64a6a8cd1b
parent: 4cab19e91d52a640ea77edbbdda61a5ca4039b06
author: Paul Brossier <[email protected]>
date: Sat Jul 22 05:48:08 EDT 2006

add tests for most function
add tests for most function


--- a/examples/tests/Makefile.am
+++ b/examples/tests/Makefile.am
@@ -1,9 +1,36 @@
-AM_CFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/ext @LASH_CFLAGS@
-AM_LDFLAGS = -L$(top_builddir)/src -L$(top_builddir)/ext -laubioext -laubio @JACK_LIBS@ @LASH_LIBS@
+AM_CFLAGS = -I$(top_srcdir)/src
+AM_LDFLAGS = -L$(top_builddir)/src -laubio @FFTWLIB_LIBS@
 
+test_phasevoc_jack_CFLAGS = -I$(top_builddir)/ext @JACK_CFLAGS@
+test_phasevoc_jack_LDADD  = -laubioext -L$(top_builddir)/ext @JACK_LIBS@ 
+
 bin_PROGRAMS = \
 	test-fft \
 	test-mfft \
+	test-hist \
+	test-scale \
+	test-sample \
+	test-window \
+	test-filter \
+	test-biquad \
+	test-resample \
+	test-peakpick \
 	test-phasevoc \
 	test-phasevoc-jack \
+	test-onsetdetection \
+	test-pitchyin \
+	test-pitchyinfft \
+	test-pitchschmitt \
+	test-pitchfcomb \
+	test-pitchmcomb \
+	test-pitchdetection \
+	test-beattracking \
+	test-onset \
+	test-tempo \
 	test-tss
+
+run-tests: $(bin_PROGRAMS)
+	for i in $(bin_PROGRAMS); do echo $$i; time ./$$i 2>&1 > /dev/null; echo $$?; done
+
+run-valgrind-tests: $(bin_PROGRAMS)
+	for i in $(bin_PROGRAMS); do echo $$i; valgrind .libs/lt-$$i 2>&1 | grep ERROR\ SUMMARY -A4; echo $$?; done
--- /dev/null
+++ b/examples/tests/test-beattracking.c
@@ -1,0 +1,27 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec (win_s/4, channels);     /* input buffer */
+  
+        /* allocate fft and other memory space */
+        aubio_beattracking_t * tempo  = new_aubio_beattracking(win_s, channels);
+
+        uint_t i = 0;
+
+        while (i < 10) {
+          aubio_beattracking_do(tempo,in,out);
+          i++;
+        };
+
+        del_aubio_beattracking(tempo);
+        del_fvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-biquad.c
@@ -1,0 +1,16 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        aubio_biquad_t * o = new_aubio_biquad(0.3,0.2,0.1,0.2,0.3);
+
+        aubio_biquad_do_filtfilt(o,in,in);
+        aubio_biquad_do(o,in);
+
+        del_aubio_biquad(o);
+        del_fvec(in);
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-filter.c
@@ -1,0 +1,23 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec (win_s, channels);     /* input buffer */
+  
+        /* allocate fft and other memory space */
+        aubio_filter_t * o = new_aubio_cdsgn_filter(44100);
+
+        aubio_filter_do(o,in);
+        aubio_filter_do_outplace(o,in,out);
+        aubio_filter_do_filtfilt(o,in,out);
+
+        del_aubio_filter(o);
+        del_fvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-hist.c
@@ -1,0 +1,38 @@
+#include <aubio.h>
+#include <stdlib.h>
+
+void print_array(fvec_t *f);
+void print_array(fvec_t *f){
+  uint i,j;
+  for (i=0;i<f->channels;i++){
+    for (j=0;j<f->length;j++){
+      printf("%f, ", f->data[i][j]); 
+    }
+    printf(";\n"); 
+  }
+}
+
+int main( int argc, char** argv )
+{
+  uint_t length;
+  for (length = 1; length < 10; length ++ ) {
+    fvec_t *t = new_fvec(length,5);
+    aubio_hist_t *o = new_aubio_hist(0, 1, length, 5);
+    aubio_window(t->data[0],t->length,aubio_win_hanning);
+    aubio_window(t->data[1],t->length,aubio_win_hanningz);
+    aubio_window(t->data[2],t->length,aubio_win_blackman);
+    aubio_window(t->data[3],t->length,aubio_win_blackman_harris);
+    aubio_window(t->data[4],t->length,aubio_win_hamming);
+    print_array(t);
+    aubio_hist_do(o,t);
+    print_array(t);
+    aubio_hist_do_notnull(o,t);
+    print_array(t);
+    aubio_hist_dyn_notnull(o,t);
+    print_array(t);
+    del_aubio_hist(o);
+    del_fvec(t);
+  }
+  return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-onset.c
@@ -1,0 +1,23 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s/4, channels); /* input buffer */
+        fvec_t * out      = new_fvec (2, channels);     /* input buffer */
+        aubio_onset_t * onset  = new_aubio_onset(aubio_onset_complex, win_s, win_s/4, channels);
+        uint_t i = 0;
+
+        while (i < 10) {
+          aubio_onset(onset,in,out);
+          i++;
+        };
+
+        del_aubio_onset(onset);
+        del_fvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-onsetdetection.c
@@ -1,0 +1,54 @@
+
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        cvec_t * in       = new_cvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec (1, channels);     /* input buffer */
+  
+        /* allocate fft and other memory space */
+        aubio_onsetdetection_t * o = 
+          new_aubio_onsetdetection(aubio_onset_energy, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_energy(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_specdiff, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_specdiff(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_hfc, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_hfc(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_complex, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_complex(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_phase, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_phase(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_kl, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_kl(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        o = new_aubio_onsetdetection(aubio_onset_mkl, win_s, channels);
+        aubio_onsetdetection(o,in,out);
+        aubio_onsetdetection_mkl(o,in,out);
+        del_aubio_onsetdetection(o);
+
+        del_cvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-peakpick.c
@@ -1,0 +1,19 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        aubio_pickpeak_t * o = new_aubio_peakpicker(0.3);
+
+        aubio_peakpick_pimrt(in,o);
+        aubio_peakpick_pimrt(in,o);
+        aubio_peakpick_pimrt(in,o);
+        aubio_peakpick_pimrt(in,o);
+
+        del_aubio_peakpicker(o);
+        del_fvec(in);
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-pitchdetection.c
@@ -1,0 +1,27 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t hop_s      = win_s/4;                    /* hop size */
+        uint_t samplerate = 44100;                      /* samplerate */
+        uint_t channels   = 1;                          /* number of channel */
+        aubio_pitchdetection_mode mode = aubio_pitchm_freq;
+        aubio_pitchdetection_type type = aubio_pitch_yinfft;
+        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
+        aubio_pitchdetection_t * o  = new_aubio_pitchdetection(
+          win_s, hop_s, channels, samplerate, type, mode
+          );
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_pitchdetection(o,in);
+          i++;
+        };
+
+        del_aubio_pitchdetection(o);
+        del_fvec(in);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-pitchfcomb.c
@@ -1,0 +1,25 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t hop_s      = win_s/4;                    /* hop size */
+        uint_t samplerate = 44100;                      /* samplerate */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (hop_s, channels); /* input buffer */
+        aubio_pitchfcomb_t * o  = new_aubio_pitchfcomb (
+          win_s, hop_s, samplerate
+          );
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_pitchfcomb_detect(o,in);
+          i++;
+        };
+
+        del_aubio_pitchfcomb(o);
+        del_fvec(in);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-pitchmcomb.c
@@ -1,0 +1,24 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t hop_s      = win_s/4;                    /* hop size */
+        uint_t samplerate = 44100;
+        uint_t channels   = 1;                          /* number of channel */
+        cvec_t * in       = new_cvec (win_s, channels); /* input buffer */
+        aubio_pitchmcomb_t * o  = new_aubio_pitchmcomb(
+          win_s, hop_s, channels, samplerate );
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_pitchmcomb_detect (o,in);
+          i++;
+        };
+
+        del_aubio_pitchmcomb(o);
+        del_cvec(in);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-pitchschmitt.c
@@ -1,0 +1,23 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t samplerate = 44100;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, 1); /* input buffer */
+        aubio_pitchschmitt_t * o  = new_aubio_pitchschmitt(
+          win_s, samplerate );
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_pitchschmitt_detect (o,in);
+          i++;
+        };
+
+        del_aubio_pitchschmitt(o);
+        del_fvec(in);
+        aubio_cleanup();
+
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-pitchyin.c
@@ -1,0 +1,24 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec (win_s/2, channels); /* input buffer */
+        uint_t i = 0;
+
+        while (i < 10) {
+          aubio_pitchyin_diff   (in,out);
+          aubio_pitchyin_getcum (out);
+          aubio_pitchyin_getpitch (out);
+          aubio_pitchyin_getpitchfast (in,out,0.2);
+          i++;
+        };
+
+        del_fvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-pitchyinfft.c
@@ -1,0 +1,22 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        aubio_pitchyinfft_t * o  = new_aubio_pitchyinfft(win_s);
+        uint_t i = 0;
+
+        while (i < 10) {
+          aubio_pitchyinfft_detect (o,in,0.2);
+          i++;
+        };
+
+        del_aubio_pitchyinfft(o);
+        del_fvec(in);
+        aubio_cleanup();
+
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-resample.c
@@ -1,0 +1,23 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        smpl_t ratio      = 0.5;
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec ((uint_t)(win_s*ratio), channels);     /* input buffer */
+        aubio_resampler_t * o  = new_aubio_resampler(0.5, 0);
+        uint_t i = 0;
+
+        while (i < 100) {
+          aubio_resampler_process(o,in,out);
+          i++;
+        };
+
+        del_aubio_resampler(o);
+        del_fvec(in);
+        del_fvec(out);
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-sample.c
@@ -1,0 +1,14 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        cvec_t * sp       = new_cvec (win_s, channels); /* input buffer */
+        del_fvec(in);
+        del_cvec(sp);
+
+        return 0;
+}
+
--- /dev/null
+++ b/examples/tests/test-scale.c
@@ -1,0 +1,21 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        aubio_scale_t * o = new_aubio_scale(0,1,2,3);
+        aubio_scale_set(o,0,1,2,3);
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_scale_do(o,in);
+          i++;
+        };
+
+        del_aubio_scale(o);
+        del_fvec(in);
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-tempo.c
@@ -1,0 +1,23 @@
+#include <aubio.h>
+
+int main(){
+        /* allocate some memory */
+        uint_t win_s      = 1024;                       /* window size */
+        uint_t channels   = 1;                          /* number of channel */
+        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
+        fvec_t * out      = new_fvec (2, channels);     /* input buffer */
+        aubio_tempo_t * o  = new_aubio_tempo(aubio_onset_complex, win_s, win_s/4, channels);
+        uint_t i = 0;
+
+        while (i < 1000) {
+          aubio_tempo(o,in,out);
+          i++;
+        };
+
+        del_aubio_tempo(o);
+        del_fvec(in);
+        del_fvec(out);
+        aubio_cleanup();
+
+        return 0;
+}
--- /dev/null
+++ b/examples/tests/test-window.c
@@ -1,0 +1,37 @@
+#include <aubio.h>
+#include <stdlib.h>
+
+void print_array(fvec_t *f);
+void print_array(fvec_t *f){
+  uint i,j;
+  for (i=0;i<f->channels;i++)
+  {
+    for (j=0;j<f->length;j++)
+    {
+      printf("%1.3e, ", f->data[i][j]); 
+    }
+    printf(";\n"); 
+  }
+}
+
+int main( int argc, char** argv )
+{
+  uint_t length;
+  for (length = 2; length <= 5; length++)
+  {
+    fvec_t *t = new_fvec(length,9);
+    aubio_window(t->data[0],t->length,aubio_win_rectangle);
+    aubio_window(t->data[1],t->length,aubio_win_hamming);
+    aubio_window(t->data[2],t->length,aubio_win_hanning);
+    aubio_window(t->data[3],t->length,aubio_win_hanningz);
+    aubio_window(t->data[4],t->length,aubio_win_blackman);
+    aubio_window(t->data[5],t->length,aubio_win_blackman_harris);
+    aubio_window(t->data[6],t->length,aubio_win_gaussian);
+    aubio_window(t->data[7],t->length,aubio_win_welch);
+    aubio_window(t->data[8],t->length,aubio_win_parzen);
+    print_array(t);
+    del_fvec(t);
+  }
+  return 0;
+}
+