[c3f4173] | 1 | /** Test for phase vocoder in jack |
---|
| 2 | * |
---|
| 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). |
---|
[437fa65] | 7 | * |
---|
| 8 | */ |
---|
| 9 | |
---|
[c3f4173] | 10 | #include <unistd.h> /* sleep() */ |
---|
[7e20db8b] | 11 | #include <aubio.h> |
---|
| 12 | #include <aubioext.h> |
---|
[437fa65] | 13 | |
---|
[c3f4173] | 14 | uint_t testing = 1; /* change this to 1 to listen */ |
---|
| 15 | |
---|
| 16 | uint_t win_s = 512;/* window size */ |
---|
| 17 | uint_t hop_s = 128;/* hop size */ |
---|
| 18 | uint_t channels = 2; /* number of audio channels */ |
---|
| 19 | uint_t midiin = 4; /* number of midi input channels */ |
---|
| 20 | uint_t midiout = 2; /* number of midi output channels */ |
---|
[7e20db8b] | 21 | uint_t pos = 0; /* frames%dspblocksize for jack loop */ |
---|
[437fa65] | 22 | |
---|
| 23 | fvec_t * in; |
---|
| 24 | cvec_t * fftgrain; |
---|
| 25 | fvec_t * out; |
---|
| 26 | |
---|
| 27 | aubio_pvoc_t * pv; |
---|
| 28 | |
---|
| 29 | int aubio_process(float **input, float **output, int nframes); |
---|
| 30 | |
---|
| 31 | int main(){ |
---|
| 32 | /* allocate some memory */ |
---|
| 33 | in = new_fvec (hop_s, channels); /* input buffer */ |
---|
| 34 | fftgrain = new_cvec (win_s, channels); /* fft norm and phase */ |
---|
| 35 | out = new_fvec (hop_s, channels); /* output buffer */ |
---|
| 36 | /* allocate fft and other memory space */ |
---|
| 37 | pv = new_aubio_pvoc(win_s,hop_s,channels); |
---|
| 38 | |
---|
[b511fa9] | 39 | #ifdef HAVE_JACK |
---|
[c3f4173] | 40 | aubio_jack_t * jack_setup; |
---|
| 41 | jack_setup = new_aubio_jack(channels, channels, |
---|
| 42 | midiin, midiout, |
---|
| 43 | (aubio_process_func_t)aubio_process); |
---|
[8659f2c] | 44 | aubio_jack_activate(jack_setup); |
---|
[c3f4173] | 45 | /* stay in main jack loop for 1 seconds only */ |
---|
| 46 | do { |
---|
| 47 | sleep(1); |
---|
| 48 | } while(testing); |
---|
[8659f2c] | 49 | aubio_jack_close(jack_setup); |
---|
| 50 | #endif |
---|
[437fa65] | 51 | |
---|
| 52 | del_aubio_pvoc(pv); |
---|
[7e20db8b] | 53 | del_cvec(fftgrain); |
---|
| 54 | del_fvec(in); |
---|
| 55 | del_fvec(out); |
---|
| 56 | aubio_cleanup(); |
---|
[437fa65] | 57 | return 0; |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | int aubio_process(float **input, float **output, int nframes) { |
---|
| 61 | uint_t i; /*channels*/ |
---|
| 62 | uint_t j; /*frames*/ |
---|
[92eea84] | 63 | for (j=0;j<(unsigned)nframes;j++) { |
---|
[437fa65] | 64 | for (i=0;i<channels;i++) { |
---|
| 65 | /* write input to datanew */ |
---|
| 66 | fvec_write_sample(in, input[i][j], i, pos); |
---|
| 67 | /* put synthnew in output */ |
---|
| 68 | output[i][j] = fvec_read_sample(out, i, pos); |
---|
| 69 | } |
---|
| 70 | /*time for fft*/ |
---|
| 71 | if (pos == hop_s-1) { |
---|
| 72 | /* block loop */ |
---|
| 73 | aubio_pvoc_do (pv,in, fftgrain); |
---|
[c3f4173] | 74 | // zero phases of first channel |
---|
| 75 | for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] = 0.; |
---|
| 76 | // double phases of second channel |
---|
| 77 | for (i=0;i<fftgrain->length;i++) { |
---|
| 78 | fftgrain->phas[1][i] = |
---|
| 79 | aubio_unwrap2pi (fftgrain->phas[1][i] * 2.); |
---|
| 80 | } |
---|
| 81 | // copy second channel to third one |
---|
[437fa65] | 82 | aubio_pvoc_rdo(pv,fftgrain,out); |
---|
| 83 | pos = -1; |
---|
| 84 | } |
---|
| 85 | pos++; |
---|
| 86 | } |
---|
| 87 | return 0; |
---|
| 88 | } |
---|