Threshold comparator with hysteresis — the bridge from the signal domain to the event domain. More...
#include <mod_tools.hpp>
Public Member Functions | |
| void | set_threshold (SampleType t) |
| Setting a threshold re-derives the default hysteresis unless an explicit one was set first. | |
| void | set_hysteresis (SampleType h) |
| Absolute dead band, in the input's units. | |
| void | reset (bool gate=false) |
| bool | process (SampleType x) |
| bool | gate () const |
| SampleType | hysteresis () const |
Static Public Attributes | |
| static constexpr SampleType | kDefaultHysteresisFraction = SampleType{0.05} |
| Default dead band, as a fraction of the threshold magnitude. | |
| static constexpr SampleType | kMinAutoHysteresis = SampleType{0.001} |
| Floor for the derived dead band. | |
Threshold comparator with hysteresis — the bridge from the signal domain to the event domain.
The gate goes high above threshold + hysteresis and low below threshold - hysteresis. Without the dead band, a source that dithers across the threshold — which is every real modulation signal, including a slow sine near its own zero crossing — chatters the gate on and off at the sample rate.
RT contract: one bool of state; process() and reset() allocate nothing.
USE: turning any modulation signal into a clock or a gate. An LFO through a comparator is a clock whose duty cycle is the threshold. An envelope through a comparator is "the note is loud enough to count".
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Absolute dead band, in the input's units.
Pins the value against later set_threshold() calls.
|
inline |
Setting a threshold re-derives the default hysteresis unless an explicit one was set first.
|
staticconstexpr |
Default dead band, as a fraction of the threshold magnitude.
|
staticconstexpr |
Floor for the derived dead band.
A threshold of 0 — the natural one for any bipolar signal — would otherwise derive a dead band of 0, which is exactly the chatter this class exists to prevent.