85 constexpr double maxPeriod =
static_cast<double>(std::numeric_limits<int>::max());
86 holdPeriod_ = (samples >= 1.0) ? std::min(samples, maxPeriod) : 1.0;
89 if (holdPeriod_ == std::floor(holdPeriod_))
90 phase_ = std::floor(phase_);
94 [[nodiscard]]
double getHoldPeriod() const noexcept {
return holdPeriod_; }
108 if (!(targetRate > 0.0) || !(actualRate > 0.0))
128 [[nodiscard]] T
process(T input,
bool trigger =
false) noexcept
131 advanceCounter(input);
153 for (
int i = 0; i < numSamples; ++i)
155 const T input = data[i];
156 advanceCounter(input);
158 data[i] = heldValue_;
161 else if (numSamples > 0)
164 previous_ = data[numSamples - 1];
165 for (
int i = 0; i < numSamples; ++i)
167 data[i] = heldValue_;
184 void processBlock(T* data,
const bool* triggers,
int numSamples)
noexcept
189 for (
int i = 0; i < numSamples; ++i)
193 heldValue_ = data[i];
196 data[i] = heldValue_;
216 void reset(T initialValue = T(0)) noexcept
218 heldValue_ = initialValue;
219 previous_ = initialValue;
227 inline void advanceCounter(T input)
noexcept
230 if (phase_ >= holdPeriod_)
232 phase_ -= holdPeriod_;
234 if (phase_ >= 1.0) phase_ = 0.0;
235 heldValue_ = (phase_ > 0.0) ? input -
static_cast<T
>(phase_) * (input - previous_)
241 double holdPeriod_ = 1.0;
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 whole samples.
double getHoldPeriod() const noexcept
Returns the Counter-mode hold period in samples.
void setMode(Mode mode) noexcept
Sets the operating mode.
void setHoldPeriod(double samples) noexcept
Sets a fractional hold period for Counter mode, in samples.
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 from 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.