[4e9101e] | 1 | #include <aubio.h> |
---|
[f69e3bd] | 2 | #include "utils_tests.h" |
---|
[4e9101e] | 3 | |
---|
[f69e3bd] | 4 | int main (int argc, char **argv) |
---|
[9547247] | 5 | { |
---|
[f69e3bd] | 6 | uint_t err = 0; |
---|
| 7 | if (argc < 2) { |
---|
| 8 | err = 2; |
---|
| 9 | PRINT_ERR("not enough arguments\n"); |
---|
| 10 | PRINT_MSG("read a wave file as a mono vector\n"); |
---|
[77db425] | 11 | PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]); |
---|
[f69e3bd] | 12 | return err; |
---|
| 13 | } |
---|
| 14 | uint_t samplerate = 0; |
---|
[77db425] | 15 | if ( argc >= 3 ) samplerate = atoi(argv[2]); |
---|
| 16 | uint_t win_size = 1024; // window size |
---|
| 17 | if ( argc >= 4 ) win_size = atoi(argv[3]); |
---|
| 18 | uint_t hop_size = win_size / 4; |
---|
| 19 | if ( argc >= 5 ) hop_size = atoi(argv[4]); |
---|
[f69e3bd] | 20 | uint_t n_frames = 0, read = 0; |
---|
[9547247] | 21 | |
---|
[f69e3bd] | 22 | char_t *source_path = argv[1]; |
---|
| 23 | aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size); |
---|
| 24 | if (!source) { err = 1; goto beach; } |
---|
[9547247] | 25 | |
---|
[f69e3bd] | 26 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); |
---|
[9547247] | 27 | |
---|
[f69e3bd] | 28 | // create some vectors |
---|
| 29 | fvec_t * in = new_fvec (hop_size); // input audio buffer |
---|
| 30 | fvec_t * out = new_fvec (2); // output position |
---|
| 31 | |
---|
| 32 | // create tempo object |
---|
[77db425] | 33 | aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate); |
---|
[9547247] | 34 | |
---|
[f69e3bd] | 35 | do { |
---|
| 36 | // put some fresh data in input vector |
---|
| 37 | aubio_source_do(source, in, &read); |
---|
[9547247] | 38 | // execute tempo |
---|
| 39 | aubio_tempo_do(o,in,out); |
---|
| 40 | // do something with the beats |
---|
[f69e3bd] | 41 | if (out->data[0] != 0) { |
---|
| 42 | PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2fbpm with confidence %.2f\n", |
---|
| 43 | aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o), |
---|
| 44 | aubio_tempo_get_last(o), aubio_tempo_get_bpm(o), aubio_tempo_get_confidence(o)); |
---|
| 45 | } |
---|
| 46 | n_frames += read; |
---|
| 47 | } while ( read == hop_size ); |
---|
| 48 | |
---|
| 49 | PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n", |
---|
| 50 | n_frames * 1. / samplerate, |
---|
| 51 | n_frames, samplerate, |
---|
| 52 | n_frames / hop_size, source_path); |
---|
| 53 | |
---|
| 54 | // clean up memory |
---|
[9547247] | 55 | del_aubio_tempo(o); |
---|
| 56 | del_fvec(in); |
---|
| 57 | del_fvec(out); |
---|
[f69e3bd] | 58 | del_aubio_source(source); |
---|
| 59 | beach: |
---|
[9547247] | 60 | aubio_cleanup(); |
---|
| 61 | |
---|
[f69e3bd] | 62 | return err; |
---|
[4e9101e] | 63 | } |
---|