Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
fft_backend.hpp
Go to the documentation of this file.
1#pragma once
2
3// Multi-backend FFT — runtime-selectable wrapper around pulp::signal::Fft.
4//
5// Backends:
6// - vdsp : Apple Accelerate.framework (always available on Apple)
7// - kissfft : built-in radix-2 fallback (always available, header-only).
8// The public backend name stays stable even though the shipping
9// implementation is the hand-rolled radix-2 Cooley-Tukey in
10// pulp::signal::Fft, so callers do not have to track
11// implementation changes.
12// - fftw3 : libfftw3f loaded via dlopen at runtime (optional)
13// - mkl : Intel MKL libmkl_rt loaded via dlopen at runtime (optional)
14//
15// Both fftw3 and mkl are loaded lazily — no link-time dependency. If the
16// shared library is not installed on the runtime machine, the selector
17// falls back to vDSP (on Apple) or kissfft.
18//
19// Backend selection precedence (highest wins):
20// 1. Explicit MultiBackendFft(size, FftBackend::X) constructor
21// 2. env var PULP_FFT_BACKEND={auto,vdsp,kissfft,fftw3,mkl}
22// 3. compile-time default: vDSP on Apple, kissfft elsewhere
23//
24// Numerical equivalence: cross-backend output matches to within a small
25// float tolerance (single-precision round-off accumulates with size). The
26// test suite asserts max-abs-error < ~1e-3 across sizes 64..16384 for
27// power-of-2 transforms.
28
29#include <complex>
30#include <memory>
31#include <string>
32
33namespace pulp::signal {
34
42
44const char* fft_backend_name(FftBackend b) noexcept;
45
47FftBackend parse_fft_backend(const char* s) noexcept;
48
53
58
67public:
74
78 MultiBackendFft& operator=(MultiBackendFft&&) noexcept;
79
80 int size() const noexcept;
81 FftBackend backend() const noexcept;
82
84 void forward(std::complex<float>* data) const;
85
87 void inverse(std::complex<float>* data) const;
88
89private:
90 struct Impl;
91 std::unique_ptr<Impl> impl_;
92};
93
94} // namespace pulp::signal
MultiBackendFft(MultiBackendFft &&) noexcept
int size() const noexcept
FftBackend backend() const noexcept
void forward(std::complex< float > *data) const
Forward complex FFT (in-place).
MultiBackendFft & operator=(const MultiBackendFft &)=delete
void inverse(std::complex< float > *data) const
Inverse complex FFT (in-place), normalized by 1/N.
MultiBackendFft(int size, FftBackend backend=FftBackend::auto_)
Construct for a given power-of-2 size.
MultiBackendFft(const MultiBackendFft &)=delete
Definition additive_bank.hpp:218
FftBackend resolve_fft_backend(FftBackend hint=FftBackend::auto_) noexcept
Resolve auto_ → best available backend on this machine, honoring the PULP_FFT_BACKEND env var if set ...
bool fft_backend_available(FftBackend b) noexcept
True iff the backend can be instantiated on this machine right now.
FftBackend
Definition fft_backend.hpp:35
@ vdsp
Apple Accelerate vDSP (Apple only).
Definition fft_backend.hpp:37
@ mkl
Intel MKL DFTI (runtime-dlopen).
Definition fft_backend.hpp:40
@ kissfft
Built-in radix-2 fallback (always available).
Definition fft_backend.hpp:38
@ fftw3
FFTW3 single-precision (runtime-dlopen).
Definition fft_backend.hpp:39
@ auto_
Pick best available at runtime.
Definition fft_backend.hpp:36
FftBackend parse_fft_backend(const char *s) noexcept
Parse a backend tag from a string. Unknown / empty → auto_.
const char * fft_backend_name(FftBackend b) noexcept
Stringify a backend tag for diagnostics / env-var parsing.
STL namespace.