source: tests/src/effects/test-timestretch.c @ c62243f

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

[tests] use ABS in test-timestretch

  • Property mode set to 100644
File size: 5.1 KB
Line 
1#define AUBIO_UNSTABLE 1
2#include <aubio.h>
3#include "aubio_priv.h"
4#include "utils_tests.h"
5
6int test_wrong_params(void);
7
8int main (int argc, char **argv)
9{
10  sint_t err = 0;
11
12  if (argc < 3 || argc >= 9) {
13    PRINT_ERR("wrong number of arguments, running tests\n");
14    err = test_wrong_params();
15    PRINT_MSG("usage: %s <input_path> <output_path> <stretch> [transpose] [mode] [hop_size] [samplerate]\n", argv[0]);
16    PRINT_MSG(" with <stretch> a time stretching ratio in the range [0.025, 10.]\n");
17    PRINT_MSG("      [transpose] a number of semi tones in the range [-24, 24]\n");
18    PRINT_MSG("  and [mode] in 'default', 'crispness:0', ..., 'crispness:6'\n");
19    return err;
20  }
21
22#ifdef HAVE_RUBBERBAND
23  uint_t samplerate = 0; // using source samplerate
24  uint_t hop_size = 64;
25  smpl_t transpose = 0.;
26  smpl_t stretch = 1.;
27  uint_t n_frames = 0, read = 0;
28  uint_t eof = 0, source_read = 0;
29
30  char_t *source_path = argv[1];
31  char_t *sink_path = argv[2];
32  char_t *mode = "default";
33
34  if ( argc >= 4 ) stretch = atof(argv[3]);
35  if ( argc >= 5 ) transpose = atof(argv[4]);
36  if ( argc >= 6 ) mode = argv[5];
37  if ( argc >= 7 ) hop_size = atoi(argv[6]);
38  if ( argc >= 8 ) samplerate = atoi(argv[7]);
39
40  uint_t source_hopsize = 2048;
41  aubio_source_t *s = new_aubio_source(source_path, samplerate, source_hopsize);
42  if (!s) { err = 1; goto beach_source; }
43  if (samplerate == 0) samplerate = aubio_source_get_samplerate(s);
44
45  fvec_t *in = new_fvec(source_hopsize);
46  fvec_t *out = new_fvec(hop_size);
47  if (!out || !in) { err = 1; goto beach_fvec; }
48
49  aubio_timestretch_t *ps = new_aubio_timestretch(mode, stretch, hop_size,
50      samplerate);
51  if (!ps) { err = 1; goto beach_timestretch; }
52  //if (samplerate == 0 ) samplerate = aubio_timestretch_get_samplerate(ps);
53
54  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
55  if (!o) { err = 1; goto beach_sink; }
56
57  if (transpose != 0) aubio_timestretch_set_transpose(ps, transpose);
58
59  do {
60    //aubio_timestretch_set_stretch(ps, stretch);
61    //aubio_timestretch_set_transpose(ps, transpose);
62
63    while (aubio_timestretch_get_available(ps) < (sint_t)hop_size && !eof) {
64      aubio_source_do(s, in, &source_read);
65      aubio_timestretch_push(ps, in, source_read);
66      if (source_read < in->length) eof = 1;
67    }
68#if 0
69    if (n_frames == hop_size * 200) {
70      PRINT_MSG("sampler: setting stretch gave %d\n",
71          aubio_timestretch_set_stretch(ps, 2.) );
72      PRINT_MSG("sampler: getting stretch gave %f\n",
73          aubio_timestretch_get_stretch(ps) );
74      PRINT_MSG("sampler: setting transpose gave %d\n",
75          aubio_timestretch_set_transpose(ps, 12.) );
76      PRINT_MSG("sampler: getting transpose gave %f\n",
77          aubio_timestretch_get_transpose(ps) );
78    }
79#endif
80    aubio_timestretch_do(ps, out, &read);
81    aubio_sink_do(o, out, read);
82    n_frames += read;
83  } while ( read == hop_size );
84
85  PRINT_MSG("wrote %d frames at %dHz (%d blocks) from %s written to %s\n",
86      n_frames, samplerate, n_frames / hop_size,
87      source_path, sink_path);
88
89  del_aubio_sink(o);
90beach_sink:
91  del_aubio_timestretch(ps);
92beach_timestretch:
93  del_fvec(out);
94  del_fvec(in);
95beach_fvec:
96  del_aubio_source(s);
97beach_source:
98#else
99  err = 0;
100  PRINT_ERR("aubio was not compiled with rubberband\n");
101#endif
102  return err;
103}
104
105int test_wrong_params(void)
106{
107  const char_t *mode = "default";
108  smpl_t stretch = 1.;
109  uint_t hop_size = 256;
110  uint_t samplerate = 44100;
111
112  if (new_aubio_timestretch("ProcessOffline:?:", stretch, hop_size, samplerate)) return 1;
113  if (new_aubio_timestretch("", stretch, hop_size, samplerate)) return 1;
114  if (new_aubio_timestretch(mode,     41., hop_size, samplerate)) return 1;
115  if (new_aubio_timestretch(mode, stretch,        0, samplerate)) return 1;
116  if (new_aubio_timestretch(mode, stretch, hop_size,          0)) return 1;
117
118  aubio_timestretch_t *p = new_aubio_timestretch(mode, stretch, hop_size,
119      samplerate);
120#ifdef HAVE_RUBBERBAND
121  if (!p) return 1;
122
123  if (aubio_timestretch_get_latency(p) == 0) return 1;
124
125  if (aubio_timestretch_get_samplerate(p) != samplerate) return 1;
126
127  aubio_timestretch_reset(p);
128
129  if (aubio_timestretch_get_transpose(p) != 0) return 1;
130  if (aubio_timestretch_set_transpose(p, 2.)) return 1;
131  if (ABS(aubio_timestretch_get_transpose(p) - 2.) > 1.e-6) return 1;
132  if (!aubio_timestretch_set_transpose(p, 200.)) return 1;
133  if (!aubio_timestretch_set_transpose(p, -200.)) return 1;
134  if (aubio_timestretch_set_transpose(p, 0.)) return 1;
135
136  if (aubio_timestretch_get_pitchscale(p) != 1) return 1;
137  if (aubio_timestretch_set_pitchscale(p, 2.)) return 1;
138  if (ABS(aubio_timestretch_get_pitchscale(p) - 2.) > 1.e-6) return 1;
139  if (!aubio_timestretch_set_pitchscale(p, 0.)) return 1;
140  if (!aubio_timestretch_set_pitchscale(p, 6.)) return 1;
141
142  if (aubio_timestretch_get_stretch(p) != stretch) return 1;
143  if (aubio_timestretch_set_stretch(p, 2.)) return 1;
144  if (ABS(aubio_timestretch_get_stretch(p) - 2.) > 1.e-6) return 1;
145  if (!aubio_timestretch_set_stretch(p, 0.)) return 1;
146  if (!aubio_timestretch_set_stretch(p, 41.)) return 1;
147
148  del_aubio_timestretch(p);
149#else
150  if (p) return 1;
151#endif
152
153  return run_on_default_source_and_sink(main);
154}
Note: See TracBrowser for help on using the repository browser.