source: examples/tests/test-phasevoc-jack.c @ 08f6688

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5pitchshiftsamplertimestretchyinfft+
Last change on this file since 08f6688 was 437fa65, checked in by Paul Brossier <piem@altern.org>, 19 years ago

added examples, bumped VERSION to 0.2.0beta1

  • Property mode set to 100644
File size: 2.5 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() */
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                pause(); /* enter main jack loop */
49                aubio_jack_close(jack_setup);
50        }
51       
52        del_aubio_pvoc(pv);
53        printf("memory freed\n");
54        return 0;
55}
56
57int aubio_process(float **input, float **output, int nframes) {
58  uint_t i;       /*channels*/
59  uint_t j;       /*frames*/
60  for (j=0;j<nframes;j++) {
61    for (i=0;i<channels;i++) {
62      /* write input to datanew */
63      fvec_write_sample(in, input[i][j], i, pos);
64      /* put synthnew in output */
65      output[i][j] = fvec_read_sample(out, i, pos);
66    }
67    /*time for fft*/
68    if (pos == hop_s-1) {
69      /* block loop */
70      aubio_pvoc_do (pv,in, fftgrain);
71      //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] *= 2.;
72      //for (i=0;i<fftgrain->length;i++) fftgrain->phas[0][i] = 0.;
73      aubio_pvoc_rdo(pv,fftgrain,out);
74      pos = -1;
75    }
76    pos++;
77  }
78  return 0;
79}
Note: See TracBrowser for help on using the repository browser.