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 < 3) { |
---|
10 | err = 2; |
---|
11 | PRINT_ERR("not enough arguments\n"); |
---|
12 | PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]); |
---|
13 | return err; |
---|
14 | } |
---|
15 | |
---|
16 | #ifdef HAVE_RUBBERBAND |
---|
17 | uint_t samplerate = 0; |
---|
18 | uint_t hop_size = 256; |
---|
19 | smpl_t pitchscale = 1.; |
---|
20 | uint_t n_frames = 0, read = 0; |
---|
21 | |
---|
22 | char_t *source_path = argv[1]; |
---|
23 | char_t *sink_path = argv[2]; |
---|
24 | |
---|
25 | if ( argc >= 4 ) samplerate = atoi(argv[3]); |
---|
26 | if ( argc >= 5 ) hop_size = atoi(argv[4]); |
---|
27 | if ( argc >= 6 ) pitchscale = atof(argv[5]); |
---|
28 | if ( argc >= 7 ) { |
---|
29 | err = 2; |
---|
30 | PRINT_ERR("too many arguments\n"); |
---|
31 | return err; |
---|
32 | } |
---|
33 | |
---|
34 | fvec_t *vec = new_fvec(hop_size); |
---|
35 | fvec_t *out = new_fvec(hop_size); |
---|
36 | if (!vec) { err = 1; goto beach_fvec; } |
---|
37 | |
---|
38 | aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); |
---|
39 | if (!i) { err = 1; goto beach_source; } |
---|
40 | |
---|
41 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); |
---|
42 | |
---|
43 | aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); |
---|
44 | if (!o) { err = 1; goto beach_sink; } |
---|
45 | |
---|
46 | aubio_pitchshift_t *ps = new_aubio_pitchshift("default", pitchscale, hop_size, samplerate); |
---|
47 | //aubio_pitchshift_set_pitchscale(ps, pitchscale); |
---|
48 | |
---|
49 | int k = 0; |
---|
50 | do { |
---|
51 | aubio_source_do(i, vec, &read); |
---|
52 | aubio_pitchshift_set_transpose(ps, (float)(k-50) / 100.); |
---|
53 | aubio_pitchshift_do(ps, vec, out); |
---|
54 | aubio_sink_do(o, out, read); |
---|
55 | k ++; |
---|
56 | n_frames += read; |
---|
57 | } while ( read == hop_size ); |
---|
58 | |
---|
59 | PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n", |
---|
60 | n_frames, samplerate, n_frames / hop_size, |
---|
61 | source_path, sink_path); |
---|
62 | |
---|
63 | del_aubio_pitchshift(ps); |
---|
64 | del_aubio_sink(o); |
---|
65 | beach_sink: |
---|
66 | del_aubio_source(i); |
---|
67 | beach_source: |
---|
68 | del_fvec(vec); |
---|
69 | del_fvec(out); |
---|
70 | beach_fvec: |
---|
71 | #else /* HAVE_RUBBERBAND */ |
---|
72 | err = 3; |
---|
73 | PRINT_ERR("aubio was not compiled with rubberband\n"); |
---|
74 | #endif /* HAVE_RUBBERBAND */ |
---|
75 | return err; |
---|
76 | } |
---|