|
DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
|
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. | |
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).
| T | Sample type (float or double). |
Definition at line 77 of file Convolver.h.
|
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.
|
inlinenoexcept |
Returns the block size.
Definition at line 283 of file Convolver.h.
|
inlinenoexcept |
Returns the processing latency in samples (= block size).
Definition at line 280 of file Convolver.h.
|
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.
|
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.
|
inline |
Prepares with AudioSpec and IR data (unified API).
Uses spec.maxBlockSize as the convolution block size.
| spec | Audio environment specification. |
| irData | Impulse response samples. |
| irLength | Number of IR samples. |
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.
|
inline |
Prepares the convolver with an impulse response.
This is the only method that allocates memory. Call once during setup.
| blockSize | Processing 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. |
| irData | Pointer to the impulse response samples. |
| irLength | Number of samples in the impulse response. |
| partitioning | Uniform (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.
|
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.
| input | Input audio samples. |
| output | Output audio samples (convolved result). |
| numSamples | Number of samples to process. |
Definition at line 192 of file Convolver.h.
|
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.
| buffer | Audio data (only channel 0 is convolved). |
Definition at line 273 of file Convolver.h.
|
inlinenoexcept |
Processes audio in-place (output overwrites input).
| data | Audio samples (input and output). |
| numSamples | Number of samples. |
Definition at line 240 of file Convolver.h.
|
inlinenoexcept |
Resets the convolution state (clears delay lines and buffers).
Definition at line 168 of file Convolver.h.