DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::Convolver< T > Class Template Reference

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

#include <Convolver.h>

Public Types

enum class  Partitioning { Uniform , NonUniform }
 How the impulse response is partitioned (see the file notes). More...
 

Public Member Functions

void prepare (int blockSize, const T *irData, int irLength, Partitioning partitioning=Partitioning::Uniform)
 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: the block-size head partitions, plus the larger tail partitions in NonUniform mode.
 
int getTailBlockSize () const noexcept
 Tail partition size in NonUniform mode, 0 when the IR is convolved in block-size partitions only.
 

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 77 of file Convolver.h.

Member Enumeration Documentation

◆ Partitioning

template<typename T >
enum class dspark::Convolver::Partitioning
strong

How the impulse response is partitioned (see the file notes).

Enumerator
Uniform 

Every partition the block size (default).

NonUniform 

Block-size head, larger time-distributed tail partitions.

Definition at line 81 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 283 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 280 of file Convolver.h.

◆ getNumPartitions()

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

Returns the number of IR partitions: the block-size head partitions, plus the larger tail partitions in NonUniform mode.

Definition at line 287 of file Convolver.h.

◆ getTailBlockSize()

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

Tail partition size in NonUniform mode, 0 when the IR is convolved in block-size partitions only.

Definition at line 291 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 259 of file Convolver.h.

◆ prepare() [2/2]

template<typename T >
void dspark::Convolver< T >::prepare ( int  blockSize,
const T *  irData,
int  irLength,
Partitioning  partitioning = Partitioning::Uniform 
)
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.
partitioningUniform (default) or NonUniform. The latency is the block size either way, and the output the same convolution up to rounding. NonUniform only splits an IR long enough for it to pay.

Definition at line 103 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 192 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 273 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 240 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 168 of file Convolver.h.


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