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