|
DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
|
Artifact-free, SIMD-friendly crossfader for two audio signals. More...
#include <Crossfade.h>
Public Types | |
| enum class | Curve { Linear , EqualPower , SCurve } |
| Defines the amplitude response of the crossfade transition. More... | |
Public Member Functions | |
| Crossfade ()=default | |
| ~Crossfade ()=default | |
| void | prepare (double sampleRate) noexcept |
| Enables the time-based glide (optional). | |
| void | prepare (const AudioSpec &spec) noexcept |
| Enables the time-based glide from an audio spec (see prepare(double)). | |
| void | reset () noexcept |
| Lands the applied position and curve on the requested ones, with no glide (for example at transport start). Settings changed before the next processing call are applied at once too. | |
| void | setCurve (Curve curve) noexcept |
| Sets the crossfade curve type. Thread-safe. Can be called from the GUI thread. A curve change is blended from the old law to the new one across the next block. | |
| void | setPosition (T position) noexcept |
| Sets the target crossfade blend position. | |
| T | getPosition () const noexcept |
| Retrieves the last requested position. | |
| T | process (T a, T b) noexcept |
| Crossfades two individual samples. | |
| void | process (const T *inputA, const T *inputB, T *output, int numSamples) noexcept |
| Crossfades two audio buffers into an output buffer with automatic parameter smoothing. | |
| void | processAutomated (const T *inputA, const T *inputB, const T *positions, T *output, int numSamples) noexcept |
| Processes crossfading using a per-sample automation buffer. | |
| T | getGainA () const noexcept |
| Gets the current internal gain multiplier for signal A. Safe from any thread: loads a published atomic word, so it may be up to one processing call behind. | |
| T | getGainB () const noexcept |
| Gets the current internal gain multiplier for signal B. Safe from any thread: loads a published atomic word, so it may be up to one processing call behind. | |
Static Public Member Functions | |
| static void | gainsFor (Curve curve, T position, T &gainA, T &gainB) noexcept |
| The gains a curve applies at a position. | |
Artifact-free, SIMD-friendly crossfader for two audio signals.
Marked as final to explicitly prohibit inheritance and avoid vtable overhead, adhering to the framework's zero virtual dispatch policy in DSP nodes.
| T | Sample type (float or double). Requires std::is_floating_point_v<T>. |
Definition at line 62 of file Crossfade.h.
|
strong |
Defines the amplitude response of the crossfade transition.
Definition at line 66 of file Crossfade.h.
|
default |
|
default |
|
inlinestaticnoexcept |
The gains a curve applies at a position.
The exact law the processing calls use, so a caller can predict or normalize a blend without running one.
| curve | Crossfade curve. |
| position | Blend position, clamped to [0, 1] (NaN reads as 0). |
| gainA | Receives the gain of signal A. |
| gainB | Receives the gain of signal B. |
Definition at line 159 of file Crossfade.h.
|
inlinenoexcept |
Gets the current internal gain multiplier for signal A. Safe from any thread: loads a published atomic word, so it may be up to one processing call behind.
Definition at line 314 of file Crossfade.h.
|
inlinenoexcept |
Gets the current internal gain multiplier for signal B. Safe from any thread: loads a published atomic word, so it may be up to one processing call behind.
Definition at line 322 of file Crossfade.h.
|
inlinenoexcept |
Retrieves the last requested position.
Definition at line 143 of file Crossfade.h.
|
inlinenoexcept |
Enables the time-based glide from an audio spec (see prepare(double)).
| spec | Audio environment; only the sample rate is used. |
Definition at line 98 of file Crossfade.h.
|
inlinenoexcept |
Enables the time-based glide (optional).
Once prepared, position changes move the applied position by at most one full sweep per 20 ms in both processing calls, independently of the block size: a per-block ramp lands in 0.7 ms with 32-sample blocks and clicks. Also lands the applied position on the requested one (reset()). Invalid rates (non-positive or non-finite) are ignored.
| sampleRate | Sample rate in Hz. |
Definition at line 87 of file Crossfade.h.
|
inlinenoexcept |
Crossfades two audio buffers into an output buffer with automatic parameter smoothing.
While the applied position is settled this is a vectorized static gain loop. During a glide (see the file overview) the curve is evaluated at every sample; a curve change is blended from the old law to the new one across the block.
| inputA | Pointer to the first input buffer array. Must not be null. |
| inputB | Pointer to the second input buffer array. Must not be null. |
| output | Pointer to the output buffer array. Must not be null. May alias either input. |
| numSamples | Number of samples to process. Must be > 0. |
Definition at line 207 of file Crossfade.h.
|
inlinenoexcept |
Crossfades two individual samples.
Unprepared, the gains follow the position at once, which suits per-sample automation through setPosition(). Prepared, the applied position glides at the same rate as in the block call. Must only be called from the audio thread.
| a | Input sample A (Dry/Left). |
| b | Input sample B (Wet/Right). |
Definition at line 178 of file Crossfade.h.
|
inlinenoexcept |
Processes crossfading using a per-sample automation buffer.
The positions are applied as given (no glide). The next call of the other processing methods glides from the last automated position to the requested one.
| inputA | Pointer to the first input buffer. |
| inputB | Pointer to the second input buffer. |
| positions | Array of target positions [0, 1] per sample. Values are clamped; NaN reads as 0 (100% A). |
| output | Pointer to the output buffer. |
| numSamples | Number of samples to process. |
Definition at line 279 of file Crossfade.h.
|
inlinenoexcept |
Lands the applied position and curve on the requested ones, with no glide (for example at transport start). Settings changed before the next processing call are applied at once too.
Definition at line 105 of file Crossfade.h.
|
inlinenoexcept |
Sets the crossfade curve type. Thread-safe. Can be called from the GUI thread. A curve change is blended from the old law to the new one across the next block.
| curve | The desired crossfade curve. Out-of-range values (a wild cast) are clamped into the enum range. |
Definition at line 118 of file Crossfade.h.
|
inlinenoexcept |
Sets the target crossfade blend position.
Thread-safe. The processing calls glide to it (see the file overview).
| position | Target blend: 0.0 = 100% A, 1.0 = 100% B. Automatically clamped [0, 1]; non-finite values are ignored. |
Definition at line 133 of file Crossfade.h.