From 3a96d3d7aa0af859bc22d0deb528bd6465c944fb Mon Sep 17 00:00:00 2001 From: Paul Brossier Date: Thu, 6 Dec 2018 11:32:11 +0100 Subject: [PATCH] [tests] improve pitchshift tests --- tests/src/effects/test-pitchshift.c | 55 +++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 15 deletions(-) diff --git a/tests/src/effects/test-pitchshift.c b/tests/src/effects/test-pitchshift.c index 80e22d68..e7891f2a 100644 --- a/tests/src/effects/test-pitchshift.c +++ b/tests/src/effects/test-pitchshift.c @@ -2,16 +2,20 @@ #include #include "utils_tests.h" +int test_wrong_params(void); + int main (int argc, char **argv) { sint_t err = 0; - if (argc < 4) { - err = 2; - PRINT_ERR("not enough arguments\n"); - PRINT_MSG("usage: %s [mode] [hop_size] [samplerate]\n", argv[0]); - PRINT_MSG(" with a number of semi tones in the range [-24, 24]\n"); - PRINT_MSG(" and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n"); + if (argc < 3) { + PRINT_ERR("not enough arguments, running tests\n"); + err = test_wrong_params(); + PRINT_MSG("usage: %s [transpose] ", argv[0]); + PRINT_MSG("[mode] [hop_size] [samplerate]\n"); + PRINT_MSG(" with [transpose] a number of semi tones in the range " + " [-24, 24], and [mode] in 'default', 'crispness:0'," + " 'crispness:1', ... 'crispness:6'\n"); return err; } @@ -24,16 +28,12 @@ int main (int argc, char **argv) char_t *sink_path = argv[2]; char_t *mode = "default"; - transpose = atof(argv[3]); + transpose = 0.; + if ( argc >= 4 ) transpose = atof(argv[3]); if ( argc >= 5 ) mode = argv[4]; if ( argc >= 6 ) hop_size = atoi(argv[5]); if ( argc >= 7 ) samplerate = atoi(argv[6]); - if ( argc >= 8 ) { - err = 2; - PRINT_ERR("too many arguments\n"); - return err; - } fvec_t *vec = new_fvec(hop_size); fvec_t *out = new_fvec(hop_size); @@ -47,7 +47,8 @@ int main (int argc, char **argv) aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); if (!o) { err = 1; goto beach_sink; } - aubio_pitchshift_t *ps = new_aubio_pitchshift(mode, transpose, hop_size, samplerate); + aubio_pitchshift_t *ps = + new_aubio_pitchshift(mode, transpose, hop_size, samplerate); if (!ps) { err = 1; goto beach_pitchshift; } do { @@ -58,9 +59,11 @@ int main (int argc, char **argv) n_frames += read; } while ( read == hop_size ); - PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n", + PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", n_frames, samplerate, n_frames / hop_size, - source_path, sink_path); + source_path); + PRINT_MSG("wrote to %s with hop_size: %d, samplerate: %d, latency %d\n", + sink_path, hop_size, samplerate, aubio_pitchshift_get_latency(ps)); del_aubio_pitchshift(ps); beach_pitchshift: @@ -73,3 +76,25 @@ beach_source: beach_fvec: return err; } + +int test_wrong_params(void) +{ + const char_t *mode = "default"; + smpl_t transpose = 0.; + uint_t hop_size = 256; + uint_t samplerate = 44100; + + if (new_aubio_pitchshift("??", transpose, hop_size, samplerate)) return 1; + if (new_aubio_pitchshift(mode, 28., hop_size, samplerate)) return 1; + if (new_aubio_pitchshift(mode, transpose, 0, samplerate)) return 1; + if (new_aubio_pitchshift(mode, transpose, hop_size, 0)) return 1; + + aubio_pitchshift_t *p = new_aubio_pitchshift(mode, transpose, + hop_size, samplerate); + if (!p) return 1; + if (!aubio_pitchshift_set_pitchscale(p, 0.1)) return 1; + if (!aubio_pitchshift_set_transpose(p, -30)) return 1; + del_aubio_pitchshift(p); + + return run_on_default_source_and_sink(main); +} -- 2.11.0