source: tests/src/effects/test-pitchshift.c @ 687835d

feature/cnnfeature/crepefeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 687835d was 687835d, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] pitchshift tests to pass without rubberband

  • Property mode set to 100644
File size: 3.0 KB
Line 
1#define AUBIO_UNSTABLE 1
2#include <aubio.h>
3#include "utils_tests.h"
4
5int test_wrong_params(void);
6
7int main (int argc, char **argv)
8{
9  sint_t err = 0;
10
11  if (argc < 3) {
12    PRINT_ERR("not enough arguments, running tests\n");
13    err = test_wrong_params();
14    PRINT_MSG("usage: %s <input_path> <output_path> [transpose] ", argv[0]);
15    PRINT_MSG("[mode] [hop_size] [samplerate]\n");
16    PRINT_MSG(" with [transpose] a number of semi tones in the range "
17        " [-24, 24], and [mode] in 'default', 'crispness:0',"
18        " 'crispness:1', ... 'crispness:6'\n");
19    return err;
20  }
21
22#ifdef HAVE_RUBBERBAND
23  uint_t samplerate = 0;
24  uint_t hop_size = 64;
25  smpl_t transpose = 0.;
26  uint_t n_frames = 0, read = 0;
27
28  char_t *source_path = argv[1];
29  char_t *sink_path = argv[2];
30  char_t *mode = "default";
31
32  transpose = 0.;
33
34  if ( argc >= 4 ) transpose = atof(argv[3]);
35  if ( argc >= 5 ) mode = argv[4];
36  if ( argc >= 6 ) hop_size = atoi(argv[5]);
37  if ( argc >= 7 ) samplerate = atoi(argv[6]);
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 =
52    new_aubio_pitchshift(mode, transpose, hop_size, samplerate);
53  if (!ps) { err = 1; goto beach_pitchshift; }
54
55  do {
56    aubio_source_do(i, vec, &read);
57    //aubio_pitchshift_set_transpose(ps, tranpose);
58    aubio_pitchshift_do(ps, vec, out);
59    aubio_sink_do(o, out, read);
60    n_frames += read;
61  } while ( read == hop_size );
62
63  PRINT_MSG("read %d frames at %dHz (%d blocks) from %s\n",
64      n_frames, samplerate, n_frames / hop_size,
65      source_path);
66  PRINT_MSG("wrote to %s with hop_size: %d, samplerate: %d, latency %d\n",
67      sink_path, hop_size, samplerate, aubio_pitchshift_get_latency(ps));
68
69  del_aubio_pitchshift(ps);
70beach_pitchshift:
71  del_aubio_sink(o);
72beach_sink:
73  del_aubio_source(i);
74beach_source:
75  del_fvec(vec);
76  del_fvec(out);
77beach_fvec:
78#else
79  err = 0;
80  PRINT_ERR("aubio was not compiled with rubberband\n");
81#endif
82  return err;
83}
84
85int test_wrong_params(void)
86{
87  const char_t *mode = "default";
88  smpl_t transpose = 0.;
89  uint_t hop_size = 256;
90  uint_t samplerate = 44100;
91
92  if (new_aubio_pitchshift("??", transpose, hop_size, samplerate)) return 1;
93  if (new_aubio_pitchshift(mode,       28., hop_size, samplerate)) return 1;
94  if (new_aubio_pitchshift(mode, transpose,        0, samplerate)) return 1;
95  if (new_aubio_pitchshift(mode, transpose, hop_size,          0)) return 1;
96
97  aubio_pitchshift_t *p = new_aubio_pitchshift(mode, transpose,
98      hop_size, samplerate);
99#ifdef HAVE_RUBBERBAND
100  if (!p) return 1;
101  if (!aubio_pitchshift_set_pitchscale(p, 0.1)) return 1;
102  if (!aubio_pitchshift_set_transpose(p, -30)) return 1;
103  del_aubio_pitchshift(p);
104#else
105  if (p) return 1;
106#endif
107
108  return run_on_default_source_and_sink(main);
109}
Note: See TracBrowser for help on using the repository browser.