source: tests/src/synth/test-wavetable.c @ abe67e1

feature/autosinkfeature/constantqfeature/pitchshiftfeature/pydocstringsfeature/timestretch
Last change on this file since abe67e1 was abe67e1, checked in by Paul Brossier <piem@piem.org>, 13 months ago

[tests] create a temporary sink, use in wavetable test

When called without argument, test-wavetable will invoke the function
run_on_default_sink to create a temporary file and runs the main
function on it.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1#include <aubio.h>
2#include "utils_tests.h"
3
4int main (int argc, char **argv)
5{
6  sint_t err = 0;
7
8  if (argc < 2) {
9    PRINT_ERR("not enough arguments, running tests\n");
10    err = run_on_default_sink(main);
11    PRINT_MSG("usage: %s <output_path> [freq] [samplerate]\n", argv[0]);
12    return err;
13  }
14
15  uint_t samplerate = 44100; // default is the samplerate of input_path
16  uint_t hop_size = 256;
17  smpl_t freq = 440.;
18
19  char_t *sink_path = argv[1];
20  if ( argc == 4 ) samplerate = atoi(argv[3]);
21  if ( argc == 3 ) freq = atof(argv[2]);
22
23  fvec_t *vec = new_fvec(hop_size);
24  aubio_sink_t *sink = new_aubio_sink(sink_path, samplerate);
25
26  aubio_wavetable_t * wavetable = new_aubio_wavetable (samplerate, hop_size);
27
28  // 2 seconds duration, in samples
29  uint_t duration = 2 * samplerate;
30
31  uint_t n_frames = 0;
32  uint_t write = 0;
33
34  aubio_wavetable_play (wavetable);
35  aubio_wavetable_set_freq ( wavetable, freq );
36
37  uint_t region = 0;
38
39  do {
40    if ( n_frames > duration / 3 && region < 1) {
41      aubio_wavetable_stop (wavetable);
42      region++;
43    }
44    if ( n_frames > 2 * duration / 3 && region < 2) {
45      aubio_wavetable_play (wavetable);
46      aubio_wavetable_set_freq ( wavetable, freq  / 2.);
47      region++;
48    }
49    if (duration - n_frames < hop_size * 2 ) {
50      aubio_wavetable_stop( wavetable );
51    }
52    if (duration - n_frames < hop_size ) {
53      write = duration - n_frames;
54    } else {
55      write = hop_size;
56    }
57    aubio_wavetable_do (wavetable, vec, vec);
58    aubio_sink_do(sink, vec, write);
59    n_frames += hop_size;
60  } while ( n_frames <= duration );
61
62  del_aubio_wavetable (wavetable);
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.