DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
dspark::SpectralProcessor< T > Class Template Reference

High-performance STFT analysis-modification-synthesis pipeline. More...

#include <SpectralProcessor.h>

Public Member Functions

void prepare (const AudioSpec &spec, int fftSize=2048, int hopSize=0)
 Allocates buffers and prepares the WOLA processing state.
 
template<typename Func >
void processBlock (AudioBufferView< T > buffer, Func &&processFunc) noexcept
 Processes a block of audio through the STFT pipeline.
 
int getLatency () const noexcept
 I/O latency in samples: exactly one FFT frame.
 
int getFFTSize () const noexcept
 
int getNumBins () const noexcept
 
int getHopSize () const noexcept
 
void reset () noexcept
 Clears all internal delay lines and state variables.
 

Detailed Description

template<typename T>
class dspark::SpectralProcessor< T >

High-performance STFT analysis-modification-synthesis pipeline.

Callback contract:

  • The callback receives the spectrum of one channel as numBins complex bins in interleaved CCS layout [re0, im0, re1, im1, ...] with numBins = fftSize/2 + 1. Bin 0 is DC and bin numBins-1 is Nyquist; their imaginary parts are zero on entry and are ignored by the inverse transform.
  • Bins carry the raw transform scale: the forward FFT is unnormalized and the inverse applies 1/N, so an unmodified spectrum reconstructs the input exactly. A full-scale sine of amplitude A appears with magnitude about A*fftSize/2 (times the window's coherent gain).
  • The callback runs once per channel per hop, in channel order. It is invoked inside a noexcept audio path and must not throw.

Channels beyond the prepared channel count pass through dry. The first fftSize output samples after prepare()/reset() are the windowed ramp-in of the zero-primed analysis ring (silence before input arrives).

Template Parameters
TSample type (float or double).

Definition at line 82 of file SpectralProcessor.h.

Member Function Documentation

◆ getFFTSize()

template<typename T >
int dspark::SpectralProcessor< T >::getFFTSize ( ) const
inlinenoexcept

Definition at line 255 of file SpectralProcessor.h.

◆ getHopSize()

template<typename T >
int dspark::SpectralProcessor< T >::getHopSize ( ) const
inlinenoexcept

Definition at line 257 of file SpectralProcessor.h.

◆ getLatency()

template<typename T >
int dspark::SpectralProcessor< T >::getLatency ( ) const
inlinenoexcept

I/O latency in samples: exactly one FFT frame.

Constant and independent of the caller's block sizes.

Definition at line 254 of file SpectralProcessor.h.

◆ getNumBins()

template<typename T >
int dspark::SpectralProcessor< T >::getNumBins ( ) const
inlinenoexcept

Definition at line 256 of file SpectralProcessor.h.

◆ prepare()

template<typename T >
void dspark::SpectralProcessor< T >::prepare ( const AudioSpec spec,
int  fftSize = 2048,
int  hopSize = 0 
)
inline

Allocates buffers and prepares the WOLA processing state.

Not real-time safe (allocates). Any previous stream state is cleared. An invalid spec (non-positive or NaN sample rate, no channels) is ignored, preserving the previous state.

Parameters
specAudio environment specification.
fftSizeFFT size (default 2048). Must be a power of two; in release builds any other value is rounded up to the next power of two within [4, 1<<20].
hopSizeHop size in samples. Values <= 0 (default) select fftSize/2 (50% overlap). Clamped to [1, fftSize/2]; non-divisors of fftSize fall back to fftSize/2 (a non-divisor hop would break the COLA condition and cause audible amplitude modulation).

Definition at line 104 of file SpectralProcessor.h.

◆ processBlock()

template<typename T >
template<typename Func >
void dspark::SpectralProcessor< T >::processBlock ( AudioBufferView< T >  buffer,
Func &&  processFunc 
)
inlinenoexcept

Processes a block of audio through the STFT pipeline.

In-place; arbitrary block sizes are supported and produce bit-identical output regardless of how the stream is chopped. Inlines the provided callback to manipulate frequency bins without function call overhead. Safe no-op before prepare().

Template Parameters
FuncCallback type, compatible with void(T* freqData, int numBins). Must not throw.
Parameters
bufferAudio block to process in-place.
processFuncUser-defined spectral modification function.

Definition at line 179 of file SpectralProcessor.h.

◆ reset()

template<typename T >
void dspark::SpectralProcessor< T >::reset ( )
inlinenoexcept

Clears all internal delay lines and state variables.

Definition at line 260 of file SpectralProcessor.h.


The documentation for this class was generated from the following file: