Mercurial > hg > batch-feature-extraction-tool
comparison Source/FFTW.h @ 4:345acbd06029
Vectorised most things to make lifer easier. Still no debug version though. Weird.
author | Geogaddi\David <d.m.ronan@qmul.ac.uk> |
---|---|
date | Fri, 10 Jul 2015 03:04:11 +0100 |
parents | 005e311b5e62 |
children | fdc592312a96 |
comparison
equal
deleted
inserted
replaced
3:005e311b5e62 | 4:345acbd06029 |
---|---|
14 | 14 |
15 #pragma once | 15 #pragma once |
16 | 16 |
17 #include "fftw3.h" | 17 #include "fftw3.h" |
18 #include <vector> | 18 #include <vector> |
19 #include <memory> | |
19 #include <stdio.h> | 20 #include <stdio.h> |
20 //#include <windows.h> | 21 //#include <windows.h> |
21 #include <string.h> | 22 #include <string.h> |
22 //#include <itl/dsp/SimdTools.h> | 23 //#include <itl/dsp/SimdTools.h> |
23 | 24 |
33 FFTW(); | 34 FFTW(); |
34 FFTW( unsigned fftLength ) | 35 FFTW( unsigned fftLength ) |
35 { | 36 { |
36 m_iFFTSize = fftLength; | 37 m_iFFTSize = fftLength; |
37 | 38 |
38 float* tempInput = new float[fftLength]; | 39 std::vector<float> tempInput = std::vector<float>(fftLength, 0); |
39 memset(tempInput,0, fftLength * sizeof(float)); | 40 std::vector<float> tempReal = std::vector<float>(fftLength, 0); |
40 float* tempReal = new float[fftLength]; | 41 std::vector<float> tempImag = std::vector<float>(fftLength, 0); |
41 memset(tempReal,0, fftLength * sizeof(float)); | 42 |
42 float* tempImag = new float[fftLength]; | 43 |
43 memset(tempImag,0, fftLength * sizeof(float)); | |
44 fftwf_iodim dim; | 44 fftwf_iodim dim; |
45 dim.n = fftLength; | 45 dim.n = fftLength; |
46 dim.is = 1; | 46 dim.is = 1; |
47 dim.os = 1; | 47 dim.os = 1; |
48 m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, nullptr, tempInput, tempReal, tempImag, FFTW_ESTIMATE ); | 48 m_plan = fftwf_plan_guru_split_dft_r2c( 1, &dim, 0, nullptr, tempInput.data(), tempReal.data(), tempImag.data(), FFTW_ESTIMATE ); |
49 delete[] tempInput; | |
50 tempInput = nullptr; | |
51 delete[] tempReal; | |
52 tempReal = nullptr; | |
53 delete[] tempImag; | |
54 tempImag = nullptr; | |
55 } | 49 } |
56 | 50 |
57 | 51 |
58 ~FFTW() | 52 ~FFTW() |
59 { | 53 { |
62 fftwf_destroy_plan( m_plan ); | 56 fftwf_destroy_plan( m_plan ); |
63 } | 57 } |
64 } | 58 } |
65 | 59 |
66 | 60 |
67 void process( const float* input , float* realPart , float* imagPart ) | 61 void process(std::vector<float> input, std::vector<float> &realPart, std::vector<float> &imagPart) |
68 { | 62 { |
69 float* nonConstInput = const_cast<float*>(input); // fftw does not take const input even though the data not be manipulated! | 63 |
70 | 64 fftwf_execute_split_dft_r2c( m_plan, input.data(), realPart.data(), imagPart.data()); |
71 fftwf_execute_split_dft_r2c( m_plan, nonConstInput, realPart, imagPart); | |
72 | 65 |
73 //Multiply results by 2 to match the iOS output | 66 //Multiply results by 2 to match the iOS output |
74 for(size_t i = 0; i < m_iFFTSize; i++) | 67 for(size_t i = 0; i < m_iFFTSize; i++) |
75 { | 68 { |
76 realPart[i] *= 2.f; | 69 realPart[i] *= 2.f; |