Class thl::dsp::fft::RealFft#

class RealFft#

The FFT of a real signal of a power-of-two size, on the backend the build chose.

forward(): size() real samples to num_bins() = size() / 2 + 1 bins, X[k] = sum over n of x[n] · e^(-2πi·k·n / N), unscaled (as numpy.fft.rfft): a sine of amplitude A at bin k reads |X[k]| = A · N / 2. Bin 0 (DC) and bin N / 2 (Nyquist) are real. inverse(): the bins back to size() samples, scaled by 1 / N, so inverse(forward(x)) is x. The imaginary parts of bins 0 and N / 2 are ignored.

The backend is a build option (TANH_FFT_BACKEND): pffft on every platform, or Apple’s Accelerate on macOS and iOS; backend_name() says which. Both give the same bins.

Threads: prepare() allocates (not on the audio thread); forward() and inverse() are real-time safe and use the object’s own buffers, so one object serves one thread at a time.

Public Functions

RealFft()#
~RealFft()#
RealFft(const RealFft&) = delete#
RealFft &operator=(const RealFft&) = delete#
RealFft(RealFft&&) noexcept#
RealFft &operator=(RealFft&&) noexcept#
bool prepare(size_t size)#

Sets up the transform of size samples (is_valid_size()).

False, and unprepared, for any other size or if the backend cannot set it up.

inline size_t size() const#

The prepared size (0 before prepare()).

inline size_t num_bins() const#

size() / 2 + 1.

void forward(std::span<const float> time, std::span<std::complex<float>> bins)#

time (size() samples) to bins (num_bins()).

void inverse(std::span<const std::complex<float>> bins, std::span<float> time)#

bins (num_bins()) to time (size() samples), scaled by 1 / size().

Public Static Functions

static bool is_valid_size(size_t size)#

True for the sizes prepare() takes: powers of two in [k_min_size, k_max_size].

static const char *backend_name()#

“pffft” or “accelerate”.

Public Static Attributes

static constexpr size_t k_min_size = 32#
static constexpr size_t k_max_size = size_t{1} << 16#