Changeset 01af943


Ignore:
Timestamp:
Nov 3, 2007, 2:22:14 PM (17 years ago)
Author:
Paul Brossier <piem@piem.org>
Branches:
feature/autosink, feature/cnn, feature/cnn_org, feature/constantq, feature/crepe, feature/crepe_org, feature/pitchshift, feature/pydocstrings, feature/timestretch, fix/ffmpeg5, master, pitchshift, sampler, timestretch, yinfft+
Children:
a47cd35
Parents:
55e030d
Message:

fft.c: reduce size of specdata with COMPLEX_H, fix computations without COMPLEX_H

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/fft.c

    r55e030d r01af943  
    5555        s->in       = AUBIO_ARRAY(real_t,size);
    5656        s->out      = AUBIO_ARRAY(real_t,size);
    57         s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*size);
    5857        /* create plans */
    5958#ifdef HAVE_COMPLEX_H
     59  s->fft_size = size/2+1;
     60        s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
    6061        s->pfw = fftw_plan_dft_r2c_1d(size, s->in,  s->specdata, FFTW_ESTIMATE);
    6162        s->pbw = fftw_plan_dft_c2r_1d(size, s->specdata, s->out, FFTW_ESTIMATE);
    6263#else
     64  s->fft_size = size;
     65        s->specdata = (fft_data_t*)fftw_malloc(sizeof(fft_data_t)*s->fft_size);
    6366        s->pfw = fftw_plan_r2r_1d(size, s->in,  s->specdata, FFTW_R2HC, FFTW_ESTIMATE);
    6467        s->pbw = fftw_plan_r2r_1d(size, s->specdata, s->out, FFTW_HC2R, FFTW_ESTIMATE);
     
    8386        for (i=0;i<size;i++) s->in[i] = data[i];
    8487        fftw_execute(s->pfw);
    85         for (i=0;i<size;i++) spectrum[i] = s->specdata[i];
     88        for (i=0; i < s->fft_size; i++) spectrum[i] = s->specdata[i];
    8689}
    8790
     
    9295        uint_t i;
    9396        const smpl_t renorm = 1./(smpl_t)size;
    94         for (i=0;i<size;i++) s->specdata[i] = spectrum[i];
     97        for (i=0; i < s->fft_size; i++) s->specdata[i] = spectrum[i];
    9598        fftw_execute(s->pbw);
    9699        for (i=0;i<size;i++) data[i] = s->out[i]*renorm;
     
    123126void aubio_fft_getnorm(smpl_t * norm, fft_data_t * spectrum, uint_t size) {
    124127        uint_t i;
    125   norm[0] = -spectrum[0];
    126         for (i=1;i<size/2+1;i++) norm[i] = SQRT(SQR(spectrum[i]) + SQR(spectrum[size-i]));
     128  norm[0] = SQR(spectrum[0]);
     129        for (i=1;i<size/2;i++) norm[i] = (SQR(spectrum[i]) + SQR(spectrum[size-i]));
     130        norm[size/2] = SQR(spectrum[size/2]);
    127131        //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", norm[i]);
    128132}
     
    130134void aubio_fft_getphas(smpl_t * phas, fft_data_t * spectrum, uint_t size) {
    131135        uint_t i;
    132   phas[0] = PI;
     136  phas[0] = 0;
    133137        for (i=1;i<size/2+1;i++) phas[i] = atan2f(spectrum[size-i] , spectrum[i]);
     138  phas[size/2] = 0;
    134139        //for (i=0;i<size/2+1;i++) AUBIO_DBG("%f\n", phas[i]);
    135140}
Note: See TracChangeset for help on using the changeset viewer.