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

feature/crepe_org
Last change on this file since 6f330f12 was 0de816c, checked in by Paul Brossier <piem@piem.org>, 6 years ago

[tests] fix argument parsing in onset and wavetable

  • Property mode set to 100644
File size: 1.7 KB
RevLine 
[dd15573]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) {
[abe67e1]9    PRINT_ERR("not enough arguments, running tests\n");
10    err = run_on_default_sink(main);
[dd15573]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];
[0de816c]20  if ( argc >= 4 ) samplerate = atoi(argv[3]);
21  if ( argc >= 3 ) freq = atof(argv[2]);
[dd15573]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.