summaryrefslogtreecommitdiff
path: root/tests/src/synth/test-sampler.c
blob: 0f3bfa7d0c71fc120bf7b20d4836d275fc76e5c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <aubio.h>
#include "utils_tests.h"

int main (int argc, char **argv)
{
  sint_t err = 0;

  if (argc < 4) {
    err = 2;
    PRINT_ERR("not enough arguments\n");
    PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
    return err;
  }

  uint_t samplerate = 0; // default is the samplerate of input_path
  uint_t hop_size = 256;
  uint_t n_frames = 0, read = 0;

  char_t *source_path = argv[1];
  char_t *sink_path = argv[2];
  char_t *sample_path = argv[3];
  if ( argc == 5 ) samplerate = atoi(argv[4]);

  fvec_t *vec = new_fvec(hop_size);
  aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size);
  if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
  aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);

  aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size);

  aubio_sampler_load (sampler, sample_path);

  do {
    aubio_source_do(source, vec, &read);
    if (n_frames / hop_size == 10) {
      aubio_sampler_play ( sampler );
    }
    if (n_frames / hop_size == 40) {
      aubio_sampler_play ( sampler );
    }
    if (n_frames / hop_size == 70) {
      aubio_sampler_play ( sampler );
    }
    if (n_frames > 10.0 * samplerate) {
      aubio_sampler_stop ( sampler );
    }
    aubio_sampler_do (sampler, vec, vec);
    aubio_sink_do(sink, vec, read);
    n_frames += read;
  } while ( read == hop_size );

  del_aubio_sampler(sampler);
  del_aubio_source(source);
  del_aubio_sink(sink);
  del_fvec(vec);
  aubio_cleanup();

  return 0;
}