65 holdPeriod_ = numSamples > 0 ? numSamples : 1;
78 void setHoldRate(
double targetRate,
double actualRate)
noexcept
80 if (!(targetRate > 0.0) || !(actualRate > 0.0))
87 const double ratio = actualRate / targetRate;
88 constexpr double maxPeriod =
static_cast<double>(std::numeric_limits<int>::max());
89 setHoldSamples(ratio >= maxPeriod ? std::numeric_limits<int>::max()
90 :
static_cast<int>(std::llround(ratio)));
105 [[nodiscard]] T
process(T input,
bool trigger =
false) noexcept
110 if (counter_ >= holdPeriod_)
141 for (
int i = 0; i < numSamples; ++i)
144 if (counter_ >= holdPeriod_)
146 heldValue_ = data[i];
149 data[i] = heldValue_;
155 for (
int i = 0; i < numSamples; ++i)
157 data[i] = heldValue_;
174 void processBlock(T* data,
const bool* triggers,
int numSamples)
noexcept
179 for (
int i = 0; i < numSamples; ++i)
183 heldValue_ = data[i];
185 data[i] = heldValue_;
205 void reset(T initialValue = T(0)) noexcept
207 heldValue_ = initialValue;
Core mathematical utilities for digital signal processing.
Holds a sample value for N samples or until externally triggered.
Mode
Defines the capture behavior of the processor.
@ Counter
Holds for a fixed number of samples automatically (Decimation).
@ Trigger
Holds until an external trigger captures a new value (level-sensitive).
void setHoldSamples(int numSamples) noexcept
Sets the hold duration for Counter mode in samples.
void setMode(Mode mode) noexcept
Sets the operating mode.
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.
T process(T input, bool trigger=false) noexcept
Processes a single sample.
void setHoldRate(double targetRate, double actualRate) noexcept
Sets the hold period based on a target effective sample rate.
void reset(T initialValue=T(0)) noexcept
Resets the processor state and sets an initial output value.
void processBlock(T *data, int numSamples) noexcept
Processes a block of samples in-place (Counter mode optimized).
Main namespace for the DSPark framework.