source: examples/tests/test-phasevoc-jack.c @ 4e9101e

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

complete test-phasevoc-jack memory freeing, use sleep instead of pause
complete test-phasevoc-jack memory freeing, use sleep instead of pause

  • 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 */
16uint_t usejack  = 1;
17
18fvec_t * in;
19cvec_t * fftgrain;
20fvec_t * out;
21
22aubio_pvoc_t * pv;
23
24aubio_jack_t * jack_setup;
25
26int aubio_process(float **input, float **output, int nframes);
27
28int main(){
29        /* allocate some memory */
30        in       = new_fvec (hop_s, channels); /* input buffer       */
31        fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
32        out      = new_fvec (hop_s, channels); /* output buffer      */
33        /* allocate fft and other memory space */
34        pv = new_aubio_pvoc(win_s,hop_s,channels);
35        /* fill input with some data */
36        printf("initialised\n");
37        /* execute stft */
38        aubio_pvoc_do (pv,in,fftgrain);
39        printf("computed forward\n");
40        /* execute inverse fourier transform */
41        aubio_pvoc_rdo(pv,fftgrain,out);
42        printf("computed backard\n");
43
44        if (usejack) {
45                jack_setup  = new_aubio_jack(channels, channels,
46                                (aubio_process_func_t)aubio_process);
47                aubio_jack_activate(jack_setup);
48                sleep(10); //pause(); /* enter main jack loop */
49                aubio_jack_close(jack_setup);
50        }
51       
52        del_aubio_pvoc(pv);
53        del_cvec(fftgrain);
54        del_fvec(in);
55        del_fvec(out);
56        aubio_cleanup();
57        printf("memory freed\n");
58        return 0;
59}
60
61int aubio_process(float **input, float **output, int nframes) {
62  uint_t i;       /*channels*/
63  uint_t j;       /*frames*/
64  for (j=0;j<(unsigned)nframes;j++) {
65    for (i=0;i<channels;i++) {
66      /* write input to datanew */
67      fvec_write_sample(in, input[i][j], i, pos);
68      /* put synthnew in output */
69      output[i][j] = fvec_read_sample(out, i, pos);
70    }
71    /*time for fft*/
72    if (pos == hop_s-1) {
73      /* block loop */
74      aubio_pvoc_do (pv,in, fftgrain);
75      //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] *= 2.;
76      //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] = 0.;
77      aubio_pvoc_rdo(pv,fftgrain,out);
78      pos = -1;
79    }
80    pos++;
81  }
82  return 0;
83}
Note: See TracBrowser for help on using the repository browser.