source: tests/src/test-phasevoc-jack.c @ 7e204d01

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 7e204d01 was de2a8af, checked in by Paul Brossier <piem@piem.org>, 17 years ago

move python/tests to tests/python, examples/tests to tests/src, add .bzrignore

  • Property mode set to 100644
File size: 2.6 KB
Line 
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
8#include <unistd.h>  /* pause() or sleep() */
9#include <aubio.h>
10#include <aubioext.h>
11
12uint_t win_s    = 32; /* window size                       */
13uint_t hop_s    = 8;  /* hop size                          */
14uint_t channels = 4;  /* number of channels                */
15uint_t pos      = 0;  /* frames%dspblocksize for jack loop */
16
17fvec_t * in;
18cvec_t * fftgrain;
19fvec_t * out;
20
21aubio_pvoc_t * pv;
22
23#ifdef JACK_SUPPORT
24aubio_jack_t * jack_setup;
25#endif
26
27int aubio_process(float **input, float **output, int nframes);
28
29int 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
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
52       
53        del_aubio_pvoc(pv);
54        del_cvec(fftgrain);
55        del_fvec(in);
56        del_fvec(out);
57        aubio_cleanup();
58        printf("memory freed\n");
59        return 0;
60}
61
62int aubio_process(float **input, float **output, int nframes) {
63  uint_t i;       /*channels*/
64  uint_t j;       /*frames*/
65  for (j=0;j<(unsigned)nframes;j++) {
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}
Note: See TracBrowser for help on using the repository browser.