comparison Source/FFTW.h @ 0:25bf17994ef1

First commit. VS2013, Codeblocks and Mac OSX configuration
author Geogaddi\David <d.m.ronan@qmul.ac.uk>
date Thu, 09 Jul 2015 01:12:16 +0100
parents
children e86e9c111b29
comparison
equal deleted inserted replaced
-1:000000000000 0:25bf17994ef1
1 //----------------------------------------------------------------------------------------------------------------------
2 /**
3 \author André Bergner
4 \date Feb/2013
5
6 \class FFTW
7
8 Encapsulates the FFT of lib-fftw
9
10 (c) Copyright NATIVE INSTRUMENTS, Berlin, Germany
11 ALL RIGHTS RESERVED
12 */
13 //----------------------------------------------------------------------------------------------------------------------
14
15 #pragma once
16
17 #include "fftw3.h"
18 #include <vector>
19 #include <windows.h>
20 #include <string>
21 //#include <itl/dsp/SimdTools.h>
22
23
24
25 class FFTW
26 {
27
28 public:
29 fftwf_plan m_plan;
30 unsigned m_iFFTSize;
31
32 FFTW();
33 FFTW( unsigned fftLength )
34 {
35 m_iFFTSize = fftLength;
36
37 float* tempInput = new float[fftLength];
38 memset(tempInput,0, fftLength * sizeof(float));
39 float* tempReal = new float[fftLength];
40 memset(tempReal,0, fftLength * sizeof(float));
41 float* tempImag = new float[fftLength];
42 memset(tempImag,0, fftLength * sizeof(float));
43 fftwf_iodim dim;
44 dim.n = fftLength;
45 dim.is = 1;
46 dim.os = 1;
47 m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, NULL, tempInput, tempReal, tempImag, FFTW_ESTIMATE );
48 delete[] tempInput;
49 tempInput = nullptr;
50 delete[] tempReal;
51 tempReal = nullptr;
52 delete[] tempImag;
53 tempImag = nullptr;
54 }
55
56
57 ~FFTW()
58 {
59 if(m_plan != NULL)
60 {
61 fftwf_destroy_plan( m_plan );
62 }
63 }
64
65
66 void process( const float* input , float* realPart , float* imagPart )
67 {
68 float* nonConstInput = const_cast<float*>(input); // fftw does not take const input even though the data not be manipulated!
69
70 fftwf_execute_split_dft_r2c( m_plan, nonConstInput, realPart, imagPart);
71
72 //Multiply results by 2 to match the iOS output
73 for(size_t i = 0; i < m_iFFTSize; i++)
74 {
75 realPart[i] *= 2.f;
76 imagPart[i] *= 2.f;
77 }
78 }
79
80 };
81