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

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

src/effects/timestretch_rubberband.c: improve threading

  • Property mode set to 100644
File size: 3.4 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
25  char_t *source_path = argv[1];
26  char_t *sink_path = argv[2];
27  char_t *mode = "default";
28
29  stretch = atof(argv[3]);
30
31  if ( argc >= 5 ) transpose = atof(argv[4]);
32  if ( argc >= 6 ) mode = argv[5];
33  if ( argc >= 7 ) hop_size = atoi(argv[6]);
34  if ( argc >= 8 ) samplerate = atoi(argv[7]);
35  if ( argc >= 9 ) {
36    err = 2;
37    PRINT_ERR("too many arguments\n");
38    return err;
39  }
40
41  fvec_t *out = new_fvec(hop_size);
42  if (!out) { err = 1; goto beach_fvec; }
43
44  aubio_timestretch_t *ps = new_aubio_timestretch(source_path, mode,
45      stretch, hop_size, samplerate);
46  if (!ps) { err = 1; goto beach_timestretch; }
47  if (samplerate == 0 ) samplerate = aubio_timestretch_get_samplerate(ps);
48
49  aubio_sink_t *o = new_aubio_sink(sink_path, samplerate);
50  if (!o) { err = 1; goto beach_sink; }
51
52  if (transpose != 0) aubio_timestretch_set_transpose(ps, transpose);
53
54#if 0
55  do {
56    if (aubio_timestretch_get_opened(ps) == 0)
57      PRINT_MSG("not opened!\n");
58    aubio_timestretch_get_opened(ps);
59    aubio_timestretch_set_stretch(ps, stretch);
60    aubio_timestretch_set_transpose(ps, transpose);
61    aubio_timestretch_do(ps, out, &read);
62    if (samplerate == 0) {
63      PRINT_MSG("setting samplerate now to %d\n", aubio_timestretch_get_samplerate(ps));
64      samplerate = aubio_timestretch_get_samplerate(ps);
65      aubio_sink_preset_samplerate(o, samplerate);
66      aubio_sink_preset_channels(o, 1);
67    }
68    aubio_sink_do(o, out, read);
69    n_frames += read;
70  } while ( read == hop_size );
71#else
72
73  aubio_timestretch_queue(ps, source_path, samplerate);
74
75  do {
76    aubio_timestretch_get_opened(ps);
77    aubio_timestretch_set_stretch(ps, stretch);
78    aubio_timestretch_set_transpose(ps, transpose);
79    aubio_timestretch_do(ps, out, &read);
80    if (n_frames == 34999 * hop_size) {
81      PRINT_MSG("instant queuing?\n");
82      aubio_timestretch_queue(ps, source_path, samplerate);
83    }
84    if (n_frames == 64999 * hop_size) {
85      PRINT_MSG("instant queuing 2\n");
86      aubio_timestretch_queue(ps, "/dev/null", samplerate);
87    }
88    if (n_frames == 54999 * hop_size) {
89      PRINT_MSG("instant queuing?\n");
90      aubio_timestretch_queue(ps, source_path, samplerate);
91    }
92    if (n_frames == 74999 * hop_size) {
93      PRINT_MSG("instant queuing?\n");
94      aubio_timestretch_queue(ps, source_path, samplerate);
95    }
96    aubio_sink_do(o, out, read);
97  //} while ( read == hop_size );
98    n_frames += hop_size;
99  } while ( n_frames < 100000 * hop_size);
100#endif
101
102  PRINT_MSG("wrote %d frames at %dHz (%d blocks) from %s written to %s\n",
103      n_frames, samplerate, n_frames / hop_size,
104      source_path, sink_path);
105
106  del_aubio_sink(o);
107beach_sink:
108  del_aubio_timestretch(ps);
109beach_timestretch:
110  del_fvec(out);
111beach_fvec:
112  return err;
113}
Note: See TracBrowser for help on using the repository browser.