source: tests/src/test-phasevoc-jack.c @ 69aaefbd

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 69aaefbd was 740f06b, checked in by Paul Brossier <piem@piem.org>, 15 years ago

ext/, examples/, swig/, python/, tests/: remove libaubioext, make libsamplerate optional

  • Property mode set to 100644
File size: 2.7 KB
Line 
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 <unistd.h>  /* sleep() */
11#include <aubio.h>
12#include "jackio.h"
13
14uint_t testing  = 1;  /* change this to 1 to listen        */
15
16uint_t win_s    = 512;/* window size                       */
17uint_t hop_s    = 128;/* hop size                          */
18uint_t channels = 2;  /* number of audio channels          */
19uint_t midiin   = 4;  /* number of midi input channels     */
20uint_t midiout  = 2;  /* number of midi output channels    */
21uint_t pos      = 0;  /* frames%dspblocksize for jack loop */
22
23fvec_t * in;
24cvec_t * fftgrain;
25fvec_t * out;
26
27aubio_pvoc_t * pv;
28
29int aubio_process(float **input, float **output, int nframes);
30
31int 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
39#ifdef HAVE_JACK
40        aubio_jack_t * jack_setup;
41        jack_setup  = new_aubio_jack(channels, channels, 
42            midiin, midiout,
43            (aubio_process_func_t)aubio_process);
44        aubio_jack_activate(jack_setup);
45        /* stay in main jack loop for 1 seconds only */
46        do {
47          sleep(1);
48        } while(testing);
49        aubio_jack_close(jack_setup);
50#endif
51       
52        del_aubio_pvoc(pv);
53        del_cvec(fftgrain);
54        del_fvec(in);
55        del_fvec(out);
56        aubio_cleanup();
57        return 0;
58}
59
60int aubio_process(float **input, float **output, int nframes) {
61  uint_t i;       /*channels*/
62  uint_t j;       /*frames*/
63  for (j=0;j<(unsigned)nframes;j++) {
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);
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
82      aubio_pvoc_rdo(pv,fftgrain,out);
83      pos = -1;
84    }
85    pos++;
86  }
87  return 0;
88}
Note: See TracBrowser for help on using the repository browser.