1 | #define AUBIO_UNSTABLE 1 |
---|
2 | #include <aubio.h> |
---|
3 | #include "utils_tests.h" |
---|
4 | |
---|
5 | #if 1 // test without inclusion in headers |
---|
6 | typedef struct _aubio_sink_vorbis_t aubio_sink_vorbis_t; |
---|
7 | extern aubio_sink_vorbis_t * new_aubio_sink_vorbis(const char_t *uri, |
---|
8 | uint_t samplerate); |
---|
9 | extern void del_aubio_sink_vorbis (aubio_sink_vorbis_t *s); |
---|
10 | extern uint_t aubio_sink_vorbis_open(aubio_sink_vorbis_t *s); |
---|
11 | extern uint_t aubio_sink_vorbis_preset_channels(aubio_sink_vorbis_t *s, |
---|
12 | uint_t channels); |
---|
13 | extern uint_t aubio_sink_vorbis_preset_samplerate(aubio_sink_vorbis_t *s, |
---|
14 | uint_t samplerate); |
---|
15 | extern uint_t aubio_sink_vorbis_get_channels(aubio_sink_vorbis_t *s); |
---|
16 | extern uint_t aubio_sink_vorbis_get_samplerate(aubio_sink_vorbis_t *s); |
---|
17 | extern void aubio_sink_vorbis_do_multi(aubio_sink_vorbis_t *s, fmat_t* |
---|
18 | write_data, uint_t write); |
---|
19 | #endif |
---|
20 | |
---|
21 | // this file uses the unstable aubio api to test aubio_sink_vorbis, please |
---|
22 | // use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c |
---|
23 | |
---|
24 | int main (int argc, char **argv) |
---|
25 | { |
---|
26 | sint_t err = 0; |
---|
27 | |
---|
28 | if (argc < 3) { |
---|
29 | PRINT_ERR("not enough arguments, running tests\n"); |
---|
30 | err = run_on_default_source_and_sink(main); |
---|
31 | PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]); |
---|
32 | return err; |
---|
33 | } |
---|
34 | |
---|
35 | #ifdef HAVE_VORBISENC |
---|
36 | uint_t samplerate = 0; |
---|
37 | uint_t channels = 0; |
---|
38 | uint_t hop_size = 512; |
---|
39 | uint_t n_frames = 0, read = 0; |
---|
40 | |
---|
41 | char_t *source_path = argv[1]; |
---|
42 | char_t *sink_path = argv[2]; |
---|
43 | |
---|
44 | if ( argc >= 4 ) samplerate = atoi(argv[3]); |
---|
45 | if ( argc >= 5 ) channels = atoi(argv[4]); |
---|
46 | if ( argc >= 6 ) hop_size = atoi(argv[5]); |
---|
47 | if ( argc >= 7 ) { |
---|
48 | err = 2; |
---|
49 | PRINT_ERR("too many arguments\n"); |
---|
50 | return err; |
---|
51 | } |
---|
52 | |
---|
53 | aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); |
---|
54 | if (!i) { err = 1; goto beach_source; } |
---|
55 | |
---|
56 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); |
---|
57 | if (channels == 0 ) channels = aubio_source_get_channels(i); |
---|
58 | |
---|
59 | fmat_t *mat = new_fmat(channels, hop_size); |
---|
60 | if (!mat) { err = 1; goto beach_fmat; } |
---|
61 | |
---|
62 | aubio_sink_vorbis_t *o = new_aubio_sink_vorbis(sink_path, 0); |
---|
63 | if (!o) { err = 1; goto beach_sink; } |
---|
64 | err = aubio_sink_vorbis_preset_samplerate(o, samplerate); |
---|
65 | if (err) { goto beach; } |
---|
66 | err = aubio_sink_vorbis_preset_channels(o, channels); |
---|
67 | if (err) { goto beach; } |
---|
68 | |
---|
69 | do { |
---|
70 | aubio_source_do_multi(i, mat, &read); |
---|
71 | aubio_sink_vorbis_do_multi(o, mat, read); |
---|
72 | n_frames += read; |
---|
73 | } while ( read == hop_size ); |
---|
74 | |
---|
75 | PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n", |
---|
76 | n_frames, samplerate, channels, n_frames / hop_size, |
---|
77 | source_path, sink_path); |
---|
78 | PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path, |
---|
79 | aubio_sink_vorbis_get_samplerate(o), |
---|
80 | aubio_sink_vorbis_get_channels(o) ); |
---|
81 | |
---|
82 | beach: |
---|
83 | del_aubio_sink_vorbis(o); |
---|
84 | beach_sink: |
---|
85 | del_fmat(mat); |
---|
86 | beach_fmat: |
---|
87 | del_aubio_source(i); |
---|
88 | beach_source: |
---|
89 | #else /* HAVE_VORBISENC */ |
---|
90 | err = 0; |
---|
91 | PRINT_ERR("aubio was not compiled with aubio_sink_vorbis\n"); |
---|
92 | #endif /* HAVE_VORBISENC */ |
---|
93 | return err; |
---|
94 | } |
---|