From 248da647c4011d8770733f1a2a3bea8b0752aa75 Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Sun, 3 Mar 2013 13:30:40 -0500 Subject: [PATCH] tests/src/io: improve examples --- tests/src/io/test-sink.c | 40 +++++++++++++++++--------- tests/src/io/test-sink_apple_audio_file.c | 43 +++++++++++++++++++--------- tests/src/io/test-sink_sndfile.c | 39 +++++++++++++++++-------- tests/src/io/test-source.c | 41 ++++++++++++++++++--------- tests/src/io/test-source_apple_audio_file.c | 44 +++++++++++++++++++---------- tests/src/io/test-source_sndfile.c | 43 +++++++++++++++++----------- tests/utils_tests.h | 7 +++++ 7 files changed, 172 insertions(+), 85 deletions(-) create mode 100644 tests/utils_tests.h diff --git a/tests/src/io/test-sink.c b/tests/src/io/test-sink.c index cf57536b..8fdba979 100644 --- a/tests/src/io/test-sink.c +++ b/tests/src/io/test-sink.c @@ -1,25 +1,40 @@ -#include #include -#include "config.h" +#include "utils_tests.h" -char_t *path = "/home/piem/archives/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; -char_t *outpath = "/var/tmp/test.wav"; +int main (int argc, char **argv) +{ + sint_t err = 0; + + if (argc < 3) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ - int err = 0; uint_t samplerate = 44100; uint_t hop_size = 512; - uint_t read = hop_size; + uint_t n_frames = 0, read = 0; + + char_t *source_path = argv[1]; + char_t *sink_path = argv[2]; + if ( argc == 4 ) samplerate = atoi(argv[3]); + fvec_t *vec = new_fvec(hop_size); - aubio_source_t * i = new_aubio_source(path, samplerate, hop_size); - aubio_sink_t * o = new_aubio_sink(outpath, samplerate); + aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); + aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); - if (!i || !o) { err = -1; goto beach; } + if (!i || !o) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_do(i, vec, &read); aubio_sink_do(o, vec, read); - } + n_frames += read; + } while ( read == hop_size ); + + PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n", + n_frames, source_path, sink_path, samplerate); beach: del_aubio_source(i); @@ -27,4 +42,3 @@ beach: del_fvec(vec); return err; } - diff --git a/tests/src/io/test-sink_apple_audio_file.c b/tests/src/io/test-sink_apple_audio_file.c index 60c18b9e..195f5d78 100644 --- a/tests/src/io/test-sink_apple_audio_file.c +++ b/tests/src/io/test-sink_apple_audio_file.c @@ -1,34 +1,49 @@ -#include #include -#include "config.h" +#include "utils_tests.h" -char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; -char_t *outpath = "/var/tmp/test.wav"; +int main (int argc, char **argv) +{ + sint_t err = 0; + + if (argc < 3) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ - int err = 0; #ifdef __APPLE__ uint_t samplerate = 44100; uint_t hop_size = 512; - uint_t read = hop_size; + uint_t n_frames = 0, read = 0; + + char_t *source_path = argv[1]; + char_t *sink_path = argv[2]; + if ( argc == 4 ) samplerate = atoi(argv[3]); + fvec_t *vec = new_fvec(hop_size); - aubio_source_apple_audio_t * i = new_aubio_source_apple_audio(path, samplerate, hop_size); - aubio_sink_apple_audio_t * o = new_aubio_sink_apple_audio(outpath, samplerate); + aubio_source_apple_audio_t *i = new_aubio_source_apple_audio(source_path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(i); + aubio_sink_apple_audio_t *o = new_aubio_sink_apple_audio(sink_path, samplerate); - if (!i || !o) { err = -1; goto beach; } + if (!i || !o) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_apple_audio_do(i, vec, &read); aubio_sink_apple_audio_do(o, vec, read); - } + n_frames += read; + } while ( read == hop_size ); + + PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n", + n_frames, source_path, sink_path, samplerate); beach: del_aubio_source_apple_audio(i); del_aubio_sink_apple_audio(o); del_fvec(vec); #else - fprintf(stderr, "ERR: aubio was not compiled with aubio_source_apple_audio\n"); + PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n"); + err = 3; #endif /* __APPLE__ */ return err; } - diff --git a/tests/src/io/test-sink_sndfile.c b/tests/src/io/test-sink_sndfile.c index 1e10e14e..0f0857e9 100644 --- a/tests/src/io/test-sink_sndfile.c +++ b/tests/src/io/test-sink_sndfile.c @@ -1,34 +1,49 @@ -#include #include -#include "config.h" +#include "utils_tests.h" -char_t *path = "/home/piem/archives/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; -char_t *outpath = "/var/tmp/test.wav"; +int main (int argc, char **argv) +{ + sint_t err = 0; + + if (argc < 3) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ - int err = 0; #ifdef HAVE_SNDFILE uint_t samplerate = 44100; uint_t hop_size = 512; - uint_t read = hop_size; + uint_t n_frames = 0, read = 0; + + char_t *source_path = argv[1]; + char_t *sink_path = argv[2]; + if ( argc == 4 ) samplerate = atoi(argv[3]); + fvec_t *vec = new_fvec(hop_size); aubio_source_sndfile_t * i = new_aubio_source_sndfile(path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_sndfile_get_samplerate(i); aubio_sink_sndfile_t * o = new_aubio_sink_sndfile(outpath, samplerate); - if (!i || !o) { err = -1; goto beach; } + if (!i || !o) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_sndfile_do(i, vec, &read); aubio_sink_sndfile_do(o, vec, read); - } + n_frames += read; + } while ( read == hop_size ); + + PRINT_MSG("%d frames read from %s\n written to %s at %dHz\n", + n_frames, source_path, sink_path, samplerate); beach: del_aubio_source_sndfile(i); del_aubio_sink_sndfile(o); del_fvec(vec); #else - fprintf(stderr, "ERR: aubio was not compiled with aubio_source_sndfile\n"); + PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n"); + err = 3; #endif /* HAVE_SNDFILE */ return err; } - diff --git a/tests/src/io/test-source.c b/tests/src/io/test-source.c index 3e1b9f51..12469ae5 100644 --- a/tests/src/io/test-source.c +++ b/tests/src/io/test-source.c @@ -1,25 +1,38 @@ -#include #include +#include "utils_tests.h" -char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; -//char_t *path = "/Users/piem/Downloads/Keziah Jones - Where's Life.mp3"; +int main (int argc, char **argv) +{ + uint_t err = 0; + if (argc < 2) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ uint_t samplerate = 32000; - uint_t hop_size = 1024; - uint_t read = hop_size; + uint_t hop_size = 256; + uint_t n_frames = 0, read = 0; + if ( argc == 3 ) samplerate = atoi(argv[2]); + + char_t *source_path = argv[1]; + fvec_t *vec = new_fvec(hop_size); - aubio_source_t* s = new_aubio_source(path, samplerate, hop_size); + aubio_source_t* s = new_aubio_source(source_path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(s); - if (!s) return -1; + if (!s) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_do(s, vec, &read); - fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]); - } + // fvec_print (vec); + n_frames += read; + } while ( read == hop_size ); - del_aubio_source(s); +beach: + del_aubio_source (s); + del_fvec (vec); - return 0; + return err; } - diff --git a/tests/src/io/test-source_apple_audio_file.c b/tests/src/io/test-source_apple_audio_file.c index 18b9a4bf..796b7960 100644 --- a/tests/src/io/test-source_apple_audio_file.c +++ b/tests/src/io/test-source_apple_audio_file.c @@ -1,28 +1,42 @@ -#include #include +#include "utils_tests.h" -char_t *path = "/Users/piem/archives/sounds/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; -//char_t *path = "/Volumes/moving/moving/photos/gopro2/100GOPRO/GOPR4515.MP4"; +int main (int argc, char **argv) +{ + uint_t err = 0; + if (argc < 2) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ -#ifdef __APPLE__ +#if __APPLE__ uint_t samplerate = 32000; - uint_t hop_size = 1024; - uint_t read = hop_size; + uint_t hop_size = 256; + uint_t n_frames = 0, read = 0; + if ( argc == 3 ) samplerate = atoi(argv[2]); + + char_t *source_path = argv[1]; + fvec_t *vec = new_fvec(hop_size); - aubio_source_apple_audio_t * s = new_aubio_source_apple_audio(path, samplerate, hop_size); + aubio_source_apple_audio_t * s = new_aubio_source_apple_audio(source_path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_apple_audio_get_samplerate(s); - if (!s) return -1; + if (!s) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_apple_audio_do(s, vec, &read); - fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]); - } + // fvec_print (vec); + n_frames += read; + } while ( read == hop_size ); - del_aubio_source_apple_audio(s); +beach: + del_aubio_source_apple_audio (s); + del_fvec (vec); #else - fprintf(stderr, "ERR: aubio was not compiled with aubio_source_apple_audio\n"); + err = 3; + PRINT_ERR("aubio was not compiled with aubio_source_apple_audio\n"); #endif /* __APPLE__ */ return 0; } - diff --git a/tests/src/io/test-source_sndfile.c b/tests/src/io/test-source_sndfile.c index 74da2c9f..3362da23 100644 --- a/tests/src/io/test-source_sndfile.c +++ b/tests/src/io/test-source_sndfile.c @@ -1,33 +1,42 @@ -#include #include -#include "config.h" +#include "utils_tests.h" -char_t *path = "/home/piem/archives/samples/loops/drum_Chocolate_Milk_-_Ation_Speaks_Louder_Than_Words.wav"; +int main (int argc, char **argv) +{ + uint_t err = 0; + if (argc < 2) { + err = 2; + PRINT_ERR("not enough arguments\n"); + PRINT_MSG("usage: %s [samplerate]\n", argv[0]); + return err; + } -int main(){ - int err = 0; #ifdef HAVE_SNDFILE - uint_t samplerate = 8000; - uint_t hop_size = 512; - uint_t read = hop_size; + uint_t samplerate = 32000; + uint_t hop_size = 256; + uint_t n_frames = 0, read = 0; + if ( argc == 3 ) samplerate = atoi(argv[2]); + + char_t *source_path = argv[1]; + fvec_t *vec = new_fvec(hop_size); - aubio_source_sndfile_t * s = new_aubio_source_sndfile(path, samplerate, hop_size); + aubio_source_sndfile_t * s = new_aubio_source_sndfile(source_path, samplerate, hop_size); + if (samplerate == 0 ) samplerate = aubio_source_sndfile_get_samplerate(s); if (!s) { err = 1; goto beach; } - while ( read == hop_size ) { + do { aubio_source_sndfile_do(s, vec, &read); - if (read == 0) break; - fprintf(stdout, "%d [%f, %f, ..., %f]\n", read, vec->data[0], vec->data[1], vec->data[read - 1]); - } + // fvec_print (vec); + n_frames += read; + } while ( read == hop_size ); beach: - del_aubio_source_sndfile(s); - del_fvec(vec); + del_aubio_source_sndfile (s); + del_fvec (vec); #else - fprintf(stderr, "ERR: aubio was not compiled with aubio_source_sndfile\n"); + PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n"); err = 2; #endif /* HAVE_SNDFILE */ return err; } - diff --git a/tests/utils_tests.h b/tests/utils_tests.h new file mode 100644 index 00000000..4961f154 --- /dev/null +++ b/tests/utils_tests.h @@ -0,0 +1,7 @@ +#include +#include + +#define PRINT_ERR(format, args...) fprintf(stderr, "AUBIO ERROR: " format , ##args) +#define PRINT_MSG(format, args...) fprintf(stdout, format , ##args) +#define PRINT_DBG(format, args...) fprintf(stderr, format , ##args) +#define PRINT_WRN(...) fprintf(stderr, "AUBIO WARNING: " format, ##args) -- 2.11.0