2 #include "utils_tests.h"
4 int test_wrong_params(void);
6 int main (int argc, char **argv)
10 PRINT_WRN("no arguments, running tests\n");
11 err = test_wrong_params();
12 PRINT_MSG("usage: %s <source_path> [samplerate] [win_size] [hop_size]\n",
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;
24 char_t *source_path = argv[1];
25 aubio_source_t * source = new_aubio_source(source_path, samplerate,
27 if (!source) { err = 1; goto beach; }
29 if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
31 // create some vectors
32 fvec_t * in = new_fvec (hop_size); // input audio buffer
33 fvec_t * out = new_fvec (1); // output position
35 // create tempo object
36 aubio_tempo_t * o = new_aubio_tempo("default", win_size, hop_size,
39 if (!o) { err = 1; goto beach_tempo; }
42 // put some fresh data in input vector
43 aubio_source_do(source, in, &read);
45 aubio_tempo_do(o,in,out);
46 // do something with the beats
47 if (out->data[0] != 0) {
48 PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2f bpm "
49 "with confidence %.2f\n",
50 aubio_tempo_get_last_ms(o), aubio_tempo_get_last_s(o),
51 aubio_tempo_get_last(o), aubio_tempo_get_bpm(o),
52 aubio_tempo_get_confidence(o));
55 } while ( read == hop_size );
57 PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
58 n_frames * 1. / samplerate,
60 n_frames / hop_size, source_path);
67 del_aubio_source(source);
74 int test_wrong_params(void)
76 uint_t win_size = 1024;
77 uint_t hop_size = 256;
78 uint_t samplerate = 44100;
83 // test wrong method fails
84 if (new_aubio_tempo("unexisting_method", win_size, hop_size, samplerate))
87 // test hop > win fails
88 if (new_aubio_tempo("default", hop_size, win_size, samplerate))
91 // test null hop_size fails
92 if (new_aubio_tempo("default", win_size, 0, samplerate))
95 // test 1 buf_size fails
96 if (new_aubio_tempo("default", 1, 1, samplerate))
99 // test null samplerate fails
100 if (new_aubio_tempo("default", win_size, hop_size, 0))
103 // test short sizes workaround
104 t = new_aubio_tempo("default", 2048, 2048, 500);
110 t = new_aubio_tempo("default", win_size, hop_size, samplerate);
114 in = new_fvec(hop_size);
117 // up to step = (next_power_of_two(5.8 * samplerate / hop_size ) / 4 )
118 for (i = 0; i < 256 + 1; i++)
120 aubio_tempo_do(t,in,out);
121 PRINT_MSG("beat at %.3fms, %.3fs, frame %d, %.2f bpm "
122 "with confidence %.2f, was tatum %d\n",
123 aubio_tempo_get_last_ms(t), aubio_tempo_get_last_s(t),
124 aubio_tempo_get_last(t), aubio_tempo_get_bpm(t),
125 aubio_tempo_get_confidence(t), aubio_tempo_was_tatum(t));
132 return run_on_default_source(main);