tests/src/synth/test-sampler.c: added simple test
[aubio.git] / tests / src / synth / test-sampler.c
1 #include <aubio.h>
2 #include "utils_tests.h"
3
4 int main (int argc, char **argv)
5 {
6   sint_t err = 0;
7
8   if (argc < 4) {
9     err = 2;
10     PRINT_ERR("not enough arguments\n");
11     PRINT_MSG("usage: %s <input_path> <output_path> <sample_path> [samplerate]\n", argv[0]);
12     return err;
13   }
14
15   uint_t samplerate = 0; // default is the samplerate of input_path
16   uint_t hop_size = 512;
17   uint_t n_frames = 0, read = 0;
18
19   char_t *source_path = argv[1];
20   char_t *sink_path = argv[2];
21   char_t *sample_path = argv[3];
22   if ( argc == 5 ) samplerate = atoi(argv[4]);
23
24   fvec_t *vec = new_fvec(hop_size);
25   aubio_source_t *source = new_aubio_source(source_path, samplerate, hop_size);
26   if (samplerate == 0 ) samplerate = aubio_source_get_samplerate(source);
27   aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);
28
29   aubio_sampler_t * sampler = new_aubio_sampler (samplerate, hop_size);
30
31   aubio_sampler_load (sampler, sample_path);
32
33   do {
34     aubio_source_do(source, vec, &read);
35     if (n_frames / hop_size == 10) {
36       aubio_sampler_play ( sampler );
37     }
38     if (n_frames / hop_size == 20) {
39       aubio_sampler_play ( sampler );
40     }
41     if (n_frames > 10.0 * samplerate) {
42       aubio_sampler_stop ( sampler );
43     }
44     aubio_sampler_do (sampler, vec, vec);
45     aubio_sink_do(sink, vec, read);
46     n_frames += read;
47   } while ( read == hop_size );
48
49   del_aubio_sampler(sampler);
50   del_aubio_source(source);
51   del_aubio_sink(sink);
52   del_fvec(vec);
53   aubio_cleanup();
54
55   return 0;
56 }