[5d1f716] | 1 | #include <aubio.h> |
---|
[248da64] | 2 | #include "utils_tests.h" |
---|
[5d1f716] | 3 | |
---|
[4ca4a4a] | 4 | int test_wrong_params(void); |
---|
[248da64] | 5 | |
---|
[4ca4a4a] | 6 | int main(int argc, char **argv) |
---|
| 7 | { |
---|
| 8 | uint_t err = 0; |
---|
| 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", |
---|
| 13 | argv[0]); |
---|
[248da64] | 14 | return err; |
---|
| 15 | } |
---|
[5d1f716] | 16 | |
---|
[9f68f11] | 17 | uint_t samplerate = 0; |
---|
| 18 | uint_t hop_size = 512; |
---|
| 19 | uint_t n_frames = 0, read = 0; |
---|
| 20 | |
---|
[248da64] | 21 | char_t *source_path = argv[1]; |
---|
| 22 | char_t *sink_path = argv[2]; |
---|
[d67a08e] | 23 | |
---|
| 24 | if ( argc >= 4 ) samplerate = atoi(argv[3]); |
---|
| 25 | if ( argc >= 5 ) hop_size = atoi(argv[4]); |
---|
[248da64] | 26 | |
---|
[5d1f716] | 27 | fvec_t *vec = new_fvec(hop_size); |
---|
[d67a08e] | 28 | |
---|
[248da64] | 29 | aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); |
---|
| 30 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); |
---|
[d67a08e] | 31 | |
---|
[248da64] | 32 | aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); |
---|
[4ca4a4a] | 33 | |
---|
| 34 | if (!vec || !i || !o) { err = 1; goto failure; } |
---|
[5d1f716] | 35 | |
---|
[248da64] | 36 | do { |
---|
[5d1f716] | 37 | aubio_source_do(i, vec, &read); |
---|
| 38 | aubio_sink_do(o, vec, read); |
---|
[248da64] | 39 | n_frames += read; |
---|
| 40 | } while ( read == hop_size ); |
---|
| 41 | |
---|
[4ca4a4a] | 42 | PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n", |
---|
[d67a08e] | 43 | n_frames, samplerate, n_frames / hop_size, |
---|
| 44 | source_path, sink_path); |
---|
[5d1f716] | 45 | |
---|
[4ca4a4a] | 46 | // close sink now (optional) |
---|
| 47 | aubio_sink_close(o); |
---|
| 48 | |
---|
| 49 | failure: |
---|
| 50 | if (o) |
---|
| 51 | del_aubio_sink(o); |
---|
| 52 | if (i) |
---|
| 53 | del_aubio_source(i); |
---|
| 54 | if (vec) |
---|
| 55 | del_fvec(vec); |
---|
| 56 | |
---|
[5d1f716] | 57 | return err; |
---|
| 58 | } |
---|
[4ca4a4a] | 59 | |
---|
| 60 | int test_wrong_params(void) |
---|
| 61 | { |
---|
| 62 | fvec_t *vec; |
---|
| 63 | fmat_t *mat; |
---|
| 64 | aubio_sink_t *s; |
---|
| 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; |
---|
| 70 | uint_t channels = 3; |
---|
| 71 | uint_t oversized_channels = 1025; |
---|
| 72 | // create temp file |
---|
| 73 | int fd = create_temp_sink(sink_path); |
---|
| 74 | |
---|
| 75 | if (!fd) return 1; |
---|
| 76 | |
---|
| 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; |
---|
| 80 | |
---|
| 81 | s = new_aubio_sink(sink_path, 0); |
---|
| 82 | |
---|
| 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; |
---|
| 87 | |
---|
| 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; |
---|
| 91 | |
---|
| 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); |
---|
| 99 | del_fvec(vec); |
---|
| 100 | |
---|
| 101 | // check writing an oversized vector |
---|
| 102 | vec = new_fvec(oversized_hop_size); |
---|
| 103 | aubio_sink_do(s, vec, oversized_hop_size); |
---|
| 104 | del_fvec(vec); |
---|
| 105 | |
---|
| 106 | // test delete without closing |
---|
| 107 | del_aubio_sink(s); |
---|
| 108 | |
---|
| 109 | s = new_aubio_sink(sink_path, 0); |
---|
| 110 | |
---|
| 111 | // preset channels first |
---|
| 112 | if (aubio_sink_preset_channels(s, channels)) return 1; |
---|
| 113 | if (aubio_sink_preset_samplerate(s, samplerate)) return 1; |
---|
| 114 | |
---|
| 115 | mat = new_fmat(channels, hop_size); |
---|
| 116 | // check writing a vector with valid length |
---|
| 117 | aubio_sink_do_multi(s, mat, hop_size); |
---|
| 118 | // check writing more than in the input |
---|
| 119 | aubio_sink_do_multi(s, mat, hop_size+1); |
---|
| 120 | del_fmat(mat); |
---|
| 121 | |
---|
| 122 | // check writing oversized input |
---|
| 123 | mat = new_fmat(channels, oversized_hop_size); |
---|
| 124 | aubio_sink_do_multi(s, mat, oversized_hop_size); |
---|
| 125 | del_fmat(mat); |
---|
| 126 | |
---|
| 127 | // check writing undersized input |
---|
| 128 | mat = new_fmat(channels - 1, hop_size); |
---|
| 129 | aubio_sink_do_multi(s, mat, hop_size); |
---|
| 130 | del_fmat(mat); |
---|
| 131 | |
---|
| 132 | aubio_sink_close(s); |
---|
| 133 | // test closing twice |
---|
| 134 | aubio_sink_close(s); |
---|
| 135 | |
---|
| 136 | del_aubio_sink(s); |
---|
| 137 | |
---|
| 138 | // delete temp file |
---|
| 139 | close_temp_sink(sink_path, fd); |
---|
| 140 | |
---|
| 141 | return run_on_default_source_and_sink(main); |
---|
| 142 | } |
---|