source: tests/src/io/test-sink_sndfile.c @ d45f527

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

tests/src/io/test-sink*: improve, unify

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[856ceb5]1#define AUBIO_UNSTABLE 1
[2c3d4ca]2#include <aubio.h>
[6d3777a]3#include "config.h"
[248da64]4#include "utils_tests.h"
[2c3d4ca]5
[856ceb5]6// this file uses the unstable aubio api, please use aubio_sink instead
7// see src/io/sink.h and tests/src/sink/test-sink.c
8
[248da64]9int main (int argc, char **argv)
10{
11  sint_t err = 0;
12
13  if (argc < 3) {
14    err = 2;
15    PRINT_ERR("not enough arguments\n");
[9f68f11]16    PRINT_MSG("usage: %s <input_path> <output_path> [samplerate] [hop_size]\n", argv[0]);
[248da64]17    return err;
18  }
[2c3d4ca]19
20#ifdef HAVE_SNDFILE
[d7ac23f]21  uint_t samplerate = 0;
[2c3d4ca]22  uint_t hop_size = 512;
[248da64]23  uint_t n_frames = 0, read = 0;
24
25  char_t *source_path = argv[1];
26  char_t *sink_path = argv[2];
[9f68f11]27
28  if ( argc >= 4 ) samplerate = atoi(argv[3]);
29  if ( argc >= 5 ) hop_size = atoi(argv[4]);
30  if ( argc >= 6 ) {
31    err = 2;
32    PRINT_ERR("too many arguments\n");
33    return err;
34  }
[248da64]35
[2c3d4ca]36  fvec_t *vec = new_fvec(hop_size);
[9f68f11]37  if (!vec) { err = 1; goto beach_fvec; }
38
39  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
40  if (!i) { err = 1; goto beach_source; }
41
42  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
[2c3d4ca]43
[9f68f11]44  aubio_sink_sndfile_t *o = new_aubio_sink_sndfile(sink_path, samplerate);
45  if (!o) { err = 1; goto beach_sink; }
[2c3d4ca]46
[248da64]47  do {
[9f68f11]48    aubio_source_do(i, vec, &read);
[d9ab958]49    aubio_sink_sndfile_do(o, vec, read);
[248da64]50    n_frames += read;
51  } while ( read == hop_size );
52
[9f68f11]53  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
54      n_frames, samplerate, n_frames / hop_size,
55      source_path, sink_path);
[2c3d4ca]56
57  del_aubio_sink_sndfile(o);
[9f68f11]58beach_sink:
59  del_aubio_source(i);
60beach_source:
[2c3d4ca]61  del_fvec(vec);
[9f68f11]62beach_fvec:
[2c3d4ca]63#else
[248da64]64  err = 3;
[856ceb5]65  PRINT_ERR("aubio was not compiled with aubio_source_sndfile\n");
[2c3d4ca]66#endif /* HAVE_SNDFILE */
67  return err;
68}
Note: See TracBrowser for help on using the repository browser.