Ignore:
Timestamp:
Mar 3, 2013, 7:37:43 PM (7 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/constantq, feature/pitchshift, feature/pydocstrings, feature/timestretch, master, pitchshift, sampler, timestretch, yinfft+
Children:
9547247
Parents:
26775a3
Message:

tests/src/spectral/: improve examples

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/src/spectral/test-phasevoc-jack.c

    r26775a3 r6938a20  
    1515#endif /* HAVE_JACK */
    1616
    17 uint_t testing  = 0;  /* change this to 1 to listen        */
     17uint_t testing  = 0;  // change this to 1 to listen
    1818
    19 uint_t win_s    = 512;/* window size                       */
    20 uint_t hop_s    = 128;/* hop size                          */
    21 uint_t channels = 2;  /* number of audio channels          */
    22 uint_t midiin   = 4;  /* number of midi input channels     */
    23 uint_t midiout  = 2;  /* number of midi output channels    */
    24 uint_t pos      = 0;  /* frames%dspblocksize for jack loop */
     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
     24uint_t pos      = 0; // frames%dspblocksize for jack loop
    2525
    2626fvec_t * in[2];
     
    3232int aubio_process(float **input, float **output, int nframes);
    3333
    34 int main(){
    35         /* allocate some memory */
     34int main ()
     35{
     36  /* allocate some memory */
    3637  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      */
    41         /* allocate fft and other memory space */
    42         pv[i] = new_aubio_pvoc(win_s,hop_s);
    43     }
     38  for (i=0;i<channels;i++) {
     39    in[i]       = new_fvec (hop_s); /* input buffer       */
     40    fftgrain[i] = new_cvec (win_s); /* fft norm and phase */
     41    out[i]      = new_fvec (hop_s); /* output buffer      */
     42    /* allocate fft and other memory space */
     43    pv[i] = new_aubio_pvoc(win_s,hop_s);
     44  }
    4445
    4546#ifdef HAVE_JACK
    46         aubio_jack_t * jack_setup;
    47         jack_setup  = new_aubio_jack(channels, channels,
    48             midiin, midiout,
    49             (aubio_process_func_t)aubio_process);
    50         aubio_jack_activate(jack_setup);
    51         /* stay in main jack loop for 1 seconds only */
    52         do {
    53           sleep(1);
    54         } while(testing);
    55         aubio_jack_close(jack_setup);
     47  aubio_jack_t * jack_setup;
     48  jack_setup  = new_aubio_jack(channels, channels,
     49      midiin, midiout,
     50      (aubio_process_func_t)aubio_process);
     51  aubio_jack_activate(jack_setup);
     52  /* stay in main jack loop for 1 seconds only */
     53  do {
     54    sleep(1);
     55  } while(testing);
     56  aubio_jack_close(jack_setup);
    5657#else
    57         fprintf(stderr, "WARNING: no jack support\n");
     58  fprintf(stderr, "WARNING: no jack support\n");
    5859#endif
    59        
    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     }
    66         aubio_cleanup();
    67         return 0;
     60
     61  for (i=0;i<channels;i++) {
     62    del_aubio_pvoc(pv[i]);
     63    del_cvec(fftgrain[i]);
     64    del_fvec(in[i]);
     65    del_fvec(out[i]);
     66  }
     67  aubio_cleanup();
     68  return 0;
    6869}
    6970
     
    8182    if (pos == hop_s-1) {
    8283      /* block loop */
    83     for (i=0;i<channels;i++) {
    84       aubio_pvoc_do (pv[i], in[i], fftgrain[i]);
    85       // zero phases of first channel
    86       for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.;
    87       // double phases of second channel
    88       for (i=0;i<fftgrain[i]->length;i++) {
    89         fftgrain[1]->phas[i] =
    90           aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.);
     84      for (i=0;i<channels;i++) {
     85        aubio_pvoc_do (pv[i], in[i], fftgrain[i]);
     86        // zero phases of first channel
     87        for (i=0;i<fftgrain[i]->length;i++) fftgrain[0]->phas[i] = 0.;
     88        // double phases of second channel
     89        for (i=0;i<fftgrain[i]->length;i++) {
     90          fftgrain[1]->phas[i] =
     91            aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.);
     92        }
     93        // copy second channel to third one
     94        aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]);
     95        pos = -1;
    9196      }
    92       // copy second channel to third one
    93       aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]);
    94       pos = -1;
    95     }
    9697    }
    9798    pos++;
Note: See TracChangeset for help on using the changeset viewer.