source: tests/src/io/test-sink_wavwrite-multi.c @ 0056314

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 0056314 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.2 KB
RevLine 
[870ad70]1#define AUBIO_UNSTABLE 1
2#include <aubio.h>
3#include "utils_tests.h"
4
[2f02d51]5// this file uses the unstable aubio api to test aubio_sink_wavwrite, please
6// use aubio_sink instead see src/io/sink.h and tests/src/sink/test-sink.c
[870ad70]7
8int main (int argc, char **argv)
9{
10  sint_t err = 0;
11
12  if (argc < 3) {
[ee0c4d50]13    PRINT_ERR("not enough arguments, running tests\n");
14    err = run_on_default_source_and_sink(main);
[870ad70]15    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [channels] [hop_size]\n", argv[0]);
16    return err;
17  }
18
[c21553d]19#ifdef HAVE_WAVWRITE
[870ad70]20  uint_t samplerate = 0;
21  uint_t channels = 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 ) channels = atoi(argv[4]);
30  if ( argc >= 6 ) hop_size = atoi(argv[5]);
31  if ( argc >= 7 ) {
32    err = 2;
33    PRINT_ERR("too many arguments\n");
34    return err;
35  }
36
37  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
38  if (!i) { err = 1; goto beach_source; }
39
40  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
41  if (channels == 0 ) channels = aubio_source_get_channels(i);
42
43  fmat_t *mat = new_fmat(channels, hop_size);
44  if (!mat) { err = 1; goto beach_fmat; }
45
46  aubio_sink_wavwrite_t *o = new_aubio_sink_wavwrite(sink_path, 0);
47  if (!o) { err = 1; goto beach_sink; }
48  err = aubio_sink_wavwrite_preset_samplerate(o, samplerate);
49  if (err) { goto beach; }
50  err = aubio_sink_wavwrite_preset_channels(o, channels);
51  if (err) { goto beach; }
52
53  do {
54    aubio_source_do_multi(i, mat, &read);
55    aubio_sink_wavwrite_do_multi(o, mat, read);
56    n_frames += read;
57  } while ( read == hop_size );
58
59  PRINT_MSG("read %d frames at %dHz in %d channels (%d blocks) from %s written to %s\n",
60      n_frames, samplerate, channels, n_frames / hop_size,
61      source_path, sink_path);
62  PRINT_MSG("wrote %s with %dHz in %d channels\n", sink_path,
63      aubio_sink_wavwrite_get_samplerate(o),
64      aubio_sink_wavwrite_get_channels(o) );
65
66beach:
67  del_aubio_sink_wavwrite(o);
68beach_sink:
69  del_fmat(mat);
70beach_fmat:
71  del_aubio_source(i);
72beach_source:
73#else
[ee0c4d50]74  err = 0;
[870ad70]75  PRINT_ERR("aubio was not compiled with aubio_sink_wavwrite\n");
[c21553d]76#endif /* HAVE_WAVWRITE */
[870ad70]77  return err;
78}
Note: See TracBrowser for help on using the repository browser.