|
DSPark 1.8.0
Header-only C++20 DSP for real-time and offline audio
|
Holds a sample value for N samples or until externally triggered. More...
#include <SampleAndHold.h>
Public Types | |
| enum class | Mode { Counter , Trigger } |
| Defines the capture behavior of the processor. More... | |
Public Member Functions | |
| void | setMode (Mode mode) noexcept |
| Sets the operating mode. | |
| void | setHoldSamples (int numSamples) noexcept |
| Sets the hold duration for Counter mode in whole samples. | |
| void | setHoldPeriod (double samples) noexcept |
| Sets a fractional hold period for Counter mode, in samples. | |
| double | getHoldPeriod () const noexcept |
| Returns the Counter-mode hold period in samples. | |
| void | setHoldRate (double targetRate, double actualRate) noexcept |
| Sets the hold period from a target effective sample rate. | |
| T | process (T input, bool trigger=false) noexcept |
| Processes a single sample. | |
| void | processBlock (T *data, int numSamples) noexcept |
| Processes a block of samples in-place (Counter mode optimized). | |
| void | processBlock (T *data, const bool *triggers, int numSamples) noexcept |
| Processes a block of samples in-place using an external trigger buffer. | |
| T | getHeldValue () const noexcept |
| Retrieves the current held value without advancing the state. | |
| void | reset (T initialValue=T(0)) noexcept |
| Resets the processor state and sets an initial output value. | |
Holds a sample value for N samples or until externally triggered.
| T | Sample type (must satisfy FloatType concept). |
Definition at line 39 of file SampleAndHold.h.
|
strong |
Defines the capture behavior of the processor.
| Enumerator | |
|---|---|
| Counter | Holds for a fixed number of samples automatically (Decimation). |
| Trigger | Holds until an external trigger captures a new value (level-sensitive). |
Definition at line 43 of file SampleAndHold.h.
|
inlinenoexcept |
Retrieves the current held value without advancing the state.
Definition at line 209 of file SampleAndHold.h.
|
inlinenoexcept |
Returns the Counter-mode hold period in samples.
Definition at line 94 of file SampleAndHold.h.
|
inlinenoexcept |
Processes a single sample.
| input | The audio or modulation input sample. |
| trigger | External trigger state (ignored in Counter mode). The trigger is level-sensitive: while it stays true, the input is tracked sample-by-sample; send single-sample pulses for classic S&H capture. |
Definition at line 128 of file SampleAndHold.h.
|
inlinenoexcept |
Processes a block of samples in-place using an external trigger buffer.
Only relevant when Mode is set to Trigger (level-sensitive, same semantics as process()). If Mode is Counter, the triggers buffer is safely ignored.
| data | Audio buffer to process in-place. |
| triggers | Array of boolean triggers, one per sample. A null pointer is treated as "no triggers" (the current value is held). |
| numSamples | Number of samples in the buffer. |
Definition at line 184 of file SampleAndHold.h.
|
inlinenoexcept |
Processes a block of samples in-place (Counter mode optimized).
If the processor is in Trigger mode, calling this method will simply fill the buffer with the last held value. For Trigger mode processing, use the overloaded processBlock with the trigger buffer.
| data | Audio buffer to process in-place. |
| numSamples | Number of samples in the buffer. |
Definition at line 148 of file SampleAndHold.h.
|
inlinenoexcept |
Resets the processor state and sets an initial output value.
| initialValue | Value to output until the next capture triggers. |
Definition at line 216 of file SampleAndHold.h.
|
inlinenoexcept |
Sets a fractional hold period for Counter mode, in samples.
A non-integer period keeps the average capture rate exact, so a swept rate moves continuously instead of jumping between whole-sample periods (at 48 kHz those are 24 k, 16 k, 12 k, 9.6 k...). Each capture takes the input at its exact fractional instant, interpolated linearly between the two neighbouring samples; the held steps themselves still change on sample boundaries. Integer periods behave exactly as setHoldSamples().
| samples | Hold period in samples. Values below 1 and NaN clamp to 1; huge values clamp to 2^31 - 1 (holds indefinitely). |
Definition at line 83 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the hold period from a target effective sample rate.
The period is the exact ratio actualRate / targetRate (fractional, see setHoldPeriod()), so the effective rate is exactly targetRate on average.
| targetRate | The desired effective sample rate in Hz. Invalid values (non-positive or NaN, either argument) reset the period to 1. |
| actualRate | The current system sample rate in Hz. |
Definition at line 106 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the hold duration for Counter mode in whole samples.
A value of 1 passes the signal transparently. A value of N reduces the effective sample rate by a factor of N. Capture phase: after reset(), the first capture happens on the Nth call (the initial value is output for the first N-1 samples), then every N samples.
| numSamples | Hold period in samples. Clamped to a minimum of 1. |
Definition at line 65 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the operating mode.
| mode | Mode::Counter or Mode::Trigger. |
Definition at line 53 of file SampleAndHold.h.