source: tests/src/onset/test-onset.c @ ea7428a

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since ea7428a was 2e17371, checked in by Paul Brossier <piem@piem.org>, 11 years ago

tests/src/onset/test-onset.c: add missing del_aubio_source

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[4e9101e]1#include <aubio.h>
[f69e3bd]2#include "utils_tests.h"
[4e9101e]3
[f69e3bd]4int main (int argc, char **argv)
[26775a3]5{
[f69e3bd]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] [hop_size]\n", argv[0]);
12    return err;
13  }
14  uint_t samplerate = 0;
[26775a3]15  uint_t win_s = 1024; // window size
[f69e3bd]16  uint_t hop_size = win_s / 4;
17  uint_t n_frames = 0, read = 0;
18  if ( argc == 3 ) samplerate = atoi(argv[2]);
19  if ( argc == 4 ) hop_size = atoi(argv[3]);
20
21  char_t *source_path = argv[1];
22  aubio_source_t * source = new_aubio_source(source_path, samplerate, hop_size);
23  if (!source) { err = 1; goto beach; }
24
25  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
26
[26775a3]27  // create some vectors
[f69e3bd]28  fvec_t * in = new_fvec (hop_size); // input audio buffer
29  fvec_t * out = new_fvec (2); // output position
30
[26775a3]31  // create onset object
[f69e3bd]32  aubio_onset_t * o = new_aubio_onset("default", win_s, hop_size, samplerate);
33
34  do {
35    // put some fresh data in input vector
36    aubio_source_do(source, in, &read);
37    // execute onset
38    aubio_onset_do(o,in,out);
39    // do something with the onsets
40    if (out->data[0] != 0) {
41      PRINT_MSG("onset at %.3fms, %.3fs, frame %d\n",
42          aubio_onset_get_last_ms(o), aubio_onset_get_last_s(o),
43          aubio_onset_get_last(o));
44    }
45    n_frames += read;
46  } while ( read == hop_size );
47
48  PRINT_MSG("read %.2fs, %d frames at %dHz (%d blocks) from %s\n",
49      n_frames * 1. / samplerate,
50      n_frames, samplerate,
51      n_frames / hop_size, source_path);
52
53  // clean up memory
[2e17371]54  del_aubio_source(source);
[f69e3bd]55  del_aubio_onset(o);
56  del_fvec(in);
[26775a3]57  del_fvec(out);
[f69e3bd]58beach:
[26775a3]59  aubio_cleanup();
[4e9101e]60
[f69e3bd]61  return err;
[4e9101e]62}
Note: See TracBrowser for help on using the repository browser.