|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
Windowed-sinc sample rate converter optimized for real-time DSP. More...
#include <Resampler.h>
Public Types | |
| enum class | Quality { Draft , Normal , High , Ultra } |
Public Member Functions | |
| void | prepare (double sourceRate, double targetRate, Quality quality=Quality::Normal) |
| Prepares the resampler for a given rate conversion. | |
| void | prepare (const AudioSpec &spec, double targetRate, Quality quality=Quality::Normal) |
| Prepares the resampler using AudioSpec (unified API). | |
| void | reset () noexcept |
| Resets the internal state (delay lines, all channels) to zero. | |
| std::vector< T > | process (const T *input, int inputLength) |
| Resamples an entire buffer (offline batch processing). | |
| int | processBlock (const T *input, int inputLength, T *output) noexcept |
| Resamples a block of audio in single-channel streaming mode. | |
| int | processBlock (AudioBufferView< T > input, AudioBufferView< T > output) noexcept |
| Resamples multi-channel audio using AudioBufferView (streaming). | |
| int | getMaxOutputSamples (int inputLength) const noexcept |
| Returns the maximum number of output samples for a given input length. | |
| double | getRatio () const noexcept |
| Returns the conversion ratio (targetRate / sourceRate). | |
| int | getLatency () const noexcept |
| Returns the streaming latency in output samples. | |
Windowed-sinc sample rate converter optimized for real-time DSP.
Quality tiers trade CPU for image/alias rejection and passband flatness. Measured on the float instantiation (each column states its test):
| Quality | Taps | 20 kHz image (48->96) | 26 kHz alias (96->44.1) | 20 kHz gain (44.1->48) |
|---|---|---|---|---|
| Draft | 8 | -12 dB | -10 dB | -3.3 dB |
| Normal | 32 | -56 dB | -27 dB | -0.6 dB |
| High | 64 | -140 dB | -69 dB | -0.02 dB |
| Ultra | 128 | -139 dB | -143 dB | flat |
The middle column probes the transition band right at the target Nyquist: only Ultra's kernel is long enough to keep it in the deep stopband. For extreme downsampling ratios (beyond ~8:1) no fixed tap count can hold the anti-alias transition band; cascade two resamplers instead.
| T | Sample type (float or double). |
Definition at line 68 of file Resampler.h.
|
strong |
Definition at line 71 of file Resampler.h.
|
inlinenoexcept |
Returns the streaming latency in output samples.
The streaming path (processBlock) delays the signal by exactly sincPoints/2 input samples – the sinc kernel's group delay – which this getter reports rounded to the nearest output sample. The offline process() path is already time-aligned and has zero latency.
Definition at line 246 of file Resampler.h.
|
inlinenoexcept |
Returns the maximum number of output samples for a given input length.
| inputLength | Number of input samples. |
Definition at line 227 of file Resampler.h.
|
inlinenoexcept |
Returns the conversion ratio (targetRate / sourceRate).
Definition at line 236 of file Resampler.h.
|
inline |
Prepares the resampler using AudioSpec (unified API).
Pre-allocates multi-channel states. MUST be called outside the audio thread.
| spec | Audio environment (sampleRate, numChannels used). |
| targetRate | Target sample rate in Hz. |
| quality | Interpolation quality (default: Normal). |
Definition at line 114 of file Resampler.h.
|
inline |
Prepares the resampler for a given rate conversion.
Allocates internal buffers. MUST be called outside the audio thread.
| sourceRate | Source sample rate in Hz. |
| targetRate | Target sample rate in Hz. |
| quality | Interpolation quality (default: Normal). |
Definition at line 88 of file Resampler.h.
|
inline |
Resamples an entire buffer (offline batch processing).
Stateless and time-aligned: output sample k interpolates the input at position k / getRatio() exactly (no latency; the buffer edges are zero-padded). Allocates the output vector – offline use only.
| input | Source audio samples. |
| inputLength | Number of input samples. |
Definition at line 149 of file Resampler.h.
|
inlinenoexcept |
Resamples multi-channel audio using AudioBufferView (streaming).
Processes each channel sequentially with its independent state.
| input | Input audio buffer view. |
| output | Output audio buffer view (pre-allocated). |
Definition at line 200 of file Resampler.h.
|
inlinenoexcept |
Resamples a block of audio in single-channel streaming mode.
| input | Input audio samples. |
| inputLength | Number of input samples. |
| output | Output buffer (must hold at least getMaxOutputSamples()). |
Definition at line 186 of file Resampler.h.
|
inlinenoexcept |
Resets the internal state (delay lines, all channels) to zero.
Safe to call from the audio thread after prepare(): the assigns below only refill storage that prepare() already sized (no reallocation).
Definition at line 127 of file Resampler.h.