[80b5bbd] | 1 | #define AUBIO_UNSTABLE 1 |
---|
| 2 | #include <aubio.h> |
---|
| 3 | #include "utils_tests.h" |
---|
| 4 | |
---|
[3a96d3d] | 5 | int test_wrong_params(void); |
---|
| 6 | |
---|
[80b5bbd] | 7 | int main (int argc, char **argv) |
---|
| 8 | { |
---|
| 9 | sint_t err = 0; |
---|
| 10 | |
---|
[3a96d3d] | 11 | if (argc < 3) { |
---|
| 12 | PRINT_ERR("not enough arguments, running tests\n"); |
---|
| 13 | err = test_wrong_params(); |
---|
| 14 | PRINT_MSG("usage: %s <input_path> <output_path> [transpose] ", argv[0]); |
---|
| 15 | PRINT_MSG("[mode] [hop_size] [samplerate]\n"); |
---|
| 16 | PRINT_MSG(" with [transpose] a number of semi tones in the range " |
---|
| 17 | " [-24, 24], and [mode] in 'default', 'crispness:0'," |
---|
| 18 | " 'crispness:1', ... 'crispness:6'\n"); |
---|
[80b5bbd] | 19 | return err; |
---|
| 20 | } |
---|
| 21 | |
---|
[687835d] | 22 | #ifdef HAVE_RUBBERBAND |
---|
[80b5bbd] | 23 | uint_t samplerate = 0; |
---|
[9953f09] | 24 | uint_t hop_size = 64; |
---|
[d5f538f] | 25 | smpl_t transpose = 0.; |
---|
[80b5bbd] | 26 | uint_t n_frames = 0, read = 0; |
---|
| 27 | |
---|
| 28 | char_t *source_path = argv[1]; |
---|
| 29 | char_t *sink_path = argv[2]; |
---|
[6e6849d] | 30 | char_t *mode = "default"; |
---|
[80b5bbd] | 31 | |
---|
[3a96d3d] | 32 | transpose = 0.; |
---|
[d5f538f] | 33 | |
---|
[3a96d3d] | 34 | if ( argc >= 4 ) transpose = atof(argv[3]); |
---|
[6e6849d] | 35 | if ( argc >= 5 ) mode = argv[4]; |
---|
[d5f538f] | 36 | if ( argc >= 6 ) hop_size = atoi(argv[5]); |
---|
[6e6849d] | 37 | if ( argc >= 7 ) samplerate = atoi(argv[6]); |
---|
[80b5bbd] | 38 | |
---|
| 39 | fvec_t *vec = new_fvec(hop_size); |
---|
| 40 | fvec_t *out = new_fvec(hop_size); |
---|
| 41 | if (!vec) { err = 1; goto beach_fvec; } |
---|
| 42 | |
---|
| 43 | aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); |
---|
| 44 | if (!i) { err = 1; goto beach_source; } |
---|
| 45 | |
---|
| 46 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); |
---|
| 47 | |
---|
| 48 | aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); |
---|
| 49 | if (!o) { err = 1; goto beach_sink; } |
---|
| 50 | |
---|
[3a96d3d] | 51 | aubio_pitchshift_t *ps = |
---|
| 52 | new_aubio_pitchshift(mode, transpose, hop_size, samplerate); |
---|
[d5f538f] | 53 | if (!ps) { err = 1; goto beach_pitchshift; } |
---|
[80b5bbd] | 54 | |
---|
| 55 | do { |
---|
| 56 | aubio_source_do(i, vec, &read); |
---|
[d5f538f] | 57 | //aubio_pitchshift_set_transpose(ps, tranpose); |
---|
[80b5bbd] | 58 | aubio_pitchshift_do(ps, vec, out); |
---|
| 59 | aubio_sink_do(o, out, read); |
---|
| 60 | n_frames += read; |
---|
| 61 | } while ( read == hop_size ); |
---|
| 62 | |
---|
[3a96d3d] | 63 | PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n", |
---|
[80b5bbd] | 64 | n_frames, samplerate, n_frames / hop_size, |
---|
[3a96d3d] | 65 | source_path); |
---|
| 66 | PRINT_MSG("wrote to %s with hop_size: %d, samplerate: %d, latency %d\n", |
---|
| 67 | sink_path, hop_size, samplerate, aubio_pitchshift_get_latency(ps)); |
---|
[80b5bbd] | 68 | |
---|
| 69 | del_aubio_pitchshift(ps); |
---|
[d5f538f] | 70 | beach_pitchshift: |
---|
[80b5bbd] | 71 | del_aubio_sink(o); |
---|
| 72 | beach_sink: |
---|
| 73 | del_aubio_source(i); |
---|
| 74 | beach_source: |
---|
| 75 | del_fvec(vec); |
---|
| 76 | del_fvec(out); |
---|
| 77 | beach_fvec: |
---|
[60ae447] | 78 | aubio_cleanup(); |
---|
[687835d] | 79 | #else |
---|
| 80 | err = 0; |
---|
| 81 | PRINT_ERR("aubio was not compiled with rubberband\n"); |
---|
| 82 | #endif |
---|
[80b5bbd] | 83 | return err; |
---|
| 84 | } |
---|
[3a96d3d] | 85 | |
---|
| 86 | int test_wrong_params(void) |
---|
| 87 | { |
---|
| 88 | const char_t *mode = "default"; |
---|
| 89 | smpl_t transpose = 0.; |
---|
| 90 | uint_t hop_size = 256; |
---|
| 91 | uint_t samplerate = 44100; |
---|
| 92 | |
---|
| 93 | if (new_aubio_pitchshift("??", transpose, hop_size, samplerate)) return 1; |
---|
| 94 | if (new_aubio_pitchshift(mode, 28., hop_size, samplerate)) return 1; |
---|
| 95 | if (new_aubio_pitchshift(mode, transpose, 0, samplerate)) return 1; |
---|
| 96 | if (new_aubio_pitchshift(mode, transpose, hop_size, 0)) return 1; |
---|
| 97 | |
---|
| 98 | aubio_pitchshift_t *p = new_aubio_pitchshift(mode, transpose, |
---|
| 99 | hop_size, samplerate); |
---|
[687835d] | 100 | #ifdef HAVE_RUBBERBAND |
---|
[3a96d3d] | 101 | if (!p) return 1; |
---|
| 102 | if (!aubio_pitchshift_set_pitchscale(p, 0.1)) return 1; |
---|
| 103 | if (!aubio_pitchshift_set_transpose(p, -30)) return 1; |
---|
| 104 | del_aubio_pitchshift(p); |
---|
[687835d] | 105 | #else |
---|
| 106 | if (p) return 1; |
---|
| 107 | #endif |
---|
[3a96d3d] | 108 | |
---|
| 109 | return run_on_default_source_and_sink(main); |
---|
| 110 | } |
---|