source: tests/src/synth/test-sampler.c @ 5c849af

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/timestretchfix/ffmpeg5
Last change on this file since 5c849af was 953cde5, checked in by Paul Brossier <piem@piem.org>, 5 years ago

[tests] use run_on_default_source_and_sink in sampler tests

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include <string.h> // strncpy
2#include <limits.h> // PATH_MAX
3#include <aubio.h>
4#include "utils_tests.h"
5
6int main (int argc, char **argv)
7{
8  sint_t err = 0;
9
10  if (argc < 3) {
11    PRINT_ERR("not enough arguments, running tests\n");
12    err = run_on_default_source_and_sink(main);
13    PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
14    return err;
15  }
16
17  uint_t samplerate = 0; // default is the samplerate of input_path
18  uint_t hop_size = 256;
19  uint_t n_frames = 0, read = 0;
20
21  char_t *source_path = argv[1];
22  char_t *sink_path = argv[2];
23  char_t sample_path[PATH_MAX];
24  if ( argc >= 4 ) {
25    strncpy(sample_path, argv[3], PATH_MAX - 1);
26  } else {
27    // use input_path as sample
28    strncpy(sample_path, source_path, PATH_MAX - 1);
29  }
30  sample_path[PATH_MAX - 1] = '\0';
31  if ( argc >= 5 ) samplerate = atoi(argv[4]);
32
33  fvec_t *vec = new_fvec(hop_size);
34  aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size);
35  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
36  aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);
37
38  aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size);
39
40  aubio_sampler_load (sampler, sample_path);
41
42  do {
43    aubio_source_do(source, vec, &read);
44    if (n_frames / hop_size == 10) {
45      aubio_sampler_play ( sampler );
46    }
47    if (n_frames / hop_size == 40) {
48      aubio_sampler_play ( sampler );
49    }
50    if (n_frames / hop_size == 70) {
51      aubio_sampler_play ( sampler );
52    }
53    if (n_frames > 10.0 * samplerate) {
54      aubio_sampler_stop ( sampler );
55    }
56    aubio_sampler_do (sampler, vec, vec);
57    aubio_sink_do(sink, vec, read);
58    n_frames += read;
59  } while ( read == hop_size );
60
61  del_aubio_sampler(sampler);
62  del_aubio_source(source);
63  del_aubio_sink(sink);
64  del_fvec(vec);
65  aubio_cleanup();
66
67  return 0;
68}
Note: See TracBrowser for help on using the repository browser.