source: tests/src/effects/test-pitchshift.c @ 3a96d3d

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

[tests] improve pitchshift tests

  • Property mode set to 100644
File size: 2.9 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  uint_t samplerate = 0;
23  uint_t hop_size = 64;
24  smpl_t transpose = 0.;
25  uint_t n_frames = 0, read = 0;
26
27  char_t *source_path = argv[1];
28  char_t *sink_path = argv[2];
29  char_t *mode = "default";
30
31  transpose = 0.;
32
33  if ( argc >= 4 ) transpose = atof(argv[3]);
34  if ( argc >= 5 ) mode = argv[4];
35  if ( argc >= 6 ) hop_size = atoi(argv[5]);
36  if ( argc >= 7 ) samplerate = atoi(argv[6]);
37
38  fvec_t *vec = new_fvec(hop_size);
39  fvec_t *out = new_fvec(hop_size);
40  if (!vec) { err = 1; goto beach_fvec; }
41
42  aubio_source_t *i = new_aubio_source(source_path, samplerate, hop_size);
43  if (!i) { err = 1; goto beach_source; }
44
45  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(i);
46
47  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
48  if (!o) { err = 1; goto beach_sink; }
49
50  aubio_pitchshift_t *ps =
51    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\n",
63      n_frames, samplerate, n_frames / hop_size,
64      source_path);
65  PRINT_MSG("wrote to %s with hop_size: %d, samplerate: %d, latency %d\n",
66      sink_path, hop_size, samplerate, aubio_pitchshift_get_latency(ps));
67
68  del_aubio_pitchshift(ps);
69beach_pitchshift:
70  del_aubio_sink(o);
71beach_sink:
72  del_aubio_source(i);
73beach_source:
74  del_fvec(vec);
75  del_fvec(out);
76beach_fvec:
77  return err;
78}
79
80int test_wrong_params(void)
81{
82  const char_t *mode = "default";
83  smpl_t transpose = 0.;
84  uint_t hop_size = 256;
85  uint_t samplerate = 44100;
86
87  if (new_aubio_pitchshift("??", transpose, hop_size, samplerate)) return 1;
88  if (new_aubio_pitchshift(mode,       28., hop_size, samplerate)) return 1;
89  if (new_aubio_pitchshift(mode, transpose,        0, samplerate)) return 1;
90  if (new_aubio_pitchshift(mode, transpose, hop_size,          0)) return 1;
91
92  aubio_pitchshift_t *p = new_aubio_pitchshift(mode, transpose,
93      hop_size, samplerate);
94  if (!p) return 1;
95  if (!aubio_pitchshift_set_pitchscale(p, 0.1)) return 1;
96  if (!aubio_pitchshift_set_transpose(p, -30)) return 1;
97  del_aubio_pitchshift(p);
98
99  return run_on_default_source_and_sink(main);
100}
Note: See TracBrowser for help on using the repository browser.