EchoMap
2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
Toggle main menu visibility
Loading...
Searching...
No Matches
FFTWBuffers.cpp
Go to the documentation of this file.
1
9
10
11
#include "
FFTWBuffers.hpp
"
12
13
#include <fftw3.h>
14
15
#include <
cassert
>
16
#include <
stdexcept
>
17
18
namespace
echomap
19
{
20
21
FFTWBuffers::FFTWBuffers
(
22
const
std::size_t
size,
23
const
std::optional
<
std::span<const float>
>& inplace_input
24
) :
25
coefficients
(fftwf_alloc_complex(size / 2 + 1)),
26
input
(inplace_input.has_value() ? const_cast<float*>(inplace_input->data()) : fftwf_alloc_real(size)),
27
input_size
(size),
28
is_input_managed
(!inplace_input.has_value())
29
{
30
/*
31
* It's not very nice, but we cast away the const on the input buffer as required by the FFTW C API. We know that
32
* in-place transforms are not going to take place, so it doesn't make sense to take optional<float*> (mutable
33
* pointer) as a constructor parameter.
34
*/
35
36
if
(
coefficients
==
nullptr
)
37
throw
std::runtime_error
(
"Failed to create FFTW coefficients buffer."
);
38
39
if
(!inplace_input.has_value() &&
input
==
nullptr
) {
40
fftwf_free(coefficients);
41
throw std::runtime_error(
"Failed to create FFTW input buffer."
);
42
}
43
44
assert(
input
!=
nullptr
);
45
assert(
coefficients
!=
nullptr
);
46
}
47
48
FFTWBuffers::~FFTWBuffers
() noexcept
49
{
50
if
(
is_input_managed
&&
input
!=
nullptr
)
51
fftwf_free(
input
);
52
53
if
(
coefficients
!=
nullptr
)
54
fftwf_free(
coefficients
);
55
}
56
57
}
// namespace echomap
FFTWBuffers.hpp
FFTWBuffers specification.
cassert
echomap::FFTWBuffers::~FFTWBuffers
~FFTWBuffers() noexcept
Deallocate the buffers.
Definition
FFTWBuffers.cpp:48
echomap::FFTWBuffers::is_input_managed
bool is_input_managed
Are we responsible for the input buffer?
Definition
FFTWBuffers.hpp:58
echomap::FFTWBuffers::FFTWBuffers
FFTWBuffers(std::size_t size, const std::optional< std::span< const float > > &inplace_input)
Setup contextual buffers for FFTW.
Definition
FFTWBuffers.cpp:21
echomap::FFTWBuffers::input_size
std::size_t input_size
Size of the input vector.
Definition
FFTWBuffers.hpp:33
echomap::FFTWBuffers::coefficients
fftwf_complex_fwd *const coefficients
Complex coefficients (output of real-to-complex FFT).
Definition
FFTWBuffers.hpp:31
echomap::FFTWBuffers::input
float * input
Real-valued inputs, either managed by us or aliased by the user.
Definition
FFTWBuffers.hpp:32
echomap
The main EchoMap outermost namespace for all non-exported symbols.
Definition
ActionController.hpp:20
std::optional
std::runtime_error
std::size_t
std::span
stdexcept
src
objects
factories
FFTWBuffers.cpp
Generated by
1.17.0