1 | #include <aubio.h> |
---|
2 | #include "utils_tests.h" |
---|
3 | |
---|
4 | int main (int argc, char **argv) |
---|
5 | { |
---|
6 | aubio_init(); |
---|
7 | |
---|
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"); |
---|
13 | PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n", argv[0]); |
---|
14 | return err; |
---|
15 | } |
---|
16 | uint_t samplerate = 0; |
---|
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]); |
---|
22 | uint_t n_frames = 0, read = 0; |
---|
23 | |
---|
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; } |
---|
27 | |
---|
28 | if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source); |
---|
29 | |
---|
30 | // create some vectors |
---|
31 | fvec_t * in = new_fvec (hop_size); // input audio buffer |
---|
32 | fvec_t * out = new_fvec (1); // output position |
---|
33 | |
---|
34 | // create tempo object |
---|
35 | aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size, samplerate); |
---|
36 | |
---|
37 | do { |
---|
38 | // put some fresh data in input vector |
---|
39 | aubio_source_do(source, in, &read); |
---|
40 | // execute tempo |
---|
41 | aubio_tempo_do(o,in,out); |
---|
42 | // do something with the beats |
---|
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 |
---|
57 | del_aubio_tempo(o); |
---|
58 | del_fvec(in); |
---|
59 | del_fvec(out); |
---|
60 | del_aubio_source(source); |
---|
61 | |
---|
62 | beach: |
---|
63 | aubio_cleanup(); |
---|
64 | |
---|
65 | return err; |
---|
66 | } |
---|