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

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

[tests] add more sink tests

  • Property mode set to 100644
File size: 4.3 KB
Line 
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
28  if ( argc >= 4 ) samplerate = atoi(argv[3]);
29  if ( argc >= 5 ) hop_size = atoi(argv[4]);
30
31  fvec_t *vec = new_fvec(hop_size);
32
33  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
34  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
35
36  aubio_sink_custom_t *o = new_aubio_sink_custom(sink_path, samplerate);
37
38  if (!vec || !i || !o) { err = 1; goto failure; }
39
40  do {
41    aubio_source_do(i, vec, &read);
42    aubio_sink_custom_do(o, vec, read);
43    n_frames += read;
44  } while ( read == hop_size );
45
46  PRINT_MSG("%d frames at %dHz (%d blocks) read from %s, wrote to %s\n",
47      n_frames, samplerate, n_frames / hop_size,
48      source_path, sink_path);
49
50  // close sink now (optional)
51  aubio_sink_custom_close(o);
52
53failure:
54  if (o)
55    del_aubio_sink_custom(o);
56  if (i)
57    del_aubio_source(i);
58  if (vec)
59    del_fvec(vec);
60
61  return err;
62}
63
64int test_wrong_params(void)
65{
66  fvec_t *vec;
67  fmat_t *mat;
68  aubio_sink_custom_t *s;
69  char_t sink_path[PATH_MAX] = "tmp_aubio_XXXXXX";
70  uint_t samplerate = 44100;
71  uint_t hop_size = 256;
72  uint_t oversized_hop_size = 4097;
73  uint_t oversized_samplerate = 192000 * 8 + 1;
74  uint_t channels = 3;
75  uint_t oversized_channels = 1025;
76  // create temp file
77  int fd = create_temp_sink(sink_path);
78
79  if (!fd) return 1;
80
81  if (new_aubio_sink_custom(   0,   samplerate)) return 1;
82  if (new_aubio_sink_custom("\0",   samplerate)) return 1;
83  if (new_aubio_sink_custom(sink_path,      -1)) return 1;
84
85  s = new_aubio_sink_custom(sink_path, 0);
86
87  // check setting wrong parameters fails
88  if (!aubio_sink_custom_preset_samplerate(s, oversized_samplerate)) return 1;
89  if (!aubio_sink_custom_preset_channels(s, oversized_channels)) return 1;
90  if (!aubio_sink_custom_preset_channels(s, -1)) return 1;
91
92  // check setting valid parameters passes
93  if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
94  if (aubio_sink_custom_preset_channels(s, 1)) return 1;
95
96  // check writing a vector with valid length
97  vec = new_fvec(hop_size);
98  aubio_sink_custom_do(s, vec, hop_size);
99  // check writing more than in the input
100  aubio_sink_custom_do(s, vec, hop_size+1);
101  // check write 0 frames
102  aubio_sink_custom_do(s, vec, 0);
103  del_fvec(vec);
104
105  // check writing an oversized vector
106  vec = new_fvec(oversized_hop_size);
107  aubio_sink_custom_do(s, vec, oversized_hop_size);
108  del_fvec(vec);
109
110  // test delete without closing
111  del_aubio_sink_custom(s);
112
113  s = new_aubio_sink_custom(sink_path, 0);
114
115  // preset channels first
116  if (aubio_sink_custom_preset_channels(s, channels)) return 1;
117  if (aubio_sink_custom_preset_samplerate(s, samplerate)) return 1;
118
119  mat = new_fmat(channels, hop_size);
120  // check writing a vector with valid length
121  aubio_sink_custom_do_multi(s, mat, hop_size);
122  // check writing more than in the input
123  aubio_sink_custom_do_multi(s, mat, hop_size+1);
124  del_fmat(mat);
125
126  // check writing oversized input
127  mat = new_fmat(channels, oversized_hop_size);
128  aubio_sink_custom_do_multi(s, mat, oversized_hop_size);
129  del_fmat(mat);
130
131  // check writing undersized input
132  mat = new_fmat(channels - 1, hop_size);
133  aubio_sink_custom_do_multi(s, mat, hop_size);
134  del_fmat(mat);
135
136  aubio_sink_custom_close(s);
137  // test closing twice
138  aubio_sink_custom_close(s);
139
140  del_aubio_sink_custom(s);
141
142  // delete temp file
143  close_temp_sink(sink_path, fd);
144
145  return run_on_default_source_and_sink(base_main);
146}
147
148#else /* HAVE_AUBIO_SINK_CUSTOM */
149
150int base_main(int argc, char** argv)
151{
152  PRINT_ERR("aubio was not compiled with aubio_sink_"
153          aubio_sink_custom ", failed running %s with %d args\n",
154          argv[0], argc);
155  return 0;
156}
157
158#endif /* HAVE_AUBIO_SINK_CUSTOM */
Note: See TracBrowser for help on using the repository browser.