From: Paul Brossier Date: Sun, 3 Mar 2013 18:37:43 +0000 (-0500) Subject: tests/src/spectral/: improve examples X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=6938a20076f6383268da0641675124f6cdff5411;p=aubio.git tests/src/spectral/: improve examples --- diff --git a/tests/src/spectral/test-fft.c b/tests/src/spectral/test-fft.c index a17b9778..101c4065 100644 --- a/tests/src/spectral/test-fft.c +++ b/tests/src/spectral/test-fft.c @@ -1,34 +1,38 @@ - #include -int main(){ - /* allocate some memory */ - uint_t win_s = 8; /* window size */ - fvec_t * in = new_fvec (win_s); /* input buffer */ - cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */ - fvec_t * out = new_fvec (win_s); /* output buffer */ - in->data[0] = 1; - in->data[1] = 2; - in->data[2] = 3; - in->data[3] = 4; - in->data[4] = 5; - in->data[5] = 6; - in->data[6] = 5; - in->data[7] = 6; - /* allocate fft and other memory space */ - aubio_fft_t * fft = new_aubio_fft(win_s); - /* fill input with some data */ - fvec_print(in); - /* execute stft */ - aubio_fft_do (fft,in,fftgrain); - cvec_print(fftgrain); - /* execute inverse fourier transform */ - aubio_fft_rdo(fft,fftgrain,out); - fvec_print(out); - del_aubio_fft(fft); - del_fvec(in); - del_cvec(fftgrain); - del_fvec(out); - aubio_cleanup(); - return 0; +int main () +{ + uint_t win_s = 8; // window size + fvec_t * in = new_fvec (win_s); // input buffer + cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase + fvec_t * out = new_fvec (win_s); // output buffer + // create fft object + aubio_fft_t * fft = new_aubio_fft(win_s); + + // fill input with some data + in->data[0] = 1; + in->data[1] = 2; + in->data[2] = 3; + in->data[3] = 4; + in->data[4] = 5; + in->data[5] = 6; + in->data[6] = 5; + in->data[7] = 6; + fvec_print(in); + + // execute stft + aubio_fft_do (fft,in,fftgrain); + cvec_print(fftgrain); + + // execute inverse fourier transform + aubio_fft_rdo(fft,fftgrain,out); + + // cleam up + fvec_print(out); + del_aubio_fft(fft); + del_fvec(in); + del_cvec(fftgrain); + del_fvec(out); + aubio_cleanup(); + return 0; } diff --git a/tests/src/spectral/test-filterbank.c b/tests/src/spectral/test-filterbank.c index 9b1db722..679e6cde 100644 --- a/tests/src/spectral/test-filterbank.c +++ b/tests/src/spectral/test-filterbank.c @@ -1,40 +1,28 @@ -#define AUBIO_UNSTABLE 1 - -#include #include -int main (void) { +int main () +{ uint_t win_s = 1024; // window size uint_t n_filters = 13; // number of filters - cvec_t *in = new_cvec (win_s); // input buffer - fvec_t *out = new_fvec (win_s); // vector output */ - fmat_t *coeffs = NULL; - // create filterbank + cvec_t *in_spec = new_cvec (win_s); // input vector of samples + fvec_t *out_filters = new_fvec (n_filters); // per-band outputs + fmat_t *coeffs; // pointer to the coefficients + + // create filterbank object aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s); coeffs = aubio_filterbank_get_coeffs (o); - if (coeffs == NULL) { - return -1; - } - - /* - if (fvec_max (coeffs) != 0.) { - return -1; - } - - if (fvec_min (coeffs) != 0.) { - return -1; - } - */ - fmat_print (coeffs); + aubio_filterbank_do (o, in_spec, out_filters); - aubio_filterbank_do (o, in, out); + // fmat_print (coeffs); + // cvec_print(in_spec); + // fvec_print(out_filters); del_aubio_filterbank (o); - del_cvec (in); - del_fvec (out); + del_cvec (in_spec); + del_fvec (out_filters); aubio_cleanup (); return 0; diff --git a/tests/src/spectral/test-filterbank_mel.c b/tests/src/spectral/test-filterbank_mel.c index 1d0caf09..89f6e774 100644 --- a/tests/src/spectral/test-filterbank_mel.c +++ b/tests/src/spectral/test-filterbank_mel.c @@ -1,35 +1,28 @@ -#define AUBIO_UNSTABLE 1 - -#include #include -int -main (void) +int main () { - /* allocate some memory */ + uint_t samplerate = 16000; // samplerate of signal to filter uint_t win_s = 512; // fft size uint_t n_filters = 40; // number of filters - cvec_t *in_spec = new_cvec (win_s); // input buffer */ - fvec_t *out_filters = new_fvec (n_filters); // output coeffs */ - fmat_t *coeffs = NULL; - smpl_t samplerate = 16000.; - /* allocate fft and other memory space */ + cvec_t *in_spec = new_cvec (win_s); // input vector of samples + fvec_t *out_filters = new_fvec (n_filters); // per-band outputs + fmat_t *coeffs; // pointer to the coefficients + + // create filterbank object aubio_filterbank_t *o = new_aubio_filterbank (n_filters, win_s); - /* assign Mel-frequency coefficients */ + // assign Mel-frequency coefficients aubio_filterbank_set_mel_coeffs_slaney (o, samplerate); coeffs = aubio_filterbank_get_coeffs (o); - fmat_print (coeffs); - - //fprintf(stderr, "%f\n", fvec_sum(coeffs)); - aubio_filterbank_do (o, in_spec, out_filters); - fvec_print(in_spec); - fvec_print(out_filters); + // fmat_print (coeffs); + // cvec_print(in_spec); + // fvec_print(out_filters); del_aubio_filterbank (o); del_cvec (in_spec); diff --git a/tests/src/spectral/test-mfcc.c b/tests/src/spectral/test-mfcc.c index c724d104..2584ec6e 100644 --- a/tests/src/spectral/test-mfcc.c +++ b/tests/src/spectral/test-mfcc.c @@ -1,26 +1,26 @@ #include -int -main (void) +int main () { - /* allocate some memory */ - uint_t win_s = 512; /* fft size */ - uint_t n_filters = 40; /* number of filters */ - uint_t n_coefs = 13; /* number of coefficients */ - cvec_t *in = new_cvec (win_s); /* input buffer */ - fvec_t *out = new_fvec (n_coefs); /* input buffer */ - smpl_t samplerate = 16000.; + uint_t win_s = 512; // fft size + uint_t n_filters = 40; // number of filters + uint_t n_coefs = 13; // number of coefficients + smpl_t samplerate = 16000.; // samplerate + cvec_t *in = new_cvec (win_s); // input buffer + fvec_t *out = new_fvec (n_coefs); // output coefficients - /* allocate fft and other memory space */ + // create mfcc object aubio_mfcc_t *o = new_aubio_mfcc (win_s, n_filters, n_coefs, samplerate); cvec_set (in, 1.); - aubio_mfcc_do (o, in, out); fvec_print (out); + + cvec_set (in, .5); aubio_mfcc_do (o, in, out); fvec_print (out); + // clean up del_aubio_mfcc (o); del_cvec (in); del_fvec (out); diff --git a/tests/src/spectral/test-phasevoc-jack.c b/tests/src/spectral/test-phasevoc-jack.c index d1b8f195..3528e139 100644 --- a/tests/src/spectral/test-phasevoc-jack.c +++ b/tests/src/spectral/test-phasevoc-jack.c @@ -14,14 +14,14 @@ #include "jackio.h" #endif /* HAVE_JACK */ -uint_t testing = 0; /* change this to 1 to listen */ +uint_t testing = 0; // change this to 1 to listen -uint_t win_s = 512;/* window size */ -uint_t hop_s = 128;/* hop size */ -uint_t channels = 2; /* number of audio channels */ -uint_t midiin = 4; /* number of midi input channels */ -uint_t midiout = 2; /* number of midi output channels */ -uint_t pos = 0; /* frames%dspblocksize for jack loop */ +uint_t win_s = 512; // window size +uint_t hop_s = 128; // hop size +uint_t channels = 2; // number of audio channels +uint_t midiin = 4; // number of midi input channels +uint_t midiout = 2; // number of midi output channels +uint_t pos = 0; // frames%dspblocksize for jack loop fvec_t * in[2]; cvec_t * fftgrain[2]; @@ -31,40 +31,41 @@ aubio_pvoc_t * pv[2]; int aubio_process(float **input, float **output, int nframes); -int main(){ - /* allocate some memory */ +int main () +{ + /* allocate some memory */ uint_t i; - for (i=0;ilength;i++) fftgrain[0]->phas[i] = 0.; - // double phases of second channel - for (i=0;ilength;i++) { - fftgrain[1]->phas[i] = - aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.); + for (i=0;ilength;i++) fftgrain[0]->phas[i] = 0.; + // double phases of second channel + for (i=0;ilength;i++) { + fftgrain[1]->phas[i] = + aubio_unwrap2pi (fftgrain[1]->phas[i] * 2.); + } + // copy second channel to third one + aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]); + pos = -1; } - // copy second channel to third one - aubio_pvoc_rdo(pv[i], fftgrain[i], out[i]); - pos = -1; - } } pos++; } diff --git a/tests/src/spectral/test-phasevoc.c b/tests/src/spectral/test-phasevoc.c index 6bea4c39..56cd4e4e 100644 --- a/tests/src/spectral/test-phasevoc.c +++ b/tests/src/spectral/test-phasevoc.c @@ -1,30 +1,47 @@ -/* test sample for phase vocoder */ - -#include #include -int main(){ - uint_t win_s = 1024; /* window size */ - uint_t hop_s = 256; /* hop size */ - /* allocate some memory */ - fvec_t * in = new_fvec (hop_s); /* input buffer */ - cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */ - fvec_t * out = new_fvec (hop_s); /* output buffer */ - /* allocate fft and other memory space */ - aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s); - /* fill input with some data */ - printf("initialised\n"); - /* execute stft */ - aubio_pvoc_do (pv,in,fftgrain); - printf("computed forward\n"); - /* execute inverse fourier transform */ - aubio_pvoc_rdo(pv,fftgrain,out); - printf("computed backard\n"); - del_aubio_pvoc(pv); - del_fvec(in); - del_cvec(fftgrain); - del_fvec(out); - aubio_cleanup(); - printf("memory freed\n"); - return 0; +int main () +{ + uint_t n = 6; // compute n times + uint_t win_s = 32; // window size + uint_t hop_s = win_s / 4; // hop size + + fvec_t * in = new_fvec (hop_s); // input buffer + cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase + fvec_t * out = new_fvec (hop_s); // output buffer + + // allocate fft and other memory space + aubio_pvoc_t * pv = new_aubio_pvoc(win_s,hop_s); + + // fill input with some data + fvec_set (in, 1.); + fvec_print (in); + + while ( n-- ) { + // get some fresh input data + // .. + + // execute phase vocoder + aubio_pvoc_do (pv,in,fftgrain); + + // do something with fftgrain + // ... + cvec_print (fftgrain); + + // optionnaly rebuild the signa + aubio_pvoc_rdo(pv,fftgrain,out); + + // and do something with the result + // ... + fvec_print (out); + } + + // clean up + del_fvec(in); + del_cvec(fftgrain); + del_fvec(out); + del_aubio_pvoc(pv); + aubio_cleanup(); + + return 0; } diff --git a/tests/src/spectral/test-specdesc.c b/tests/src/spectral/test-specdesc.c index fe1b71b7..b99ea16a 100644 --- a/tests/src/spectral/test-specdesc.c +++ b/tests/src/spectral/test-specdesc.c @@ -1,17 +1,13 @@ - -#define AUBIO_UNSTABLE 1 - #include -int -main () +int main () { - uint_t win_s = 1024; /* window size */ - cvec_t *in = new_cvec (win_s); /* input buffer */ - fvec_t *out = new_fvec (1); /* input buffer */ + uint_t win_s = 1024; // window size + cvec_t *in = new_cvec (win_s); // input buffer + fvec_t *out = new_fvec (1); // output spectral descriptor aubio_specdesc_t *o; - + o = new_aubio_specdesc ("energy", win_s); aubio_specdesc_do (o, in, out); del_aubio_specdesc (o); diff --git a/tests/src/spectral/test-tss.c b/tests/src/spectral/test-tss.c index c0600ec7..201d35b8 100644 --- a/tests/src/spectral/test-tss.c +++ b/tests/src/spectral/test-tss.c @@ -1,41 +1,37 @@ -/* test sample for phase vocoder - * - * this program should start correctly using JACK_START_SERVER=true and - * reconstruct each audio input frame perfectly on the corresponding input with - * a delay equal to the window size, hop_s. - */ - -#include -#define AUBIO_UNSTABLE 1 #include -int main(){ - int i; - uint_t win_s = 1024; /* window size */ - uint_t hop_s = 256; /* hop size */ - - /* allocate some memory */ - fvec_t * in = new_fvec (hop_s); /* input buffer */ - cvec_t * fftgrain = new_cvec (win_s); /* fft norm and phase */ - cvec_t * cstead = new_cvec (win_s); /* fft norm and phase */ - cvec_t * ctrans = new_cvec (win_s); /* fft norm and phase */ - fvec_t * stead = new_fvec (hop_s); /* output buffer */ - fvec_t * trans = new_fvec (hop_s); /* output buffer */ - /* allocate phase vocoders and transient steady-state separation */ +int main () +{ + uint_t n = 10; // compute n times + uint_t win_s = 1024; // window size + uint_t hop_s = 256; // hop size + + // create some vectors + fvec_t * in = new_fvec (hop_s); // input buffer + cvec_t * fftgrain = new_cvec (win_s); // fft norm and phase + cvec_t * cstead = new_cvec (win_s); // fft norm and phase + cvec_t * ctrans = new_cvec (win_s); // fft norm and phase + fvec_t * stead = new_fvec (hop_s); // output buffer + fvec_t * trans = new_fvec (hop_s); // output buffer + + // create phase vocoder for analysis of input signal aubio_pvoc_t * pv = new_aubio_pvoc (win_s,hop_s); + // create transient/steady-state separation object + aubio_tss_t * tss = new_aubio_tss(win_s,hop_s); + // create phase vocoder objects for synthesis of output signals aubio_pvoc_t * pvt = new_aubio_pvoc(win_s,hop_s); aubio_pvoc_t * pvs = new_aubio_pvoc(win_s,hop_s); - aubio_tss_t * tss = new_aubio_tss(win_s,hop_s); - - /* fill input with some data */ - printf("initialised\n"); /* execute stft */ - for (i = 0; i < 10; i++) { - aubio_pvoc_do (pv,in,fftgrain); - aubio_tss_do (tss,fftgrain,ctrans,cstead); - aubio_pvoc_rdo(pvt,cstead,stead); - aubio_pvoc_rdo(pvs,ctrans,trans); + while ( n-- ) { + // fftgrain = pv(in) + aubio_pvoc_do (pv, in, fftgrain); + // ctrans, cstead = tss (fftgrain) + aubio_tss_do (tss, fftgrain, ctrans, cstead); + // stead = pvt_inverse (cstead) + // trans = pvt_inverse (ctrans) + aubio_pvoc_rdo (pvt, cstead, stead); + aubio_pvoc_rdo (pvs, ctrans, trans); } del_aubio_pvoc(pv); @@ -49,7 +45,8 @@ int main(){ del_cvec(ctrans); del_fvec(stead); del_fvec(trans); + aubio_cleanup(); - printf("memory freed\n"); + return 0; }