Changeset 6938a20


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

Location:
tests/src/spectral
Files:
8 edited

Legend:

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

    r26775a3 r6938a20  
    1 
    21#include <aubio.h>
    32
    4 int main(){
    5         /* allocate some memory */
    6         uint_t win_s      = 8;                       /* window size        */
    7         fvec_t * in       = new_fvec (win_s); /* input buffer       */
    8         cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    9         fvec_t * out      = new_fvec (win_s); /* output buffer      */
    10         in->data[0] = 1;
    11         in->data[1] = 2;
    12         in->data[2] = 3;
    13         in->data[3] = 4;
    14         in->data[4] = 5;
    15         in->data[5] = 6;
    16         in->data[6] = 5;
    17         in->data[7] = 6;
    18         /* allocate fft and other memory space */
    19         aubio_fft_t * fft = new_aubio_fft(win_s);
    20         /* fill input with some data */
    21         fvec_print(in);
    22         /* execute stft */
    23         aubio_fft_do (fft,in,fftgrain);
    24         cvec_print(fftgrain);
    25         /* execute inverse fourier transform */
    26         aubio_fft_rdo(fft,fftgrain,out);
    27         fvec_print(out);
    28         del_aubio_fft(fft);
    29         del_fvec(in);
    30         del_cvec(fftgrain);
    31         del_fvec(out);
    32         aubio_cleanup();
    33         return 0;
     3int main ()
     4{
     5  uint_t win_s = 8; // window size
     6  fvec_t * in = new_fvec (win_s); // input buffer
     7  cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase
     8  fvec_t * out = new_fvec (win_s); // output buffer
     9  // create fft object
     10  aubio_fft_t * fft = new_aubio_fft(win_s);
     11
     12  // fill input with some data
     13  in->data[0] = 1;
     14  in->data[1] = 2;
     15  in->data[2] = 3;
     16  in->data[3] = 4;
     17  in->data[4] = 5;
     18  in->data[5] = 6;
     19  in->data[6] = 5;
     20  in->data[7] = 6;
     21  fvec_print(in);
     22
     23  // execute stft
     24  aubio_fft_do (fft,in,fftgrain);
     25  cvec_print(fftgrain);
     26
     27  // execute inverse fourier transform
     28  aubio_fft_rdo(fft,fftgrain,out);
     29
     30  // cleam up
     31  fvec_print(out);
     32  del_aubio_fft(fft);
     33  del_fvec(in);
     34  del_cvec(fftgrain);
     35  del_fvec(out);
     36  aubio_cleanup();
     37  return 0;
    3438}
  • tests/src/spectral/test-filterbank.c

    r26775a3 r6938a20  
    1 #define AUBIO_UNSTABLE 1
    2 
    3 #include <stdio.h>
    41#include <aubio.h>
    52
    6 int main (void) {
     3int main ()
     4{
    75  uint_t win_s = 1024; // window size
    86  uint_t n_filters = 13; // number of filters
    9   cvec_t *in = new_cvec (win_s); // input buffer
    10   fvec_t *out = new_fvec (win_s); // vector output */
    11   fmat_t *coeffs = NULL;
    127
    13   // create filterbank
     8  cvec_t *in_spec = new_cvec (win_s); // input vector of samples
     9  fvec_t *out_filters = new_fvec (n_filters); // per-band outputs
     10  fmat_t *coeffs; // pointer to the coefficients
     11
     12  // create filterbank object
    1413  aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s);
    1514
    1615  coeffs = aubio_filterbank_get_coeffs (o);
    17   if (coeffs == NULL) {
    18     return -1;
    19   }
    2016
    21   /*
    22   if (fvec_max (coeffs) != 0.) {
    23     return -1;
    24   }
     17  aubio_filterbank_do (o, in_spec, out_filters);
    2518
    26   if (fvec_min (coeffs) != 0.) {
    27     return -1;
    28   }
    29   */
    30 
    31   fmat_print (coeffs);
    32 
    33   aubio_filterbank_do (o, in, out);
     19  // fmat_print (coeffs);
     20  // cvec_print(in_spec);
     21  // fvec_print(out_filters);
    3422
    3523  del_aubio_filterbank (o);
    36   del_cvec (in);
    37   del_fvec (out);
     24  del_cvec (in_spec);
     25  del_fvec (out_filters);
    3826  aubio_cleanup ();
    3927
  • tests/src/spectral/test-filterbank_mel.c

    r26775a3 r6938a20  
    1 #define AUBIO_UNSTABLE 1
    2 
    3 #include <stdio.h>
    41#include <aubio.h>
    52
    6 int
    7 main (void)
     3int main ()
    84{
    9   /* allocate some memory */
     5  uint_t samplerate = 16000; // samplerate of signal to filter
    106  uint_t win_s = 512; // fft size
    117  uint_t n_filters = 40; // number of filters
    12   cvec_t *in_spec = new_cvec (win_s); // input buffer */
    13   fvec_t *out_filters = new_fvec (n_filters); // output coeffs */
    14   fmat_t *coeffs = NULL;
    15   smpl_t samplerate = 16000.;
    168
    17   /* allocate fft and other memory space */
     9  cvec_t *in_spec = new_cvec (win_s); // input vector of samples
     10  fvec_t *out_filters = new_fvec (n_filters); // per-band outputs
     11  fmat_t *coeffs; // pointer to the coefficients
     12
     13  // create filterbank object
    1814  aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s);
    1915
    20   /* assign Mel-frequency coefficients */
     16  // assign Mel-frequency coefficients
    2117  aubio_filterbank_set_mel_coeffs_slaney (o, samplerate);
    2218
    2319  coeffs = aubio_filterbank_get_coeffs (o);
    2420
    25   fmat_print (coeffs);
    26 
    27   //fprintf(stderr, "%f\n", fvec_sum(coeffs));
    28 
    2921  aubio_filterbank_do (o, in_spec, out_filters);
    3022
    31   fvec_print(in_spec);
    32   fvec_print(out_filters);
     23  // fmat_print (coeffs);
     24  // cvec_print(in_spec);
     25  // fvec_print(out_filters);
    3326
    3427  del_aubio_filterbank (o);
  • tests/src/spectral/test-mfcc.c

    r26775a3 r6938a20  
    11#include <aubio.h>
    22
    3 int
    4 main (void)
     3int main ()
    54{
    6   /* allocate some memory */
    7   uint_t win_s = 512;           /* fft size */
    8   uint_t n_filters = 40;        /* number of filters */
    9   uint_t n_coefs = 13;          /* number of coefficients */
    10   cvec_t *in = new_cvec (win_s);      /* input buffer */
    11   fvec_t *out = new_fvec (n_coefs);     /* input buffer */
    12   smpl_t samplerate = 16000.;
     5  uint_t win_s = 512; // fft size
     6  uint_t n_filters = 40; // number of filters
     7  uint_t n_coefs = 13; // number of coefficients
     8  smpl_t samplerate = 16000.; // samplerate
     9  cvec_t *in = new_cvec (win_s); // input buffer
     10  fvec_t *out = new_fvec (n_coefs); // output coefficients
    1311
    14   /* allocate fft and other memory space */
     12  // create mfcc object
    1513  aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate);
    1614
    1715  cvec_set (in, 1.);
    18 
    19   aubio_mfcc_do (o, in, out);
    20   fvec_print (out);
    2116  aubio_mfcc_do (o, in, out);
    2217  fvec_print (out);
    2318
     19  cvec_set (in, .5);
     20  aubio_mfcc_do (o, in, out);
     21  fvec_print (out);
     22
     23  // clean up
    2424  del_aubio_mfcc (o);
    2525  del_cvec (in);
  • 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++;
  • tests/src/spectral/test-phasevoc.c

    r26775a3 r6938a20  
    1 /* test sample for phase vocoder */
    2 
    3 #include <stdio.h>
    41#include <aubio.h>
    52
    6 int main(){
    7         uint_t win_s    = 1024; /* window size                       */
    8         uint_t hop_s    = 256;  /* hop size                          */
    9         /* allocate some memory */
    10         fvec_t * in       = new_fvec (hop_s); /* input buffer       */
    11         cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    12         fvec_t * out      = new_fvec (hop_s); /* output buffer      */
    13         /* allocate fft and other memory space */
    14         aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s);
    15         /* fill input with some data */
    16         printf("initialised\n");
    17         /* execute stft */
    18         aubio_pvoc_do (pv,in,fftgrain);
    19         printf("computed forward\n");
    20         /* execute inverse fourier transform */
    21         aubio_pvoc_rdo(pv,fftgrain,out);
    22         printf("computed backard\n");
    23         del_aubio_pvoc(pv);
    24         del_fvec(in);
    25         del_cvec(fftgrain);
    26         del_fvec(out);
    27         aubio_cleanup();
    28         printf("memory freed\n");
    29         return 0;
     3int main ()
     4{
     5  uint_t n = 6; // compute n times
     6  uint_t win_s = 32; // window size
     7  uint_t hop_s = win_s / 4; // hop size
     8
     9  fvec_t * in = new_fvec (hop_s); // input buffer
     10  cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase
     11  fvec_t * out = new_fvec (hop_s); // output buffer
     12
     13  // allocate fft and other memory space
     14  aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s);
     15
     16  // fill input with some data
     17  fvec_set (in, 1.);
     18  fvec_print (in);
     19
     20  while ( n-- ) {
     21    // get some fresh input data
     22    // ..
     23
     24    // execute phase vocoder
     25    aubio_pvoc_do (pv,in,fftgrain);
     26
     27    // do something with fftgrain
     28    // ...
     29    cvec_print (fftgrain);
     30
     31    // optionnaly rebuild the signa
     32    aubio_pvoc_rdo(pv,fftgrain,out);
     33
     34    // and do something with the result
     35    // ...
     36    fvec_print (out);
     37  }
     38
     39  // clean up
     40  del_fvec(in);
     41  del_cvec(fftgrain);
     42  del_fvec(out);
     43  del_aubio_pvoc(pv);
     44  aubio_cleanup();
     45
     46  return 0;
    3047}
  • tests/src/spectral/test-specdesc.c

    r26775a3 r6938a20  
    1 
    2 #define AUBIO_UNSTABLE 1
    3 
    41#include <aubio.h>
    52
    6 int
    7 main ()
     3int main ()
    84{
    9   uint_t win_s = 1024;          /* window size */
    10   cvec_t *in = new_cvec (win_s);      /* input buffer */
    11   fvec_t *out = new_fvec (1); /* input buffer */
     5  uint_t win_s = 1024; // window size
     6  cvec_t *in = new_cvec (win_s); // input buffer
     7  fvec_t *out = new_fvec (1); // output spectral descriptor
    128
    139  aubio_specdesc_t *o;
    14  
     10
    1511  o = new_aubio_specdesc ("energy", win_s);
    1612  aubio_specdesc_do (o, in, out);
  • tests/src/spectral/test-tss.c

    r26775a3 r6938a20  
    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 <stdio.h>
    9 #define AUBIO_UNSTABLE 1
    101#include <aubio.h>
    112
    12 int main(){
    13   int i;
    14   uint_t win_s    = 1024; /* window size                       */
    15   uint_t hop_s    = 256;  /* hop size                          */
     3int main ()
     4{
     5  uint_t n = 10; // compute n times
     6  uint_t win_s = 1024; // window size
     7  uint_t hop_s = 256;  // hop size
    168
    17   /* allocate some memory */
    18   fvec_t * in       = new_fvec (hop_s); /* input buffer       */
    19   cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */
    20   cvec_t * cstead   = new_cvec (win_s); /* fft norm and phase */
    21   cvec_t * ctrans   = new_cvec (win_s); /* fft norm and phase */
    22   fvec_t * stead    = new_fvec (hop_s); /* output buffer      */
    23   fvec_t * trans    = new_fvec (hop_s); /* output buffer      */
    24   /* allocate phase vocoders and transient steady-state separation */
     9  // create some vectors
     10  fvec_t * in       = new_fvec (hop_s); // input buffer
     11  cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase
     12  cvec_t * cstead   = new_cvec (win_s); // fft norm and phase
     13  cvec_t * ctrans   = new_cvec (win_s); // fft norm and phase
     14  fvec_t * stead    = new_fvec (hop_s); // output buffer
     15  fvec_t * trans    = new_fvec (hop_s); // output buffer
     16
     17  // create phase vocoder for analysis of input signal
    2518  aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s);
     19  // create transient/steady-state separation object
     20  aubio_tss_t *  tss = new_aubio_tss(win_s,hop_s);
     21  // create phase vocoder objects for synthesis of output signals
    2622  aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s);
    2723  aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s);
    28   aubio_tss_t *  tss = new_aubio_tss(win_s,hop_s);
    29 
    30   /* fill input with some data */
    31   printf("initialised\n");
    3224
    3325  /* execute stft */
    34   for (i = 0; i < 10; i++) {
    35     aubio_pvoc_do (pv,in,fftgrain);
    36     aubio_tss_do  (tss,fftgrain,ctrans,cstead);
    37     aubio_pvoc_rdo(pvt,cstead,stead);
    38     aubio_pvoc_rdo(pvs,ctrans,trans);
     26  while ( n-- ) {
     27    // fftgrain = pv(in)
     28    aubio_pvoc_do (pv, in, fftgrain);
     29    // ctrans, cstead = tss (fftgrain)
     30    aubio_tss_do (tss, fftgrain, ctrans, cstead);
     31    // stead = pvt_inverse (cstead)
     32    // trans = pvt_inverse (ctrans)
     33    aubio_pvoc_rdo (pvt, cstead, stead);
     34    aubio_pvoc_rdo (pvs, ctrans, trans);
    3935  }
    4036
     
    5046  del_fvec(stead);
    5147  del_fvec(trans);
     48
    5249  aubio_cleanup();
    53   printf("memory freed\n");
     50
    5451  return 0;
    5552}
Note: See TracChangeset for help on using the changeset viewer.