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

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

tests/src/effects/test-timestretch.c: update to use new interface

  • Property mode set to 100644
File size: 3.1 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> <stretch> [transpose] [mode] [hop_size] [samplerate]\n", argv[0]);
13    PRINT_MSG(" with <stretch> a time stretching ratio in the range [0.025, 10.]\n");
14    PRINT_MSG("      [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  smpl_t stretch = 1.;
23  uint_t n_frames = 0, read = 0;
24  uint_t eof = 0, source_read = 0;
25
26  char_t *source_path = argv[1];
27  char_t *sink_path = argv[2];
28  char_t *mode = "default";
29
30  stretch = atof(argv[3]);
31
32  if ( argc >= 5 ) transpose = atof(argv[4]);
33  if ( argc >= 6 ) mode = argv[5];
34  if ( argc >= 7 ) hop_size = atoi(argv[6]);
35  if ( argc >= 8 ) samplerate = atoi(argv[7]);
36  if ( argc >= 9 ) {
37    err = 2;
38    PRINT_ERR("too many arguments\n");
39    return err;
40  }
41
42  uint_t source_hopsize = 2048;
43  aubio_source_t *s = new_aubio_source(source_path, samplerate, source_hopsize);
44  if (!s) { err = 1; goto beach_source; }
45  if (samplerate == 0) samplerate = aubio_source_get_samplerate(s);
46
47  fvec_t *in = new_fvec(source_hopsize);
48  fvec_t *out = new_fvec(hop_size);
49  if (!out) { err = 1; goto beach_fvec; }
50
51  aubio_timestretch_t *ps = new_aubio_timestretch(mode, stretch, hop_size,
52      samplerate);
53  if (!ps) { err = 1; goto beach_timestretch; }
54  //if (samplerate == 0 ) samplerate = aubio_timestretch_get_samplerate(ps);
55
56  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
57  if (!o) { err = 1; goto beach_sink; }
58
59  if (transpose != 0) aubio_timestretch_set_transpose(ps, transpose);
60
61  do {
62    //aubio_timestretch_set_stretch(ps, stretch);
63    //aubio_timestretch_set_transpose(ps, transpose);
64
65    while (aubio_timestretch_get_available(ps) < (sint_t)hop_size && !eof) {
66      aubio_source_do(s, in, &source_read);
67      aubio_timestretch_push(ps, in, source_read);
68      if (source_read < in->length) eof = 1;
69    }
70#if 0
71    if (n_frames == hop_size * 200) {
72      PRINT_MSG("sampler: setting stretch gave %d\n",
73          aubio_timestretch_set_stretch(ps, 2.) );
74      PRINT_MSG("sampler: getting stretch gave %f\n",
75          aubio_timestretch_get_stretch(ps) );
76      PRINT_MSG("sampler: setting transpose gave %d\n",
77          aubio_timestretch_set_transpose(ps, 12.) );
78      PRINT_MSG("sampler: getting transpose gave %f\n",
79          aubio_timestretch_get_transpose(ps) );
80    }
81#endif
82    aubio_timestretch_do(ps, out, &read);
83    aubio_sink_do(o, out, read);
84    n_frames += read;
85  } while ( read == hop_size );
86
87  PRINT_MSG("wrote %d frames at %dHz (%d blocks) from %s written to %s\n",
88      n_frames, samplerate, n_frames / hop_size,
89      source_path, sink_path);
90
91  del_aubio_sink(o);
92beach_sink:
93  del_aubio_timestretch(ps);
94beach_timestretch:
95  del_fvec(out);
96beach_fvec:
97  del_aubio_source(s);
98beach_source:
99  return err;
100}
Note: See TracBrowser for help on using the repository browser.