From: Paul Brossier Date: Sat, 3 Nov 2007 13:22:14 +0000 (+0100) Subject: fft.c: reduce size of specdata with COMPLEX_H, fix computations without COMPLEX_H X-Git-Tag: bzr2git~492 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=01af943cd6f76ca84604f339bf6cbbd679af80cb;p=aubio.git fft.c: reduce size of specdata with COMPLEX_H, fix computations without COMPLEX_H --- diff --git a/src/fft.c b/src/fft.c index 37c7cb90..53566989 100644 --- a/src/fft.c +++ b/src/fft.c @@ -54,12 +54,15 @@ aubio_fft_t * new_aubio_fft(uint_t size) { /* allocate memory */ s->in = AUBIO_ARRAY(real_t,size); s->out = AUBIO_ARRAY(real_t,size); - s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size); /* create plans */ #ifdef HAVE_COMPLEX_H + s->fft_size = size/2+1; + s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size); s->pfw = fftw_plan_dft_r2c_1d(size, s->in, s->specdata, FFTW_ESTIMATE); s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE); #else + s->fft_size = size; + s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size); s->pfw = fftw_plan_r2r_1d(size, s->in, s->specdata, FFTW_R2HC, FFTW_ESTIMATE); s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE); #endif @@ -82,7 +85,7 @@ void aubio_fft_do(const aubio_fft_t * s, uint_t i; for (i=0;iin[i] = data[i]; fftw_execute(s->pfw); - for (i=0;ispecdata[i]; + for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i]; } void aubio_fft_rdo(const aubio_fft_t * s, @@ -91,7 +94,7 @@ void aubio_fft_rdo(const aubio_fft_t * s, const uint_t size) { uint_t i; const smpl_t renorm = 1./(smpl_t)size; - for (i=0;ispecdata[i] = spectrum[i]; + for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i]; fftw_execute(s->pbw); for (i=0;iout[i]*renorm; } @@ -122,15 +125,17 @@ void aubio_fft_getspectrum(fft_data_t * spectrum, smpl_t *norm, smpl_t * phas, u void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) { uint_t i; - norm[0] = -spectrum[0]; - for (i=1;i