|
DSPark 1.6.1
Header-only audio DSP framework in pure C++20 — zero dependencies
|
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 samples. | |
| void | setHoldRate (double targetRate, double actualRate) noexcept |
| Sets the hold period based on 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 37 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 41 of file SampleAndHold.h.
|
inlinenoexcept |
Retrieves the current held value without advancing the state.
Definition at line 198 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 105 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 174 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 136 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 205 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the hold period based on a target effective sample rate.
The period is rounded to the nearest integer (truncating would bias the effective rate upward) and clamped to a valid range.
| 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 78 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the hold duration for Counter mode in 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 63 of file SampleAndHold.h.
|
inlinenoexcept |
Sets the operating mode.
| mode | Mode::Counter or Mode::Trigger. |
Definition at line 51 of file SampleAndHold.h.