[c2e3f44] | 1 | #define AUBIO_UNSTABLE 1 |
---|
| 2 | #include <aubio.h> |
---|
| 3 | #include "utils_tests.h" |
---|
| 4 | |
---|
[9d8cedf5] | 5 | int test_wrong_params(void); |
---|
| 6 | |
---|
[c2e3f44] | 7 | int main (int argc, char **argv) |
---|
| 8 | { |
---|
| 9 | sint_t err = 0; |
---|
| 10 | |
---|
[9d8cedf5] | 11 | if (argc < 3 || argc >= 9) { |
---|
| 12 | PRINT_ERR("wrong number of arguments, running tests\n"); |
---|
| 13 | err = test_wrong_params(); |
---|
[c2e3f44] | 14 | PRINT_MSG("usage: %s <input_path> <output_path> <stretch> [transpose] [mode] [hop_size] [samplerate]\n", argv[0]); |
---|
| 15 | PRINT_MSG(" with <stretch> a time stretching ratio in the range [0.025, 10.]\n"); |
---|
| 16 | PRINT_MSG(" [transpose] a number of semi tones in the range [-24, 24]\n"); |
---|
| 17 | PRINT_MSG(" and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n"); |
---|
| 18 | return err; |
---|
| 19 | } |
---|
| 20 | |
---|
[9d8cedf5] | 21 | #ifdef HAVE_RUBBERBAND |
---|
| 22 | uint_t samplerate = 0; // using source samplerate |
---|
[c2e3f44] | 23 | uint_t hop_size = 64; |
---|
| 24 | smpl_t transpose = 0.; |
---|
| 25 | smpl_t stretch = 1.; |
---|
| 26 | uint_t n_frames = 0, read = 0; |
---|
[e7d4aa0] | 27 | uint_t eof = 0, source_read = 0; |
---|
[c2e3f44] | 28 | |
---|
| 29 | char_t *source_path = argv[1]; |
---|
| 30 | char_t *sink_path = argv[2]; |
---|
| 31 | char_t *mode = "default"; |
---|
| 32 | |
---|
[9d8cedf5] | 33 | if ( argc >= 4 ) stretch = atof(argv[3]); |
---|
[c2e3f44] | 34 | if ( argc >= 5 ) transpose = atof(argv[4]); |
---|
| 35 | if ( argc >= 6 ) mode = argv[5]; |
---|
| 36 | if ( argc >= 7 ) hop_size = atoi(argv[6]); |
---|
| 37 | if ( argc >= 8 ) samplerate = atoi(argv[7]); |
---|
| 38 | |
---|
[e7d4aa0] | 39 | uint_t source_hopsize = 2048; |
---|
| 40 | aubio_source_t *s = new_aubio_source(source_path, samplerate, source_hopsize); |
---|
| 41 | if (!s) { err = 1; goto beach_source; } |
---|
| 42 | if (samplerate == 0) samplerate = aubio_source_get_samplerate(s); |
---|
| 43 | |
---|
| 44 | fvec_t *in = new_fvec(source_hopsize); |
---|
[c2e3f44] | 45 | fvec_t *out = new_fvec(hop_size); |
---|
[ff87a67] | 46 | if (!out || !in) { err = 1; goto beach_fvec; } |
---|
[c2e3f44] | 47 | |
---|
[e7d4aa0] | 48 | aubio_timestretch_t *ps = new_aubio_timestretch(mode, stretch, hop_size, |
---|
| 49 | samplerate); |
---|
[c2e3f44] | 50 | if (!ps) { err = 1; goto beach_timestretch; } |
---|
[e7d4aa0] | 51 | //if (samplerate == 0 ) samplerate = aubio_timestretch_get_samplerate(ps); |
---|
[c2e3f44] | 52 | |
---|
| 53 | aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); |
---|
| 54 | if (!o) { err = 1; goto beach_sink; } |
---|
| 55 | |
---|
| 56 | if (transpose != 0) aubio_timestretch_set_transpose(ps, transpose); |
---|
| 57 | |
---|
| 58 | do { |
---|
[e7d4aa0] | 59 | //aubio_timestretch_set_stretch(ps, stretch); |
---|
| 60 | //aubio_timestretch_set_transpose(ps, transpose); |
---|
[4559863] | 61 | |
---|
[e7d4aa0] | 62 | while (aubio_timestretch_get_available(ps) < (sint_t)hop_size && !eof) { |
---|
| 63 | aubio_source_do(s, in, &source_read); |
---|
| 64 | aubio_timestretch_push(ps, in, source_read); |
---|
| 65 | if (source_read < in->length) eof = 1; |
---|
[4559863] | 66 | } |
---|
[e7d4aa0] | 67 | #if 0 |
---|
| 68 | if (n_frames == hop_size * 200) { |
---|
| 69 | PRINT_MSG("sampler: setting stretch gave %d\n", |
---|
| 70 | aubio_timestretch_set_stretch(ps, 2.) ); |
---|
| 71 | PRINT_MSG("sampler: getting stretch gave %f\n", |
---|
| 72 | aubio_timestretch_get_stretch(ps) ); |
---|
| 73 | PRINT_MSG("sampler: setting transpose gave %d\n", |
---|
| 74 | aubio_timestretch_set_transpose(ps, 12.) ); |
---|
| 75 | PRINT_MSG("sampler: getting transpose gave %f\n", |
---|
| 76 | aubio_timestretch_get_transpose(ps) ); |
---|
[4559863] | 77 | } |
---|
| 78 | #endif |
---|
[e7d4aa0] | 79 | aubio_timestretch_do(ps, out, &read); |
---|
| 80 | aubio_sink_do(o, out, read); |
---|
| 81 | n_frames += read; |
---|
| 82 | } while ( read == hop_size ); |
---|
[c2e3f44] | 83 | |
---|
| 84 | PRINT_MSG("wrote %d frames at %dHz (%d blocks) from %s written to %s\n", |
---|
| 85 | n_frames, samplerate, n_frames / hop_size, |
---|
| 86 | source_path, sink_path); |
---|
| 87 | |
---|
| 88 | del_aubio_sink(o); |
---|
| 89 | beach_sink: |
---|
| 90 | del_aubio_timestretch(ps); |
---|
| 91 | beach_timestretch: |
---|
| 92 | del_fvec(out); |
---|
[ff87a67] | 93 | del_fvec(in); |
---|
[c2e3f44] | 94 | beach_fvec: |
---|
[e7d4aa0] | 95 | del_aubio_source(s); |
---|
| 96 | beach_source: |
---|
[9d8cedf5] | 97 | #else |
---|
| 98 | err = 0; |
---|
| 99 | PRINT_ERR("aubio was not compiled with rubberband\n"); |
---|
| 100 | #endif |
---|
[c2e3f44] | 101 | return err; |
---|
| 102 | } |
---|
[9d8cedf5] | 103 | |
---|
| 104 | int test_wrong_params(void) |
---|
| 105 | { |
---|
| 106 | const char_t *mode = "default"; |
---|
| 107 | smpl_t stretch = 1.; |
---|
| 108 | uint_t hop_size = 256; |
---|
| 109 | uint_t samplerate = 44100; |
---|
| 110 | |
---|
[ff87a67] | 111 | if (new_aubio_timestretch("ProcessOffline:?:", stretch, hop_size, samplerate)) return 1; |
---|
| 112 | if (new_aubio_timestretch("", stretch, hop_size, samplerate)) return 1; |
---|
[9d8cedf5] | 113 | if (new_aubio_timestretch(mode, 41., hop_size, samplerate)) return 1; |
---|
| 114 | if (new_aubio_timestretch(mode, stretch, 0, samplerate)) return 1; |
---|
| 115 | if (new_aubio_timestretch(mode, stretch, hop_size, 0)) return 1; |
---|
| 116 | |
---|
| 117 | aubio_timestretch_t *p = new_aubio_timestretch(mode, stretch, hop_size, |
---|
| 118 | samplerate); |
---|
| 119 | #ifdef HAVE_RUBBERBAND |
---|
| 120 | if (!p) return 1; |
---|
| 121 | |
---|
| 122 | if (aubio_timestretch_get_latency(p) == 0) return 1; |
---|
| 123 | |
---|
[ff87a67] | 124 | if (aubio_timestretch_get_samplerate(p) != samplerate) return 1; |
---|
| 125 | |
---|
[9d8cedf5] | 126 | aubio_timestretch_reset(p); |
---|
| 127 | |
---|
| 128 | if (aubio_timestretch_get_transpose(p) != 0) return 1; |
---|
| 129 | if (aubio_timestretch_set_transpose(p, 2.)) return 1; |
---|
[9279ba0] | 130 | if (fabs(aubio_timestretch_get_transpose(p) - 2.) >= 1e-6) return 1; |
---|
[9d8cedf5] | 131 | if (!aubio_timestretch_set_transpose(p, 200.)) return 1; |
---|
| 132 | if (!aubio_timestretch_set_transpose(p, -200.)) return 1; |
---|
| 133 | if (aubio_timestretch_set_transpose(p, 0.)) return 1; |
---|
| 134 | |
---|
| 135 | if (aubio_timestretch_get_pitchscale(p) != 1) return 1; |
---|
| 136 | if (aubio_timestretch_set_pitchscale(p, 2.)) return 1; |
---|
[9279ba0] | 137 | if (fabs(aubio_timestretch_get_pitchscale(p) - 2.) >= 1e-6) return 1; |
---|
[9d8cedf5] | 138 | if (!aubio_timestretch_set_pitchscale(p, 0.)) return 1; |
---|
| 139 | if (!aubio_timestretch_set_pitchscale(p, 6.)) return 1; |
---|
| 140 | |
---|
| 141 | if (aubio_timestretch_get_stretch(p) != stretch) return 1; |
---|
| 142 | if (aubio_timestretch_set_stretch(p, 2.)) return 1; |
---|
[9279ba0] | 143 | if (fabs(aubio_timestretch_get_stretch(p) - 2.) >= 1e-6) return 1; |
---|
[9d8cedf5] | 144 | if (!aubio_timestretch_set_stretch(p, 0.)) return 1; |
---|
| 145 | if (!aubio_timestretch_set_stretch(p, 41.)) return 1; |
---|
| 146 | |
---|
| 147 | del_aubio_timestretch(p); |
---|
| 148 | #else |
---|
| 149 | if (p) return 1; |
---|
| 150 | #endif |
---|
| 151 | |
---|
| 152 | return run_on_default_source_and_sink(main); |
---|
| 153 | } |
---|