EchoMap 2026-07-25 6d3977c
An experimental cross-platform digital signal processing application for sound-source localisation.
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
18namespace echomap
19{
20
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
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 specification.
~FFTWBuffers() noexcept
Deallocate the buffers.
bool is_input_managed
Are we responsible for the input buffer?
FFTWBuffers(std::size_t size, const std::optional< std::span< const float > > &inplace_input)
Setup contextual buffers for FFTW.
std::size_t input_size
Size of the input vector.
fftwf_complex_fwd *const coefficients
Complex coefficients (output of real-to-complex FFT).
float * input
Real-valued inputs, either managed by us or aliased by the user.
The main EchoMap outermost namespace for all non-exported symbols.