source: tests/src/io/test-sink-multi.c @ 9f060d1

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5sampler
Last change on this file since 9f060d1 was 4ed4b1f, checked in by Paul Brossier <piem@piem.org>, 11 years ago

src/io/sink.h: add do_multi, preset_samplerate, preset_channels, get_samplerate, and get_channels

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