shithub: aubio

Download patch

ref: 3a96d3d7aa0af859bc22d0deb528bd6465c944fb
parent: 283a619ac024af5cc6f0ab6f75807adc6434d5b0
author: Paul Brossier <piem@piem.org>
date: Thu Dec 6 06:32:11 EST 2018

[tests] improve pitchshift tests

--- a/tests/src/effects/test-pitchshift.c
+++ b/tests/src/effects/test-pitchshift.c
@@ -2,16 +2,20 @@
 #include <aubio.h>
 #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 <input_path> <output_path> <transpose> [mode] [hop_size] [samplerate]\n", argv[0]);
-    PRINT_MSG(" with <transpose> 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 <input_path> <output_path> [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 @@
   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 @@
   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 @@
     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:
@@ -72,4 +75,26 @@
   del_fvec(out);
 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);
 }