source: examples/tests/test-fft.c @ 229ea56

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

really fill test-fft
really fill test-fft

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[26499e4]1#include <stdlib.h>
2#include <math.h>
3#include <complex.h>
[17fbb7a]4#include <aubio.h>
[437fa65]5
[26499e4]6#define NEW_ARRAY(_t,_n)                (_t*)malloc((_n)*sizeof(_t))
7
8
[437fa65]9int main(){
10        uint_t i,j;
11        /* allocate some memory */
12        uint_t win_s      = 1024;                       /* window size */
13        uint_t channels   = 1;                          /* number of channel */
14        fvec_t * in       = new_fvec (win_s, channels); /* input buffer */
15        cvec_t * fftgrain = new_cvec (win_s, channels); /* fft norm and phase */
16        fvec_t * out      = new_fvec (win_s, channels); /* output buffer */
17 
18        /* allocate fft and other memory space */
[17fbb7a]19        aubio_fft_t * fft      = new_aubio_fft(win_s);      /* fft interface */
[26499e4]20        smpl_t * w             = NEW_ARRAY(smpl_t,win_s); /* window */
[437fa65]21        /* complex spectral data */
[26499e4]22        fft_data_t ** spec     = NEW_ARRAY(fft_data_t*,channels); 
[437fa65]23        for (i=0; i < channels; i++)
[26499e4]24                spec[i] = NEW_ARRAY(fft_data_t,win_s);
[437fa65]25        /* initialize the window (see mathutils.c) */
[28d8c4a]26        aubio_window(w,win_s,aubio_win_hanningz);
[437fa65]27 
28        /* fill input with some data */
[9ec7876]29        in->data[0][win_s/2] = 1;
[437fa65]30 
31        /* execute stft */
32        for (i=0; i < channels; i++) {
33                aubio_fft_do (fft,in->data[i],spec[i],win_s);
34                /* put norm and phase into fftgrain */
35                aubio_fft_getnorm(fftgrain->norm[i], spec[i], win_s/2+1);
36                aubio_fft_getphas(fftgrain->phas[i], spec[i], win_s/2+1);
37        }
38 
39        /* execute inverse fourier transform */
40        for (i=0; i < channels; i++) {
41                for (j=0; j<win_s/2+1; j++) {
[26499e4]42                        spec[i][j]  = cexp(I*aubio_unwrap2pi(fftgrain->phas[i][j]));
[437fa65]43                        spec[i][j] *= fftgrain->norm[i][j];
44                }
45                aubio_fft_rdo(fft,spec[i],out->data[i],win_s);
46        }
[17fbb7a]47
48        del_fvec(in);
49        del_fvec(out);
50        del_cvec(fftgrain);
[26499e4]51        free(w);
[17fbb7a]52        del_aubio_fft(fft);
53        for (i=0; i < channels; i++)
[26499e4]54                free(spec[i]);
55        free(spec); 
[17fbb7a]56        aubio_cleanup();
[437fa65]57        return 0;
58}
Note: See TracBrowser for help on using the repository browser.