source: tests/src/io/base-sink_custom.h @ 30cb440e

feature/crepe_org
Last change on this file since 30cb440e was 37c7e61, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] test del_aubio_sink on null

  • Property mode set to 100644
File size: 4.7 KB
RevLine 
[46a1e34]1// this should be included *after* custom functions have been defined
2
3#ifndef aubio_sink_custom
4#define aubio_sink_custom "undefined"
5#endif /* aubio_sink_custom */
6
7#ifdef HAVE_AUBIO_SINK_CUSTOM
8int test_wrong_params(void);
9
10int base_main(int argc, char **argv)
11{
12  uint_t err = 0;
13  if (argc < 3 || argc >= 6) {
14    PRINT_ERR("wrong number of arguments, running tests\n");
15    err = test_wrong_params();
16    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n",
17        argv[0]);
18    return err;
19  }
20
21  uint_t samplerate = 0;
22  uint_t hop_size = 512;
23  uint_t n_frames = 0, read = 0;
24
25  char_t *source_path = argv[1];
26  char_t *sink_path = argv[2];
27
[43ea60d]28  aubio_source_t *src = NULL;
29  aubio_sink_custom_t *snk = NULL;
[387b605]30
[46a1e34]31  if ( argc >= 4 ) samplerate = atoi(argv[3]);
32  if ( argc >= 5 ) hop_size = atoi(argv[4]);
33
34  fvec_t *vec = new_fvec(hop_size);
[387b605]35  if (!vec) { err = 1; goto failure; }
[46a1e34]36
[43ea60d]37  src = new_aubio_source(source_path, samplerate, hop_size);
38  if (!src) { err = 1; goto failure; }
39  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(src);
[46a1e34]40
[43ea60d]41  snk = new_aubio_sink_custom(sink_path, samplerate);
42  if (!snk) { err = 1; goto failure; }
[46a1e34]43
44  do {
[43ea60d]45    aubio_source_do(src, vec, &read);
46    aubio_sink_custom_do(snk, vec, read);
[46a1e34]47    n_frames += read;
48  } while ( read == hop_size );
49
50  PRINT_MSG("%d frames at %dHz (%d blocks) read from %s, wrote to %s\n",
51      n_frames, samplerate, n_frames / hop_size,
52      source_path, sink_path);
53
54  // close sink now (optional)
[43ea60d]55  aubio_sink_custom_close(snk);
[46a1e34]56
57failure:
[43ea60d]58  if (snk)
59    del_aubio_sink_custom(snk);
60  if (src)
61    del_aubio_source(src);
[46a1e34]62  if (vec)
63    del_fvec(vec);
64
65  return err;
66}
67
68int test_wrong_params(void)
69{
[276032d]70  fvec_t *vec;
71  fmat_t *mat;
[633a408]72  aubio_sink_custom_t *s;
73  char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
74  uint_t samplerate = 44100;
[276032d]75  uint_t hop_size = 256;
76  uint_t oversized_hop_size = 4097;
77  uint_t oversized_samplerate = 192000 * 8 + 1;
78  uint_t channels = 3;
79  uint_t oversized_channels = 1025;
[633a408]80  // create temp file
81  int fd = create_temp_sink(sink_path);
82
83  if (!fd) return 1;
84
85  if (new_aubio_sink_custom(   0,   samplerate)) return 1;
86  if (new_aubio_sink_custom("\0",   samplerate)) return 1;
87  if (new_aubio_sink_custom(sink_path,      -1)) return 1;
88
89  s = new_aubio_sink_custom(sink_path, 0);
90
[276032d]91  // check setting wrong parameters fails
92  if (!aubio_sink_custom_preset_samplerate(s, oversized_samplerate)) return 1;
93  if (!aubio_sink_custom_preset_channels(s, oversized_channels)) return 1;
94  if (!aubio_sink_custom_preset_channels(s, -1)) return 1;
95
96  // check setting valid parameters passes
[633a408]97  if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
98  if (aubio_sink_custom_preset_channels(s, 1)) return 1;
99
[276032d]100  // check writing a vector with valid length
101  vec = new_fvec(hop_size);
102  aubio_sink_custom_do(s, vec, hop_size);
103  // check writing more than in the input
104  aubio_sink_custom_do(s, vec, hop_size+1);
105  // check write 0 frames
106  aubio_sink_custom_do(s, vec, 0);
107  del_fvec(vec);
108
109  // check writing an oversized vector
110  vec = new_fvec(oversized_hop_size);
111  aubio_sink_custom_do(s, vec, oversized_hop_size);
112  del_fvec(vec);
113
[633a408]114  // test delete without closing
115  del_aubio_sink_custom(s);
116
117  s = new_aubio_sink_custom(sink_path, 0);
118
[276032d]119  // preset channels first
120  if (aubio_sink_custom_preset_channels(s, channels)) return 1;
[633a408]121  if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
[276032d]122
[05774ba3]123  if (aubio_sink_custom_get_samplerate(s) != samplerate) return 1;
124  if (aubio_sink_custom_get_channels(s) != channels) return 1;
125
[276032d]126  mat = new_fmat(channels, hop_size);
127  // check writing a vector with valid length
128  aubio_sink_custom_do_multi(s, mat, hop_size);
[05774ba3]129  // check writing 0 frames
130  aubio_sink_custom_do_multi(s, mat, 0);
[276032d]131  // check writing more than in the input
132  aubio_sink_custom_do_multi(s, mat, hop_size+1);
133  del_fmat(mat);
134
135  // check writing oversized input
136  mat = new_fmat(channels, oversized_hop_size);
137  aubio_sink_custom_do_multi(s, mat, oversized_hop_size);
138  del_fmat(mat);
139
140  // check writing undersized input
141  mat = new_fmat(channels - 1, hop_size);
142  aubio_sink_custom_do_multi(s, mat, hop_size);
143  del_fmat(mat);
[633a408]144
145  aubio_sink_custom_close(s);
146  // test closing twice
147  aubio_sink_custom_close(s);
148
149  del_aubio_sink_custom(s);
150
151  // delete temp file
152  close_temp_sink(sink_path, fd);
153
[37c7e61]154  // shouldn't crash on null (bypassed, only check del_aubio_sink)
155  // del_aubio_sink_custom(NULL);
156
[46a1e34]157  return run_on_default_source_and_sink(base_main);
158}
159
160#else /* HAVE_AUBIO_SINK_CUSTOM */
161
162int base_main(int argc, char** argv)
163{
164  PRINT_ERR("aubio was not compiled with aubio_sink_"
165          aubio_sink_custom ", failed running %s with %d args\n",
166          argv[0], argc);
167  return 0;
168}
169
170#endif /* HAVE_AUBIO_SINK_CUSTOM */
Note: See TracBrowser for help on using the repository browser.