1 | #define AUBIO_UNSTABLE 1 |
---|
2 | #include <aubio.h> |
---|
3 | #include "config.h" |
---|
4 | #include "utils_tests.h" |
---|
5 | |
---|
6 | // this file uses the unstable aubio api, please use aubio_sink instead |
---|
7 | // see src/io/sink.h and tests/src/sink/test-sink.c |
---|
8 | |
---|
9 | int main (int argc, char **argv) |
---|
10 | { |
---|
11 | sint_t err = 0; |
---|
12 | |
---|
13 | if (argc < 3) { |
---|
14 | err = 2; |
---|
15 | PRINT_ERR("not enough arguments\n"); |
---|
16 | PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]); |
---|
17 | return err; |
---|
18 | } |
---|
19 | |
---|
20 | #ifdef HAVE_SNDFILE |
---|
21 | uint_t samplerate = 0; |
---|
22 | uint_t channels = 0; |
---|
23 | uint_t hop_size = 512; |
---|
24 | uint_t n_frames = 0, read = 0; |
---|
25 | |
---|
26 | char_t *source_path = argv[1]; |
---|
27 | char_t *sink_path = argv[2]; |
---|
28 | |
---|
29 | if ( argc >= 4 ) samplerate = atoi(argv[3]); |
---|
30 | if ( argc >= 5 ) channels = atoi(argv[4]); |
---|
31 | if ( argc >= 6 ) hop_size = atoi(argv[5]); |
---|
32 | if ( argc >= 7 ) { |
---|
33 | err = 2; |
---|
34 | PRINT_ERR("too many arguments\n"); |
---|
35 | return err; |
---|
36 | } |
---|
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 | if (channels == 0 ) channels = aubio_source_get_channels(i); |
---|
43 | |
---|
44 | fmat_t *mat = new_fmat(channels, hop_size); |
---|
45 | if (!mat) { err = 1; goto beach_fmat; } |
---|
46 | |
---|
47 | aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, 0); |
---|
48 | if (!o) { err = 1; goto beach_sink; } |
---|
49 | err = aubio_sink_sndfile_preset_samplerate(o, samplerate); |
---|
50 | if (err) { goto beach; } |
---|
51 | err = aubio_sink_sndfile_preset_channels(o, channels); |
---|
52 | if (err) { goto beach; } |
---|
53 | |
---|
54 | do { |
---|
55 | aubio_source_do_multi(i, mat, &read); |
---|
56 | aubio_sink_sndfile_do_multi(o, mat, read); |
---|
57 | n_frames += read; |
---|
58 | } while ( read == hop_size ); |
---|
59 | |
---|
60 | PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n", |
---|
61 | n_frames, samplerate, channels, n_frames / hop_size, |
---|
62 | source_path, sink_path); |
---|
63 | PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path, |
---|
64 | aubio_sink_sndfile_get_samplerate(o), |
---|
65 | aubio_sink_sndfile_get_channels(o) ); |
---|
66 | |
---|
67 | beach: |
---|
68 | del_aubio_sink_sndfile(o); |
---|
69 | beach_sink: |
---|
70 | del_fmat(mat); |
---|
71 | beach_fmat: |
---|
72 | del_aubio_source(i); |
---|
73 | beach_source: |
---|
74 | #else |
---|
75 | err = 3; |
---|
76 | PRINT_ERR("aubio was not compiled with aubio_sink_sndfile\n"); |
---|
77 | #endif /* HAVE_SNDFILE */ |
---|
78 | return err; |
---|
79 | } |
---|