|
| | Dither (int targetBits=16, bool noiseShaping=false) noexcept |
| | Constructs a dithering processor.
|
| |
| void | setTargetBitDepth (int bits) noexcept |
| | Sets the target bit depth and recalculates scaling factors.
|
| |
| void | setNoiseShaping (bool enabled) noexcept |
| | Enables or disables noise shaping.
|
| |
| void | setShaper (Shaper shaper) noexcept |
| | Selects the noise-shaping filter (used while shaping is enabled).
|
| |
| Shaper | getShaper () const noexcept |
| | Returns the selected noise-shaping filter.
|
| |
| void | reset () noexcept |
| | Resets the noise shaping state. Call this when playback stops or flushes.
|
| |
| T | processSample (T input, int channel=0) noexcept |
| | Applies TPDF dither and quantises a single sample.
|
| |
| void | processBlock (T *data, int numSamples, int channel=0) noexcept |
| | Applies dithering to an entire audio buffer in-place.
|
| |
| int | getTargetBitDepth () const noexcept |
| |
| T | getQuantisationStep () const noexcept |
| |
template<typename T>
class dspark::Dither< T >
TPDF dithering processor with optional noise shaping.
Adds Triangular Probability Density Function (TPDF) noise of 2 LSB peak-to-peak before quantisation. This replaces correlated quantisation distortion (truncation harmonics, noise modulation) with a constant, signal-independent noise floor.
The optional noise shaper feeds back the total requantisation error (dither + quantiser) through a filter of the past errors:
- Shaper::FirstOrder (default): one-sample delay, first-order highpass shaping of the entire noise floor: about 15 dB less noise at 1 kHz (44.1 kHz rate) in exchange for a gentle rise towards Nyquist.
- Shaper::Lipshitz5: the 5-tap error filter {2.033, -2.165, 1.959, -1.590, 0.6149} of Lipshitz, Vanderkooy and Wannamaker, "Minimally
Audible Noise Shaping" (JAES 1991), designed for 44.1 kHz. It moves the noise out of the 1-5 kHz region where hearing is most sensitive: about 5 dB less noise there than first order (measured -113.1 vs -108.2 dB in 1-5 kHz for 16 bits), more above 15 kHz. At other rates the curve shifts with the rate.
Quantised output lies exactly on the integer level grid of the target depth: levels in [-2^(bits-1), 2^(bits-1) - 1], so positive full scale is one step below 1.0, exactly like the int16/int24 file writers. Feeding the output to WavFile round-trips bit-exactly.
Non-finite input is sanitised on entry (NaN becomes silence, infinities clip to full scale), so a single bad sample cannot poison the error feedback: before, one NaN made every later sample NaN until reset().
Threading is owner-managed: call setters and processing from the thread that owns the stream (the PRNG and error state are plain members by design). Use one instance per processing thread.
- Template Parameters
-
| T | Sample type (float or double). |
Definition at line 68 of file Dither.h.