[4e9101e] | 1 | #include <aubio.h> |
---|
[f69e3bd] | 2 | #include "utils_tests.h" |
---|
[4e9101e] | 3 | |
---|
[0f5f40b] | 4 | int test_wrong_params(void); |
---|
| 5 | |
---|
[f69e3bd] | 6 | int main (int argc, char **argv) |
---|
[26775a3] | 7 | { |
---|
[f69e3bd] | 8 | uint_t err = 0; |
---|
| 9 | if (argc < 2) { |
---|
| 10 | err = 2; |
---|
[0f5f40b] | 11 | PRINT_WRN("no arguments, running tests\n"); |
---|
[1b3edc6] | 12 | err = test_wrong_params(); |
---|
[f69e3bd] | 13 | PRINT_MSG("usage: %s <source_path> [samplerate] [hop_size]\n", argv[0]); |
---|
| 14 | return err; |
---|
| 15 | } |
---|
| 16 | uint_t samplerate = 0; |
---|
[26775a3] | 17 | uint_t win_s = 1024; // window size |
---|
[f69e3bd] | 18 | uint_t hop_size = win_s / 4; |
---|
| 19 | uint_t n_frames = 0, read = 0; |
---|
[0de816c] | 20 | if ( argc >= 3 ) samplerate = atoi(argv[2]); |
---|
| 21 | if ( argc >= 4 ) hop_size = atoi(argv[3]); |
---|
[f69e3bd] | 22 | |
---|
| 23 | char_t *source_path = argv[1]; |
---|
| 24 | aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size); |
---|
| 25 | if (!source) { err = 1; goto beach; } |
---|
| 26 | |
---|
| 27 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); |
---|
| 28 | |
---|
[26775a3] | 29 | // create some vectors |
---|
[f69e3bd] | 30 | fvec_t * in = new_fvec (hop_size); // input audio buffer |
---|
| 31 | fvec_t * out = new_fvec (2); // output position |
---|
| 32 | |
---|
[26775a3] | 33 | // create onset object |
---|
[f69e3bd] | 34 | aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate); |
---|
| 35 | |
---|
| 36 | do { |
---|
| 37 | // put some fresh data in input vector |
---|
| 38 | aubio_source_do(source, in, &read); |
---|
| 39 | // execute onset |
---|
| 40 | aubio_onset_do(o,in,out); |
---|
| 41 | // do something with the onsets |
---|
| 42 | if (out->data[0] != 0) { |
---|
| 43 | PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n", |
---|
| 44 | aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o), |
---|
| 45 | aubio_onset_get_last(o)); |
---|
| 46 | } |
---|
| 47 | n_frames += read; |
---|
| 48 | } while ( read == hop_size ); |
---|
| 49 | |
---|
| 50 | PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n", |
---|
| 51 | n_frames * 1. / samplerate, |
---|
| 52 | n_frames, samplerate, |
---|
| 53 | n_frames / hop_size, source_path); |
---|
| 54 | |
---|
| 55 | // clean up memory |
---|
[2e17371] | 56 | del_aubio_source(source); |
---|
[f69e3bd] | 57 | del_aubio_onset(o); |
---|
| 58 | del_fvec(in); |
---|
[26775a3] | 59 | del_fvec(out); |
---|
[f69e3bd] | 60 | beach: |
---|
[26775a3] | 61 | aubio_cleanup(); |
---|
[4e9101e] | 62 | |
---|
[f69e3bd] | 63 | return err; |
---|
[4e9101e] | 64 | } |
---|
[0f5f40b] | 65 | |
---|
| 66 | int test_wrong_params(void) |
---|
| 67 | { |
---|
| 68 | uint_t win_size = 1024; |
---|
| 69 | uint_t hop_size = win_size / 2; |
---|
| 70 | uint_t samplerate = 44100; |
---|
| 71 | // hop_size < 1 |
---|
| 72 | if (new_aubio_onset("default", 5, 0, samplerate)) |
---|
| 73 | return 1; |
---|
| 74 | // buf_size < 2 |
---|
| 75 | if (new_aubio_onset("default", 1, 1, samplerate)) |
---|
| 76 | return 1; |
---|
| 77 | // buf_size < hop_size |
---|
| 78 | if (new_aubio_onset("default", hop_size, win_size, samplerate)) |
---|
| 79 | return 1; |
---|
| 80 | // samplerate < 1 |
---|
| 81 | if (new_aubio_onset("default", 1024, 512, 0)) |
---|
| 82 | return 1; |
---|
| 83 | |
---|
| 84 | // specdesc creation failed |
---|
| 85 | if (new_aubio_onset("abcd", win_size, win_size/2, samplerate)) |
---|
| 86 | return 1; |
---|
| 87 | |
---|
| 88 | aubio_onset_t *o; |
---|
[2cf905f] | 89 | |
---|
| 90 | // pv creation might fail |
---|
| 91 | o = new_aubio_onset("default", 5, 2, samplerate); |
---|
| 92 | if (o) del_aubio_onset(o); |
---|
| 93 | |
---|
[0f5f40b] | 94 | o = new_aubio_onset("default", win_size, hop_size, samplerate); |
---|
| 95 | if (!aubio_onset_set_default_parameters(o, "wrong_type")) |
---|
| 96 | return 1; |
---|
| 97 | del_aubio_onset(o); |
---|
| 98 | |
---|
[1b3edc6] | 99 | return run_on_default_source(main); |
---|
[0f5f40b] | 100 | } |
---|