source: tests/src/io/test-sink-multi.c @ 4ca4a4a

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

[tests] use run_on_default_source_and_sink in sink tests

  • Property mode set to 100644
File size: 2.0 KB
RevLine 
[4ed4b1f]1#include <aubio.h>
2#include "utils_tests.h"
3
[2f02d51]4// same as test-sink.c, but uses aubio_source_do_multi to read multiple
5// channels
[4ed4b1f]6
7int main (int argc, char **argv)
8{
9  sint_t err = 0;
10
11  if (argc < 3) {
[ee0c4d50]12    PRINT_ERR("not enough arguments, running tests\n");
13    err = run_on_default_source_and_sink(main);
[4ed4b1f]14    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
15    return err;
16  }
17
18  uint_t samplerate = 0;
19  uint_t channels = 0;
20  uint_t hop_size = 512;
21  uint_t n_frames = 0, read = 0;
22
23  char_t *source_path = argv[1];
24  char_t *sink_path = argv[2];
25
26  if ( argc >= 4 ) samplerate = atoi(argv[3]);
27  if ( argc >= 5 ) channels = atoi(argv[4]);
28  if ( argc >= 6 ) hop_size = atoi(argv[5]);
29  if ( argc >= 7 ) {
30    err = 2;
31    PRINT_ERR("too many arguments\n");
32    return err;
33  }
34
35  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
36  if (!i) { err = 1; goto beach_source; }
37
38  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
39  if (channels == 0 ) channels = aubio_source_get_channels(i);
40
41  fmat_t *mat = new_fmat(channels, hop_size);
42  if (!mat) { err = 1; goto beach_fmat; }
43
44  aubio_sink_t *o = new_aubio_sink(sink_path, 0);
45  if (!o) { err = 1; goto beach_sink; }
46  err = aubio_sink_preset_samplerate(o, samplerate);
47  if (err) { goto beach; }
48  err = aubio_sink_preset_channels(o, channels);
49  if (err) { goto beach; }
50
51  do {
52    aubio_source_do_multi(i, mat, &read);
53    aubio_sink_do_multi(o, mat, read);
54    n_frames += read;
55  } while ( read == hop_size );
56
57  PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
58      n_frames, samplerate, channels, n_frames / hop_size,
59      source_path, sink_path);
60  PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
61      aubio_sink_get_samplerate(o),
62      aubio_sink_get_channels(o) );
63
64beach:
65  del_aubio_sink(o);
66beach_sink:
67  del_fmat(mat);
68beach_fmat:
69  del_aubio_source(i);
70beach_source:
71  return err;
72}
Note: See TracBrowser for help on using the repository browser.