source: tests/src/spectral/test-phasevoc-jack.c @ 02418f6

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

tests/: move file around to match src/

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