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

Real-time partitioned convolution using overlap-save with FFT. More...

#include <Convolver.h>

Public Member Functions

void prepare (int blockSize, const T *irData, int irLength)
 Prepares the convolver with an impulse response.
 
void reset () noexcept
 Resets the convolution state (clears delay lines and buffers).
 
void process (const T *input, T *output, int numSamples) noexcept
 Processes a block of audio through the convolver.
 
void processInPlace (T *data, int numSamples) noexcept
 Processes audio in-place (output overwrites input).
 
void prepare (const AudioSpec &spec, const T *irData, int irLength)
 Prepares with AudioSpec and IR data (unified API).
 
void processBlock (AudioBufferView< T > buffer) noexcept
 Processes an audio buffer in-place (unified API).
 
int getLatency () const noexcept
 Returns the processing latency in samples (= block size).
 
int getBlockSize () const noexcept
 Returns the block size.
 
int getNumPartitions () const noexcept
 Returns the number of IR partitions.
 

Detailed Description

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

Real-time partitioned convolution using overlap-save with FFT.

The impulse response is divided into partitions of size blockSize. Each partition is pre-transformed to the frequency domain. During processing, each input block is also transformed, multiplied with all IR partitions, and the results are accumulated with appropriate delays.

The block size determines both the FFT size (2 * blockSize for overlap-save) and the processing latency (= blockSize samples).

Template Parameters
TSample type (float or double).

Definition at line 67 of file Convolver.h.

Member Function Documentation

◆ getBlockSize()

template<typename T >
int dspark::Convolver< T >::getBlockSize ( ) const
inlinenoexcept

Returns the block size.

Definition at line 248 of file Convolver.h.

◆ getLatency()

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

Returns the processing latency in samples (= block size).

Definition at line 245 of file Convolver.h.

◆ getNumPartitions()

template<typename T >
int dspark::Convolver< T >::getNumPartitions ( ) const
inlinenoexcept

Returns the number of IR partitions.

Definition at line 251 of file Convolver.h.

◆ prepare() [1/2]

template<typename T >
void dspark::Convolver< T >::prepare ( const AudioSpec spec,
const T *  irData,
int  irLength 
)
inline

Prepares with AudioSpec and IR data (unified API).

Uses spec.maxBlockSize as the convolution block size.

Parameters
specAudio environment specification.
irDataImpulse response samples.
irLengthNumber of IR samples.
Note
If spec.maxBlockSize is not already a power of two the effective FFT block rounds up silently (e.g. 300 -> 512), doubling the effective latency. Use getBlockSize() after prepare to inspect the resolved value, or pre-set maxBlockSize to a power of two.

Definition at line 224 of file Convolver.h.

◆ prepare() [2/2]

template<typename T >
void dspark::Convolver< T >::prepare ( int  blockSize,
const T *  irData,
int  irLength 
)
inline

Prepares the convolver with an impulse response.

This is the only method that allocates memory. Call once during setup.

Parameters
blockSizeProcessing block size. Should be a power of two >= 2 (anything else rounds UP release-safely; check getBlockSize()). Determines latency and FFT size. Typical: 128, 256, 512.
irDataPointer to the impulse response samples.
irLengthNumber of samples in the impulse response.

Definition at line 82 of file Convolver.h.

◆ process()

template<typename T >
void dspark::Convolver< T >::process ( const T *  input,
T *  output,
int  numSamples 
)
inlinenoexcept

Processes a block of audio through the convolver.

numSamples may exceed the convolution block size: the run loop fires a partition transform at every block boundary, so arbitrary lengths are handled. input and output may be the SAME buffer (full in-place); partially overlapping buffers are not supported.

Parameters
inputInput audio samples.
outputOutput audio samples (convolved result).
numSamplesNumber of samples to process.

Definition at line 162 of file Convolver.h.

◆ processBlock()

template<typename T >
void dspark::Convolver< T >::processBlock ( AudioBufferView< T >  buffer)
inlinenoexcept

Processes an audio buffer in-place (unified API).

Important: Convolver is a mono processor. This method processes only channel 0. For multi-channel convolution, use separate Convolver instances per channel, or use the Reverb class.

Parameters
bufferAudio data (only channel 0 is convolved).

Definition at line 238 of file Convolver.h.

◆ processInPlace()

template<typename T >
void dspark::Convolver< T >::processInPlace ( T *  data,
int  numSamples 
)
inlinenoexcept

Processes audio in-place (output overwrites input).

Parameters
dataAudio samples (input and output).
numSamplesNumber of samples.

Definition at line 205 of file Convolver.h.

◆ reset()

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

Resets the convolution state (clears delay lines and buffers).

Definition at line 139 of file Convolver.h.


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