- Timestamp:
- Dec 16, 2018, 7:20:25 PM (6 years ago)
- Branches:
- feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/timestretch, fix/ffmpeg5, master
- Children:
- e957246
- Parents:
- 276032d
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/src/io/test-sink.c
r276032d r4ca4a4a 2 2 #include "utils_tests.h" 3 3 4 int main (int argc, char **argv) 4 int test_wrong_params(void); 5 6 int main(int argc, char **argv) 5 7 { 6 sint_t err = 0;7 8 if (argc < 3) {9 PRINT_ERR("not enough arguments, running tests\n");10 err = run_on_default_source_and_sink(main);11 PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",argv[0]);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]); 12 14 return err; 13 15 } … … 22 24 if ( argc >= 4 ) samplerate = atoi(argv[3]); 23 25 if ( argc >= 5 ) hop_size = atoi(argv[4]); 24 if ( argc >= 6 ) {25 err = 2;26 PRINT_ERR("too many arguments\n");27 return err;28 }29 26 30 27 fvec_t *vec = new_fvec(hop_size); 31 if (!vec) { err = 1; goto beach_fvec; }32 28 33 29 aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size); 34 if (!i) { err = 1; goto beach_source; }35 36 30 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i); 37 31 38 32 aubio_sink_t *o = new_aubio_sink(sink_path, samplerate); 39 if (!o) { err = 1; goto beach_sink; } 33 34 if (!vec || !i || !o) { err = 1; goto failure; } 40 35 41 36 do { … … 45 40 } while ( read == hop_size ); 46 41 47 PRINT_MSG(" read %d frames at %dHz (%d blocks) from %swritten to %s\n",42 PRINT_MSG("%d frames read at %dHz (%d blocks) from %s and written to %s\n", 48 43 n_frames, samplerate, n_frames / hop_size, 49 44 source_path, sink_path); 50 45 51 del_aubio_sink(o); 52 beach_sink: 53 del_aubio_source(i); 54 beach_source: 55 del_fvec(vec); 56 beach_fvec: 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 57 57 return err; 58 58 } 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 }
Note: See TracChangeset
for help on using the changeset viewer.