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