Mercurial > hg > svcore
comparison data/fft/FFTapi.h @ 1126:39019ce29178 tony-2.0-integration
Merge through to branch for Tony 2.0
author | Chris Cannam |
---|---|
date | Thu, 20 Aug 2015 14:54:21 +0100 |
parents | b66734b5f806 |
children | db946591a391 |
comparison
equal
deleted
inserted
replaced
1119:e22bfe8ca248 | 1126:39019ce29178 |
---|---|
48 #define FFTW_ESTIMATE 0 | 48 #define FFTW_ESTIMATE 0 |
49 #define FFTW_MEASURE 0 | 49 #define FFTW_MEASURE 0 |
50 | 50 |
51 #endif | 51 #endif |
52 | 52 |
53 #include <vector> | |
54 #include <complex> | |
55 | |
56 class FFTForward // with fft shift but not window | |
57 { | |
58 public: | |
59 FFTForward(int size) : | |
60 m_size(size), | |
61 m_input((float *)fftf_malloc(size * sizeof(float))), | |
62 m_output((fftf_complex *)fftf_malloc((size/2 + 1) * sizeof(fftf_complex))), | |
63 m_plan(fftf_plan_dft_r2c_1d(size, m_input, m_output, FFTW_MEASURE)) | |
64 { } | |
65 | |
66 ~FFTForward() { | |
67 fftf_destroy_plan(m_plan); | |
68 fftf_free(m_input); | |
69 fftf_free(m_output); | |
70 } | |
71 | |
72 std::vector<std::complex<float> > process(std::vector<float> in) const { | |
73 const int hs = m_size/2; | |
74 for (int i = 0; i < hs; ++i) { | |
75 m_input[i] = in[i + hs]; | |
76 } | |
77 for (int i = 0; i < hs; ++i) { | |
78 m_input[i + hs] = in[i]; | |
79 } | |
80 fftf_execute(m_plan); | |
81 std::vector<std::complex<float> > result; | |
82 result.reserve(hs + 1); | |
83 for (int i = 0; i <= hs; ++i) { | |
84 result.push_back({ m_output[i][0], m_output[i][1] }); | |
85 } | |
86 return result; | |
87 } | |
88 | |
89 private: | |
90 int m_size; | |
91 float *m_input; | |
92 fftf_complex *m_output; | |
93 fftf_plan m_plan; | |
94 }; | |
95 | |
53 #endif | 96 #endif |
54 | 97 |