2 #include "utils_tests.h"
4 int test_wrong_params(void);
6 int main(int argc, char **argv)
9 if (argc < 3 || argc >= 6) {
10 PRINT_ERR("wrong number of arguments, running tests\n");
11 err = test_wrong_params();
12 PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
17 uint_t samplerate = 0;
18 uint_t hop_size = 512;
19 uint_t n_frames = 0, read = 0;
21 char_t *source_path = argv[1];
22 char_t *sink_path = argv[2];
24 if ( argc >= 4 ) samplerate = atoi(argv[3]);
25 if ( argc >= 5 ) hop_size = atoi(argv[4]);
27 fvec_t *vec = new_fvec(hop_size);
29 aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
30 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
32 aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
34 if (!vec || !i || !o) { err = 1; goto failure; }
37 aubio_source_do(i, vec, &read);
38 aubio_sink_do(o, vec, read);
40 } while ( read == hop_size );
42 PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n",
43 n_frames, samplerate, n_frames / hop_size,
44 source_path, sink_path);
46 // close sink now (optional)
60 int test_wrong_params(void)
65 char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
66 uint_t samplerate = 44100;
67 uint_t hop_size = 256;
68 uint_t oversized_hop_size = 4097;
69 uint_t oversized_samplerate = 192000 * 8 + 1;
71 uint_t oversized_channels = 1025;
73 int fd = create_temp_sink(sink_path);
77 if (new_aubio_sink( 0, samplerate)) return 1;
78 if (new_aubio_sink("\0", samplerate)) return 1;
79 if (new_aubio_sink(sink_path, -1)) return 1;
81 s = new_aubio_sink(sink_path, 0);
83 // check setting wrong parameters fails
84 if (!aubio_sink_preset_samplerate(s, oversized_samplerate)) return 1;
85 if (!aubio_sink_preset_channels(s, oversized_channels)) return 1;
86 if (!aubio_sink_preset_channels(s, -1)) return 1;
88 // check setting valid parameters passes
89 if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
90 if (aubio_sink_preset_channels(s, 1)) return 1;
92 // check writing a vector with valid length
93 vec = new_fvec(hop_size);
94 aubio_sink_do(s, vec, hop_size);
95 // check writing more than in the input
96 aubio_sink_do(s, vec, hop_size+1);
97 // check write 0 frames
98 aubio_sink_do(s, vec, 0);
101 // check writing an oversized vector
102 vec = new_fvec(oversized_hop_size);
103 aubio_sink_do(s, vec, oversized_hop_size);
106 // test delete without closing
109 s = new_aubio_sink(sink_path, 0);
111 // preset channels first
112 if (aubio_sink_preset_channels(s, channels)) return 1;
113 if (aubio_sink_preset_samplerate(s, samplerate)) return 1;
115 if (aubio_sink_get_samplerate(s) != samplerate) return 1;
116 if (aubio_sink_get_channels(s) != channels) return 1;
118 mat = new_fmat(channels, hop_size);
119 // check writing a vector with valid length
120 aubio_sink_do_multi(s, mat, hop_size);
121 // check writing 0 frames
122 aubio_sink_do_multi(s, mat, 0);
123 // check writing more than in the input
124 aubio_sink_do_multi(s, mat, hop_size+1);
127 // check writing oversized input
128 mat = new_fmat(channels, oversized_hop_size);
129 aubio_sink_do_multi(s, mat, oversized_hop_size);
132 // check writing undersized input
133 mat = new_fmat(channels - 1, hop_size);
134 aubio_sink_do_multi(s, mat, hop_size);
138 // test closing twice
144 close_temp_sink(sink_path, fd);
146 return run_on_default_source_and_sink(main);