[437fa65] | 1 | /* test sample for phase vocoder |
---|
| 2 | * |
---|
| 3 | * this program should start correctly using JACK_START_SERVER=true and |
---|
| 4 | * reconstruct each audio input frame perfectly on the corresponding input with |
---|
| 5 | * a delay equal to the window size, hop_s. |
---|
| 6 | */ |
---|
| 7 | |
---|
[7e20db8b] | 8 | #include <unistd.h> /* pause() or sleep() */ |
---|
| 9 | #include <aubio.h> |
---|
| 10 | #include <aubioext.h> |
---|
[437fa65] | 11 | |
---|
| 12 | uint_t win_s = 32; /* window size */ |
---|
| 13 | uint_t hop_s = 8; /* hop size */ |
---|
[7e20db8b] | 14 | uint_t channels = 4; /* number of channels */ |
---|
| 15 | uint_t pos = 0; /* frames%dspblocksize for jack loop */ |
---|
[437fa65] | 16 | |
---|
| 17 | fvec_t * in; |
---|
| 18 | cvec_t * fftgrain; |
---|
| 19 | fvec_t * out; |
---|
| 20 | |
---|
| 21 | aubio_pvoc_t * pv; |
---|
| 22 | |
---|
[8659f2c] | 23 | #ifdef JACK_SUPPORT |
---|
[437fa65] | 24 | aubio_jack_t * jack_setup; |
---|
[8659f2c] | 25 | #endif |
---|
[437fa65] | 26 | |
---|
| 27 | int aubio_process(float **input, float **output, int nframes); |
---|
| 28 | |
---|
| 29 | int main(){ |
---|
| 30 | /* allocate some memory */ |
---|
| 31 | in = new_fvec (hop_s, channels); /* input buffer */ |
---|
| 32 | fftgrain = new_cvec (win_s, channels); /* fft norm and phase */ |
---|
| 33 | out = new_fvec (hop_s, channels); /* output buffer */ |
---|
| 34 | /* allocate fft and other memory space */ |
---|
| 35 | pv = new_aubio_pvoc(win_s,hop_s,channels); |
---|
| 36 | /* fill input with some data */ |
---|
| 37 | printf("initialised\n"); |
---|
| 38 | /* execute stft */ |
---|
| 39 | aubio_pvoc_do (pv,in,fftgrain); |
---|
| 40 | printf("computed forward\n"); |
---|
| 41 | /* execute inverse fourier transform */ |
---|
| 42 | aubio_pvoc_rdo(pv,fftgrain,out); |
---|
| 43 | printf("computed backard\n"); |
---|
| 44 | |
---|
[8659f2c] | 45 | #ifdef JACK_SUPPORT |
---|
| 46 | jack_setup = new_aubio_jack(channels, channels, |
---|
| 47 | (aubio_process_func_t)aubio_process); |
---|
| 48 | aubio_jack_activate(jack_setup); |
---|
| 49 | sleep(10); //pause(); /* enter main jack loop */ |
---|
| 50 | aubio_jack_close(jack_setup); |
---|
| 51 | #endif |
---|
[437fa65] | 52 | |
---|
| 53 | del_aubio_pvoc(pv); |
---|
[7e20db8b] | 54 | del_cvec(fftgrain); |
---|
| 55 | del_fvec(in); |
---|
| 56 | del_fvec(out); |
---|
| 57 | aubio_cleanup(); |
---|
[437fa65] | 58 | printf("memory freed\n"); |
---|
| 59 | return 0; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | int aubio_process(float **input, float **output, int nframes) { |
---|
| 63 | uint_t i; /*channels*/ |
---|
| 64 | uint_t j; /*frames*/ |
---|
[92eea84] | 65 | for (j=0;j<(unsigned)nframes;j++) { |
---|
[437fa65] | 66 | for (i=0;i<channels;i++) { |
---|
| 67 | /* write input to datanew */ |
---|
| 68 | fvec_write_sample(in, input[i][j], i, pos); |
---|
| 69 | /* put synthnew in output */ |
---|
| 70 | output[i][j] = fvec_read_sample(out, i, pos); |
---|
| 71 | } |
---|
| 72 | /*time for fft*/ |
---|
| 73 | if (pos == hop_s-1) { |
---|
| 74 | /* block loop */ |
---|
| 75 | aubio_pvoc_do (pv,in, fftgrain); |
---|
| 76 | //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] *= 2.; |
---|
| 77 | //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] = 0.; |
---|
| 78 | aubio_pvoc_rdo(pv,fftgrain,out); |
---|
| 79 | pos = -1; |
---|
| 80 | } |
---|
| 81 | pos++; |
---|
| 82 | } |
---|
| 83 | return 0; |
---|
| 84 | } |
---|