source: tests/src/spectral/test-phasevoc-jack.c @ 9d6001cb

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

tests/src: fix memory leaks

  • Property mode set to 100644
File size: 2.9 KB
RevLine 
[c3f4173]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).
[437fa65]7 *
8 */
9
[7b485af]10#include <stdio.h>
[c3f4173]11#include <unistd.h>  /* sleep() */
[7e20db8b]12#include <aubio.h>
[9d6001cb]13#ifdef HAVE_JACK
[740f06b]14#include "jackio.h"
[9d6001cb]15#endif /* HAVE_JACK */
[437fa65]16
[7b485af]17uint_t testing  = 0;  /* change this to 1 to listen        */
[c3f4173]18
19uint_t win_s    = 512;/* window size                       */
20uint_t hop_s    = 128;/* hop size                          */
21uint_t channels = 2;  /* number of audio channels          */
22uint_t midiin   = 4;  /* number of midi input channels     */
23uint_t midiout  = 2;  /* number of midi output channels    */
[7e20db8b]24uint_t pos      = 0;  /* frames%dspblocksize for jack loop */
[437fa65]25
[aea235c]26fvec_t * in[2];
27cvec_t * fftgrain[2];
28fvec_t * out[2];
[437fa65]29
[aea235c]30aubio_pvoc_t * pv[2];
[437fa65]31
32int aubio_process(float **input, float **output, int nframes);
33
34int main(){
35        /* allocate some memory */
[aea235c]36  uint_t i;
37    for (i=0;i<channels;i++) {
38        in[i]       = new_fvec (hop_s); /* input buffer       */
39        fftgrain[i] = new_cvec (win_s); /* fft norm and phase */
40        out[i]      = new_fvec (hop_s); /* output buffer      */
[437fa65]41        /* allocate fft and other memory space */
[aea235c]42        pv[i] = new_aubio_pvoc(win_s,hop_s);
43    }
[437fa65]44
[b511fa9]45#ifdef HAVE_JACK
[c3f4173]46        aubio_jack_t * jack_setup;
47        jack_setup  = new_aubio_jack(channels, channels, 
48            midiin, midiout,
49            (aubio_process_func_t)aubio_process);
[8659f2c]50        aubio_jack_activate(jack_setup);
[c3f4173]51        /* stay in main jack loop for 1 seconds only */
52        do {
53          sleep(1);
54        } while(testing);
[8659f2c]55        aubio_jack_close(jack_setup);
[7b485af]56#else
57        fprintf(stderr, "WARNING: no jack support\n");
[8659f2c]58#endif
[437fa65]59       
[aea235c]60    for (i=0;i<channels;i++) {
61        del_aubio_pvoc(pv[i]);
62        del_cvec(fftgrain[i]);
63        del_fvec(in[i]);
64        del_fvec(out[i]);
65    }
[7e20db8b]66        aubio_cleanup();
[437fa65]67        return 0;
68}
69
70int aubio_process(float **input, float **output, int nframes) {
71  uint_t i;       /*channels*/
72  uint_t j;       /*frames*/
[92eea84]73  for (j=0;j<(unsigned)nframes;j++) {
[437fa65]74    for (i=0;i<channels;i++) {
75      /* write input to datanew */
[aea235c]76      fvec_write_sample(in[i], input[i][j], pos);
[437fa65]77      /* put synthnew in output */
[aea235c]78      output[i][j] = fvec_read_sample(out[i], pos);
[437fa65]79    }
80    /*time for fft*/
81    if (pos == hop_s-1) {
82      /* block loop */
[aea235c]83    for (i=0;i<channels;i++) {
84      aubio_pvoc_do (pv[i], in[i], fftgrain[i]);
[c3f4173]85      // zero phases of first channel
[aea235c]86      for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.; 
[c3f4173]87      // double phases of second channel
[aea235c]88      for (i=0;i<fftgrain[i]->length;i++) {
89        fftgrain[1]->phas[i] = 
90          aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.); 
[c3f4173]91      }
92      // copy second channel to third one
[aea235c]93      aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]);
[437fa65]94      pos = -1;
95    }
[aea235c]96    }
[437fa65]97    pos++;
98  }
99  return 0;
100}
Note: See TracBrowser for help on using the repository browser.