1 /** Test for phase vocoder in jack
3 * This program should start correctly, when jackd is started or when
4 * using JACK_START_SERVER=true and reconstruct each audio input channel
5 * on the corresponding output channel with some strange effects and a
6 * delay equal to the hop size (hop_s).
11 #include <unistd.h> /* sleep() */
15 uint_t testing = 0; /* change this to 1 to listen */
17 uint_t win_s = 512;/* window size */
18 uint_t hop_s = 128;/* hop size */
19 uint_t channels = 2; /* number of audio channels */
20 uint_t midiin = 4; /* number of midi input channels */
21 uint_t midiout = 2; /* number of midi output channels */
22 uint_t pos = 0; /* frames%dspblocksize for jack loop */
30 int aubio_process(float **input, float **output, int nframes);
33 /* allocate some memory */
35 for (i=0;i<channels;i++) {
36 in[i] = new_fvec (hop_s); /* input buffer */
37 fftgrain[i] = new_cvec (win_s); /* fft norm and phase */
38 out[i] = new_fvec (hop_s); /* output buffer */
39 /* allocate fft and other memory space */
40 pv[i] = new_aubio_pvoc(win_s,hop_s);
44 aubio_jack_t * jack_setup;
45 jack_setup = new_aubio_jack(channels, channels,
47 (aubio_process_func_t)aubio_process);
48 aubio_jack_activate(jack_setup);
49 /* stay in main jack loop for 1 seconds only */
53 aubio_jack_close(jack_setup);
55 fprintf(stderr, "WARNING: no jack support\n");
58 for (i=0;i<channels;i++) {
59 del_aubio_pvoc(pv[i]);
60 del_cvec(fftgrain[i]);
68 int aubio_process(float **input, float **output, int nframes) {
69 uint_t i; /*channels*/
71 for (j=0;j<(unsigned)nframes;j++) {
72 for (i=0;i<channels;i++) {
73 /* write input to datanew */
74 fvec_write_sample(in[i], input[i][j], pos);
75 /* put synthnew in output */
76 output[i][j] = fvec_read_sample(out[i], pos);
81 for (i=0;i<channels;i++) {
82 aubio_pvoc_do (pv[i], in[i], fftgrain[i]);
83 // zero phases of first channel
84 for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.;
85 // double phases of second channel
86 for (i=0;i<fftgrain[i]->length;i++) {
87 fftgrain[1]->phas[i] =
88 aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.);
90 // copy second channel to third one
91 aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]);