/
bpm_fft_impl_kissfft.cpp
69 lines (52 loc) · 1.59 KB
/
bpm_fft_impl_kissfft.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "bpm_fft_impl_kissfft.h"
bpm_fft_impl_kissfft::bpm_fft_impl_kissfft():
m_plan(nullptr)
{
}
bpm_fft_impl_kissfft::~bpm_fft_impl_kissfft()
{
}
void bpm_fft_impl_kissfft::create_plan(int p_size)
{
m_plan = nullptr;
m_plan = kiss_fft_alloc(p_size, 0, 0, 0);
m_size = p_size;
m_input_buffer = (double*)KISS_FFT_MALLOC(p_size*sizeof(double));
m_output_buffer = (double*)KISS_FFT_MALLOC(p_size*sizeof(double));
m_complex_input_buffer = (kiss_fft_cpx*)KISS_FFT_MALLOC(p_size*sizeof(kiss_fft_cpx));
m_complex_output_buffer = (kiss_fft_cpx*)KISS_FFT_MALLOC(p_size*sizeof(kiss_fft_cpx));
}
void bpm_fft_impl_kissfft::execute_plan()
{
PFC_ASSERT(m_plan.is_valid());
for (int index = 0; index < m_size; ++index)
{
m_complex_input_buffer.get_ptr()[index].r = m_input_buffer.get_ptr()[index];
m_complex_input_buffer.get_ptr()[index].i = 0.0;
}
kiss_fft(m_plan.get_ptr(), m_complex_input_buffer.get_ptr(), m_complex_output_buffer.get_ptr());
for (int index = 0; index <= m_size / 2; ++index)
{
m_output_buffer.get_ptr()[index] = m_complex_output_buffer.get_ptr()[index].r;
}
for (int index = 1; index < (m_size + 1) / 2; ++index)
{
m_output_buffer.get_ptr()[m_size - index] = m_complex_output_buffer.get_ptr()[index].i;
}
}
void bpm_fft_impl_kissfft::destroy_plan()
{
m_plan.release();
m_input_buffer.release();
m_output_buffer.release();
m_complex_input_buffer.release();
m_complex_output_buffer.release();
}
double * bpm_fft_impl_kissfft::get_input_buffer()
{
return m_input_buffer.get_ptr();
}
double * bpm_fft_impl_kissfft::get_output_buffer()
{
return m_output_buffer.get_ptr();
}