DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
Loading...
Searching...
No Matches
Convolver.h File Reference

FFT-based partitioned convolution for long impulse responses. More...

#include "AudioBuffer.h"
#include "AudioSpec.h"
#include "FFT.h"
#include "SimdOps.h"
#include <algorithm>
#include <cassert>
#include <memory>
#include <vector>
Include dependency graph for Convolver.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  dspark::Convolver< T >
 Real-time partitioned convolution using overlap-save with FFT. More...
 

Namespaces

namespace  dspark
 Main namespace for the DSPark framework.
 

Detailed Description

FFT-based partitioned convolution for long impulse responses.

Implements the uniform partitioned overlap-save algorithm, which is the standard approach for real-time convolution with long impulse responses (reverb IRs, cabinet simulations, etc.). Breaks the IR into blocks, transforms each block with FFT, and convolves in the frequency domain.

Complexity: O(N log N) per block, vs O(N * M) for direct convolution. For a 2-second reverb IR at 48 kHz (96000 samples), direct convolution would require ~96000 multiplies per sample. FFT-based convolution needs ~20.

Dependencies: FFT.h, AudioBuffer.h, AudioSpec.h, SimdOps.h.

// Load an impulse response from a WAV file:
wav.openRead("cabinet.wav");
auto info = wav.getInfo();
ir.resize(1, static_cast<int>(info.numSamples));
wav.readSamples(ir.toView());
wav.close();
// Set up the convolver:
conv.prepare(512, ir.getChannel(0), static_cast<int>(info.numSamples));
// In your audio callback:
conv.process(inputBlock, outputBlock, blockSize);
Owning audio buffer with contiguous, 32-byte aligned storage.
AudioBufferView< T, MaxChannels > toView() noexcept
Returns a non-owning mutable view of this buffer. The view's channel capacity is propagated from MaxC...
T * getChannel(int ch) noexcept
Returns a pointer to the sample data.
void resize(int numChannels, int numSamples)
Allocates the buffer for the given dimensions.
Real-time partitioned convolution using overlap-save with FFT.
Definition Convolver.h:68
void process(const T *input, T *output, int numSamples) noexcept
Processes a block of audio through the convolver.
Definition Convolver.h:162
void prepare(int blockSize, const T *irData, int irLength)
Prepares the convolver with an impulse response.
Definition Convolver.h:82
Complete WAV file reader and writer in pure C++20.
Definition WavFile.h:67
AudioFileInfo getInfo() const override
Retrieves metadata of the currently opened file.
Definition WavFile.h:145
bool readSamples(AudioBufferView< float > dest) override
Reads samples from the start of the file into the destination view.
Definition WavFile.h:147
bool openRead(const std::filesystem::path &path) override
Opens a WAV file for reading.
Definition WavFile.h:78
void close() override
Finalizes file headers and releases system handles.
Definition WavFile.h:226

Definition in file Convolver.h.