Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
pulp::signal::ComparatorT< SampleType > Class Template Reference

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.

Detailed Description

template<typename SampleType = float>
class pulp::signal::ComparatorT< SampleType >

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".

Member Function Documentation

◆ gate()

template<typename SampleType = float>
bool pulp::signal::ComparatorT< SampleType >::gate ( ) const
inline

◆ hysteresis()

template<typename SampleType = float>
SampleType pulp::signal::ComparatorT< SampleType >::hysteresis ( ) const
inline

◆ process()

template<typename SampleType = float>
bool pulp::signal::ComparatorT< SampleType >::process ( SampleType x)
inline

◆ reset()

template<typename SampleType = float>
void pulp::signal::ComparatorT< SampleType >::reset ( bool gate = false)
inline

◆ set_hysteresis()

template<typename SampleType = float>
void pulp::signal::ComparatorT< SampleType >::set_hysteresis ( SampleType h)
inline

Absolute dead band, in the input's units.

Pins the value against later set_threshold() calls.

◆ set_threshold()

template<typename SampleType = float>
void pulp::signal::ComparatorT< SampleType >::set_threshold ( SampleType t)
inline

Setting a threshold re-derives the default hysteresis unless an explicit one was set first.

Member Data Documentation

◆ kDefaultHysteresisFraction

template<typename SampleType = float>
SampleType pulp::signal::ComparatorT< SampleType >::kDefaultHysteresisFraction = SampleType{0.05}
staticconstexpr

Default dead band, as a fraction of the threshold magnitude.

◆ kMinAutoHysteresis

template<typename SampleType = float>
SampleType pulp::signal::ComparatorT< SampleType >::kMinAutoHysteresis = SampleType{0.001}
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.


The documentation for this class was generated from the following file:
  • /home/runner/work/pulp/pulp/core/signal/include/pulp/signal/mod_tools.hpp