[24914e1] | 1 | #define AUBIO_UNSTABLE 1 |
---|
| 2 | #include <aubio.h> |
---|
| 3 | #include "utils_tests.h" |
---|
| 4 | |
---|
| 5 | int main (int argc, char **argv) |
---|
| 6 | { |
---|
| 7 | sint_t err = 0; |
---|
| 8 | |
---|
| 9 | if (argc < 4) { |
---|
| 10 | err = 2; |
---|
| 11 | PRINT_ERR("not enough arguments\n"); |
---|
| 12 | PRINT_MSG("usage: %s <input_path> <output_path> <stretch> [transpose] [mode] [hop_size] [samplerate]\n", argv[0]); |
---|
| 13 | PRINT_MSG(" with <stretch> a time stretching ratio in the range [0.025, 10.]\n"); |
---|
| 14 | PRINT_MSG(" [transpose] a number of semi tones in the range [-24, 24]\n"); |
---|
| 15 | PRINT_MSG(" and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n"); |
---|
| 16 | return err; |
---|
| 17 | } |
---|
| 18 | |
---|
| 19 | uint_t samplerate = 0; |
---|
| 20 | uint_t hop_size = 64; |
---|
| 21 | smpl_t transpose = 0.; |
---|
| 22 | smpl_t stretch = 1.; |
---|
| 23 | uint_t n_frames = 0, read = 0; |
---|
| 24 | |
---|
| 25 | char_t *source_path = argv[1]; |
---|
| 26 | char_t *sink_path = argv[2]; |
---|
| 27 | char_t *mode = "default"; |
---|
| 28 | |
---|
| 29 | stretch = atof(argv[3]); |
---|
| 30 | |
---|
| 31 | if ( argc >= 5 ) transpose = atof(argv[4]); |
---|
| 32 | if ( argc >= 6 ) mode = argv[5]; |
---|
| 33 | if ( argc >= 7 ) hop_size = atoi(argv[6]); |
---|
| 34 | if ( argc >= 8 ) samplerate = atoi(argv[7]); |
---|
| 35 | if ( argc >= 9 ) { |
---|
| 36 | err = 2; |
---|
| 37 | PRINT_ERR("too many arguments\n"); |
---|
| 38 | return err; |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | fvec_t *out = new_fvec(hop_size); |
---|
| 42 | if (!out) { err = 1; goto beach_fvec; } |
---|
| 43 | |
---|
| 44 | aubio_timestretch_t *ps = new_aubio_timestretch(source_path, mode, |
---|
| 45 | stretch, hop_size, samplerate); |
---|
| 46 | if (!ps) { err = 1; goto beach_timestretch; } |
---|
| 47 | if (samplerate == 0 ) samplerate = aubio_timestretch_get_samplerate(ps); |
---|
| 48 | |
---|
| 49 | aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); |
---|
| 50 | if (!o) { err = 1; goto beach_sink; } |
---|
| 51 | |
---|
| 52 | if (transpose != 0) aubio_timestretch_set_transpose(ps, transpose); |
---|
| 53 | |
---|
| 54 | do { |
---|
| 55 | aubio_timestretch_set_stretch(ps, stretch); |
---|
| 56 | aubio_timestretch_set_transpose(ps, transpose); |
---|
| 57 | aubio_timestretch_do(ps, out, &read); |
---|
| 58 | aubio_sink_do(o, out, read); |
---|
| 59 | n_frames += read; |
---|
| 60 | } while ( read == hop_size ); |
---|
| 61 | |
---|
| 62 | PRINT_MSG("wrote %d frames at %dHz (%d blocks) from %s written to %s\n", |
---|
| 63 | n_frames, samplerate, n_frames / hop_size, |
---|
| 64 | source_path, sink_path); |
---|
| 65 | |
---|
| 66 | del_aubio_sink(o); |
---|
| 67 | beach_sink: |
---|
| 68 | del_aubio_timestretch(ps); |
---|
| 69 | beach_timestretch: |
---|
| 70 | del_fvec(out); |
---|
| 71 | beach_fvec: |
---|
| 72 | return err; |
---|
| 73 | } |
---|