Zero-latency lookup-table waveshaper with RT-safe gain modulation.
More...
#include <WaveshapeTable.h>
|
| | WaveshapeTable () |
| | Constructor. Initializes a safe passthrough table to prevent RT crashes.
|
| |
| void | buildFromFunction (std::function< T(T)> func, int tableSize=4096, T xMax=T(8)) |
| | Builds the lookup table from an arbitrary transfer function.
|
| |
| void | buildTanh (int tableSize=4096) |
| | Builds a normalized tanh (soft clip) table.
|
| |
| void | buildHardClip (T threshold=T(0.8), int tableSize=4096) |
| | Builds a hard-clip table.
|
| |
| void | buildSoftClip (int tableSize=4096) |
| | Builds a cubic soft-clip table.
|
| |
| void | buildAsymmetric (int tableSize=4096) |
| | Builds an asymmetric clipping table for even-harmonic generation.
|
| |
| T | process (T input, T preGain=T(1), T postGain=T(1)) const noexcept |
| | Processes a single sample through the waveshaper with Hermite interpolation.
|
| |
| void | process (T *__restrict data, int numSamples, T preGain=T(1), T postGain=T(1)) const noexcept |
| | Processes a buffer in-place.
|
| |
| void | prepare (const AudioSpec &spec) |
| | Prepares the waveshaper for oversampled block processing.
|
| |
| void | setOversampling (int factor) |
| | Enables oversampling.
|
| |
| int | getOversamplingFactor () const noexcept |
| |
| void | processBlock (AudioBufferView< T > buffer, T preGain=T(1), T postGain=T(1)) noexcept |
| | Processes a buffer view with optional oversampling.
|
| |
| void | reset () noexcept |
| |
| int | getTableSize () const noexcept |
| |
| bool | isReady () const noexcept |
| |
| T | getInputRange () const noexcept |
| | Returns the half-range of the table's input domain.
|
| |
| int | getLatency () const noexcept |
| | Reports the processing latency in samples.
|
| |
template<FloatType T>
class dspark::WaveshapeTable< T >
Zero-latency lookup-table waveshaper with RT-safe gain modulation.
- Template Parameters
-
| T | Sample type (float or double). |
Definition at line 59 of file WaveshapeTable.h.
◆ WaveshapeTable()
Constructor. Initializes a safe passthrough table to prevent RT crashes.
Definition at line 65 of file WaveshapeTable.h.
◆ buildAsymmetric()
Builds an asymmetric clipping table for even-harmonic generation.
- Parameters
-
Definition at line 155 of file WaveshapeTable.h.
◆ buildFromFunction()
template<FloatType T>
| void dspark::WaveshapeTable< T >::buildFromFunction |
( |
std::function< T(T)> |
func, |
|
|
int |
tableSize = 4096, |
|
|
T |
xMax = T(8) |
|
) |
| |
|
inline |
Builds the lookup table from an arbitrary transfer function.
- Warning
- Allocates memory. Do not call from the audio thread.
The table spans the input range [-xMax, +xMax]. A range wider than the nominal [-1, 1] is what makes preGain work as a true drive control: driven samples keep following the curve instead of slamming into a hard plateau at the table edge.
- Parameters
-
| func | Transfer function mapping [-xMax, xMax] to output. |
| tableSize | Number of active table entries (default: 4096). |
| xMax | Half-range of the table input domain (default: 8). |
Definition at line 84 of file WaveshapeTable.h.
◆ buildHardClip()
Builds a hard-clip table.
- Parameters
-
| threshold | Clipping threshold (0 to 1, default: 0.8). |
| tableSize | Table entries. |
Definition at line 131 of file WaveshapeTable.h.
◆ buildSoftClip()
◆ buildTanh()
Builds a normalized tanh (soft clip) table.
- Note
- Use
preGain in process() to drive the saturation in Real-Time.
- Parameters
-
| tableSize | Table entries (default: 4096). |
Definition at line 121 of file WaveshapeTable.h.
◆ getInputRange()
Returns the half-range of the table's input domain.
Definition at line 285 of file WaveshapeTable.h.
◆ getLatency()
Reports the processing latency in samples.
- Returns
- The oversampler group delay (0 when oversampling is off). Report this to the host for plugin delay compensation.
Definition at line 292 of file WaveshapeTable.h.
◆ getOversamplingFactor()
◆ getTableSize()
◆ isReady()
◆ prepare()
Prepares the waveshaper for oversampled block processing.
- Parameters
-
Definition at line 215 of file WaveshapeTable.h.
◆ process() [1/2]
template<FloatType T>
| void dspark::WaveshapeTable< T >::process |
( |
T *__restrict |
data, |
|
|
int |
numSamples, |
|
|
T |
preGain = T(1), |
|
|
T |
postGain = T(1) |
|
) |
| const |
|
inlinenoexcept |
Processes a buffer in-place.
Tight scalar loop: the data-dependent table gather defeats autovectorization, so per-sample cost is the process() call inlined.
- Parameters
-
| data | Audio samples pointer (should ideally be __restrict). |
| numSamples | Number of samples to process. |
| preGain | Gain to drive into the shaper. |
| postGain | Gain to compensate volume output. |
Definition at line 203 of file WaveshapeTable.h.
◆ process() [2/2]
Processes a single sample through the waveshaper with Hermite interpolation.
- Parameters
-
| input | Input sample. |
| preGain | Real-time drive/gain applied before lookup (default 1.0). |
| postGain | Real-time makeup gain applied after lookup (default 1.0). |
- Returns
- Shaped output sample.
Definition at line 170 of file WaveshapeTable.h.
◆ processBlock()
Processes a buffer view with optional oversampling.
- Parameters
-
| buffer | Audio buffer view. |
| preGain | Real-time drive applied per-sample. |
| postGain | Real-time makeup gain applied per-sample. |
Definition at line 256 of file WaveshapeTable.h.
◆ reset()
◆ setOversampling()
Enables oversampling.
- Warning
- Allocates memory. Do not call from the audio thread.
- Parameters
-
Definition at line 227 of file WaveshapeTable.h.
The documentation for this class was generated from the following file: