source: tests/src/effects/test-pitchshift.c @ 4ac4ebc

sampler
Last change on this file since 4ac4ebc was 4ac4ebc, checked in by Paul Brossier <piem@piem.org>, 7 years ago

tests/src/effects/test-pitchshift.c: cosmetic changes

  • 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
5int main (int argc, char **argv)
6{
7  sint_t err = 0;
8
9  if (argc < 4) {
10    err = 2;
11    PRINT_ERR("not enough arguments\n");
12    PRINT_MSG("usage: %s <input_path> <output_path> <transpose> [mode] "
13        "[hop_size] [samplerate]\n", argv[0]);
14    PRINT_MSG(" with <transpose> a number of semi tones in the range [-24, 24]\n");
15    PRINT_MSG(" and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n");
16    return err;
17  }
18
19  uint_t samplerate = 0;
20  uint_t hop_size = 64;
21  smpl_t transpose = 0.;
22  uint_t n_frames = 0, read = 0;
23
24  char_t *source_path = argv[1];
25  char_t *sink_path = argv[2];
26  char_t *mode = "default";
27
28  transpose = atof(argv[3]);
29
30  if ( argc >= 5 ) mode = argv[4];
31  if ( argc >= 6 ) hop_size = atoi(argv[5]);
32  if ( argc >= 7 ) samplerate = atoi(argv[6]);
33  if ( argc >= 8 ) {
34    err = 2;
35    PRINT_ERR("too many arguments\n");
36    return err;
37  }
38
39  fvec_t *vec = new_fvec(hop_size);
40  fvec_t *out = new_fvec(hop_size);
41  if (!vec) { err = 1; goto beach_fvec; }
42
43  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
44  if (!i) { err = 1; goto beach_source; }
45
46  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
47
48  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
49  if (!o) { err = 1; goto beach_sink; }
50
51  aubio_pitchshift_t *ps = new_aubio_pitchshift(mode, transpose, hop_size, samplerate);
52  if (!ps) { err = 1; goto beach_pitchshift; }
53
54  do {
55    aubio_source_do(i, vec, &read);
56    //aubio_pitchshift_set_transpose(ps, tranpose);
57    aubio_pitchshift_do(ps, vec, out);
58    aubio_sink_do(o, out, read);
59    n_frames += read;
60  } while ( read == hop_size );
61
62  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s written to %s\n",
63      n_frames, samplerate, n_frames / hop_size,
64      source_path, sink_path);
65
66  del_aubio_pitchshift(ps);
67beach_pitchshift:
68  del_aubio_sink(o);
69beach_sink:
70  del_aubio_source(i);
71beach_source:
72  del_fvec(vec);
73  del_fvec(out);
74beach_fvec:
75  aubio_cleanup();
76  return err;
77}
Note: See TracBrowser for help on using the repository browser.