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