Mercurial > hg > batch-feature-extraction-tool
view Source/FFTW.h @ 3:005e311b5e62
Fixed memory leak. :) Need to fix Debug FFTW now though.
author | Geogaddi\David <d.m.ronan@qmul.ac.uk> |
---|---|
date | Fri, 10 Jul 2015 00:33:15 +0100 |
parents | e86e9c111b29 |
children | 345acbd06029 |
line wrap: on
line source
//---------------------------------------------------------------------------------------------------------------------- /** \author André Bergner \date Feb/2013 \class FFTW Encapsulates the FFT of lib-fftw (c) Copyright NATIVE INSTRUMENTS, Berlin, Germany ALL RIGHTS RESERVED */ //---------------------------------------------------------------------------------------------------------------------- #pragma once #include "fftw3.h" #include <vector> #include <stdio.h> //#include <windows.h> #include <string.h> //#include <itl/dsp/SimdTools.h> class FFTW { public: fftwf_plan m_plan; unsigned m_iFFTSize; FFTW(); FFTW( unsigned fftLength ) { m_iFFTSize = fftLength; float* tempInput = new float[fftLength]; memset(tempInput,0, fftLength * sizeof(float)); float* tempReal = new float[fftLength]; memset(tempReal,0, fftLength * sizeof(float)); float* tempImag = new float[fftLength]; memset(tempImag,0, fftLength * sizeof(float)); fftwf_iodim dim; dim.n = fftLength; dim.is = 1; dim.os = 1; m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, nullptr, tempInput, tempReal, tempImag, FFTW_ESTIMATE ); delete[] tempInput; tempInput = nullptr; delete[] tempReal; tempReal = nullptr; delete[] tempImag; tempImag = nullptr; } ~FFTW() { if(m_plan != nullptr) { fftwf_destroy_plan( m_plan ); } } void process( const float* input , float* realPart , float* imagPart ) { float* nonConstInput = const_cast<float*>(input); // fftw does not take const input even though the data not be manipulated! fftwf_execute_split_dft_r2c( m_plan, nonConstInput, realPart, imagPart); //Multiply results by 2 to match the iOS output for(size_t i = 0; i < m_iFFTSize; i++) { realPart[i] *= 2.f; imagPart[i] *= 2.f; } } };