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

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since be94d24 was 2cf905f, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] onset creation may succeed with non-power of two sizes

  • Property mode set to 100644
File size: 2.6 KB
Line 
1#include <aubio.h>
2#include "utils_tests.h"
3
4int test_wrong_params(void);
5
6int main (int argc, char **argv)
7{
8  uint_t err = 0;
9  if (argc < 2) {
10    err = 2;
11    PRINT_WRN("no arguments, running tests\n");
12    err = test_wrong_params();
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);
60beach:
61  aubio_cleanup();
62
63  return err;
64}
65
66int test_wrong_params(void)
67{
68  uint_t win_size = 1024;
69  uint_t hop_size = win_size / 2;
70  uint_t samplerate = 44100;
71  // hop_size < 1
72  if (new_aubio_onset("default", 5, 0, samplerate))
73    return 1;
74  // buf_size < 2
75  if (new_aubio_onset("default", 1, 1, samplerate))
76    return 1;
77  // buf_size < hop_size
78  if (new_aubio_onset("default", hop_size, win_size, samplerate))
79    return 1;
80  // samplerate < 1
81  if (new_aubio_onset("default", 1024, 512, 0))
82    return 1;
83
84  // specdesc creation failed
85  if (new_aubio_onset("abcd", win_size, win_size/2, samplerate))
86    return 1;
87
88  aubio_onset_t *o;
89
90  // pv creation might fail
91  o = new_aubio_onset("default", 5, 2, samplerate);
92  if (o) del_aubio_onset(o);
93
94  o = new_aubio_onset("default", win_size, hop_size, samplerate);
95  if (!aubio_onset_set_default_parameters(o, "wrong_type"))
96    return 1;
97  del_aubio_onset(o);
98
99  return run_on_default_source(main);
100}
Note: See TracBrowser for help on using the repository browser.