Intel IPP support for aubio
[aubio.git] / tests / src / onset / test-onset.c
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] [hop_size]\n", argv[0]);
14     return err;
15   }
16   uint_t samplerate = 0;
17   uint_t win_s = 1024; // window size
18   uint_t hop_size = win_s / 4;
19   uint_t n_frames = 0, read = 0;
20   if ( argc == 3 ) samplerate = atoi(argv[2]);
21   if ( argc == 4 ) hop_size = atoi(argv[3]);
22
23   char_t *source_path = argv[1];
24   aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
25   if (!source) { err = 1; goto beach; }
26
27   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
28
29   // create some vectors
30   fvec_t * in = new_fvec (hop_size); // input audio buffer
31   fvec_t * out = new_fvec (2); // output position
32
33   // create onset object
34   aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate);
35
36   do {
37     // put some fresh data in input vector
38     aubio_source_do(source, in, &read);
39     // execute onset
40     aubio_onset_do(o,in,out);
41     // do something with the onsets
42     if (out->data[0] != 0) {
43       PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n",
44           aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o),
45           aubio_onset_get_last(o));
46     }
47     n_frames += read;
48   } while ( read == hop_size );
49
50   PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
51       n_frames * 1. / samplerate,
52       n_frames, samplerate,
53       n_frames / hop_size, source_path);
54
55   // clean up memory
56   del_aubio_source(source);
57   del_aubio_onset(o);
58   del_fvec(in);
59   del_fvec(out);
60 beach:
61   aubio_cleanup();
62
63   return err;
64 }