DSPark 1.9.0
Header-only C++20 DSP for real-time and offline audio
Loading...
Searching...
No Matches
dspark::TriggeredEnvelope< T > Class Template Reference

DAHDSR envelope with bending curves, triggered by notes or by audio. More...

#include <TriggeredEnvelope.h>

Public Types

enum class  Stage {
  Idle , Delay , Attack , Hold ,
  Decay , Sustain , Release
}
 
enum class  Trigger { Notes , Audio }
 

Public Member Functions

 TriggeredEnvelope () noexcept
 
void prepare (double sampleRate) noexcept
 Prepares for a sample rate (invalid rates are ignored).
 
void setDelay (T ms) noexcept
 Delay before the attack, in ms (>= 0; non-finite ignored).
 
void setAttack (T ms) noexcept
 Attack, 0 to 1, in ms.
 
void setHold (T ms) noexcept
 Hold at the top, in ms.
 
void setDecay (T ms) noexcept
 Decay, 1 to the sustain, in ms.
 
void setRelease (T ms) noexcept
 Release, full scale to 0, in ms (from a lower value it arrives earlier).
 
void setTimes (T delayMs, T attackMs, T holdMs, T decayMs, T releaseMs) noexcept
 All five times at once, in ms.
 
void setSustain (T level) noexcept
 The sustain level, 0..1 (non-finite ignored). During the decay the rest of the decay bends to it; during the sustain the output moves to it at the decay's pace.
 
void setCurves (T attack, T decay, T release) noexcept
 The curves of the attack, the decay and the release, -1 (slow start) to 1 (fast start), 0 straight (non-finite ignored). A curve that changes in the middle of its stage keeps the output where it is.
 
void setBipolar (bool on) noexcept
 Output centred on the sustain (see the file notes).
 
bool isBipolar () const noexcept
 
void setTrigger (Trigger trigger) noexcept
 Notes (noteOn()/noteOff()) or the audio of the key signal.
 
Trigger getTrigger () const noexcept
 
void setThresholdDb (T db) noexcept
 Level of the key above which the audio trigger starts the envelope, in dB (non-finite ignored).
 
void setHysteresisDb (T db) noexcept
 How far below the threshold the key must fall to let go, in dB (0..40; 6 by default).
 
void setReleaseWaitMs (T ms) noexcept
 How long the key must stay below that before the release, in ms (>= 0; 50 by default).
 
void noteOn () noexcept
 Starts the envelope (from where the output is).
 
void noteOff () noexcept
 Lets the envelope go to its release (from where the output is).
 
void reset () noexcept
 Back to rest at 0, the trigger disarmed.
 
Stage getStage () const noexcept
 
T getValue () const noexcept
 The envelope now, 0..1 (before the bipolar mapping).
 
bool isActive () const noexcept
 
T process (T key=T(0)) noexcept
 One sample: the key (read by the audio trigger), then the output.
 
void processBlock (const T *key, T *out, int numSamples) noexcept
 A block: key drives the audio trigger (may be null with the note trigger), the envelope goes to out.
 

Detailed Description

template<FloatType T>
class dspark::TriggeredEnvelope< T >

DAHDSR envelope with bending curves, triggered by notes or by audio.

env.prepare(48000.0);
env.setThresholdDb(-30.0f);
env.setTimes(0.0f, 5.0f, 20.0f, 150.0f, 300.0f); // delay, attack, hold, decay, release
env.setSustain(0.4f);
env.processBlock(keySignal, modulation, numSamples);
DAHDSR envelope with bending curves, triggered by notes or by audio.
void processBlock(const T *key, T *out, int numSamples) noexcept
A block: key drives the audio trigger (may be null with the note trigger), the envelope goes to out.
void setThresholdDb(T db) noexcept
Level of the key above which the audio trigger starts the envelope, in dB (non-finite ignored).
void setSustain(T level) noexcept
The sustain level, 0..1 (non-finite ignored). During the decay the rest of the decay bends to it; dur...
void prepare(double sampleRate) noexcept
Prepares for a sample rate (invalid rates are ignored).
void setTrigger(Trigger trigger) noexcept
Notes (noteOn()/noteOff()) or the audio of the key signal.
void setTimes(T delayMs, T attackMs, T holdMs, T decayMs, T releaseMs) noexcept
All five times at once, in ms.
Template Parameters
TSample type (float or double). The phases are double.

Definition at line 70 of file TriggeredEnvelope.h.

Member Enumeration Documentation

◆ Stage

template<FloatType T>
enum class dspark::TriggeredEnvelope::Stage
strong
Enumerator
Idle 
Delay 
Attack 
Hold 
Decay 
Sustain 
Release 

Definition at line 73 of file TriggeredEnvelope.h.

◆ Trigger

template<FloatType T>
enum class dspark::TriggeredEnvelope::Trigger
strong
Enumerator
Notes 
Audio 

Definition at line 74 of file TriggeredEnvelope.h.

Constructor & Destructor Documentation

◆ TriggeredEnvelope()

template<FloatType T>
dspark::TriggeredEnvelope< T >::TriggeredEnvelope ( )
inlinenoexcept

Definition at line 76 of file TriggeredEnvelope.h.

Member Function Documentation

◆ getStage()

template<FloatType T>
Stage dspark::TriggeredEnvelope< T >::getStage ( ) const
inlinenoexcept

Definition at line 228 of file TriggeredEnvelope.h.

◆ getTrigger()

template<FloatType T>
Trigger dspark::TriggeredEnvelope< T >::getTrigger ( ) const
inlinenoexcept

Definition at line 175 of file TriggeredEnvelope.h.

◆ getValue()

template<FloatType T>
T dspark::TriggeredEnvelope< T >::getValue ( ) const
inlinenoexcept

The envelope now, 0..1 (before the bipolar mapping).

Definition at line 230 of file TriggeredEnvelope.h.

◆ isActive()

template<FloatType T>
bool dspark::TriggeredEnvelope< T >::isActive ( ) const
inlinenoexcept

Definition at line 231 of file TriggeredEnvelope.h.

◆ isBipolar()

template<FloatType T>
bool dspark::TriggeredEnvelope< T >::isBipolar ( ) const
inlinenoexcept

Definition at line 169 of file TriggeredEnvelope.h.

◆ noteOff()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::noteOff ( )
inlinenoexcept

Lets the envelope go to its release (from where the output is).

Definition at line 211 of file TriggeredEnvelope.h.

◆ noteOn()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::noteOn ( )
inlinenoexcept

Starts the envelope (from where the output is).

Definition at line 202 of file TriggeredEnvelope.h.

◆ prepare()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::prepare ( double  sampleRate)
inlinenoexcept

Prepares for a sample rate (invalid rates are ignored).

Definition at line 79 of file TriggeredEnvelope.h.

◆ process()

template<FloatType T>
T dspark::TriggeredEnvelope< T >::process ( T  key = T(0))
inlinenoexcept

One sample: the key (read by the audio trigger), then the output.

Parameters
keyKey signal sample (ignored with the note trigger).

Definition at line 239 of file TriggeredEnvelope.h.

◆ processBlock()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::processBlock ( const T *  key,
T *  out,
int  numSamples 
)
inlinenoexcept

A block: key drives the audio trigger (may be null with the note trigger), the envelope goes to out.

Definition at line 250 of file TriggeredEnvelope.h.

◆ reset()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::reset ( )
inlinenoexcept

Back to rest at 0, the trigger disarmed.

Definition at line 218 of file TriggeredEnvelope.h.

◆ setAttack()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setAttack ( T  ms)
inlinenoexcept

Attack, 0 to 1, in ms.

Definition at line 91 of file TriggeredEnvelope.h.

◆ setBipolar()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setBipolar ( bool  on)
inlinenoexcept

Output centred on the sustain (see the file notes).

Definition at line 168 of file TriggeredEnvelope.h.

◆ setCurves()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setCurves ( T  attack,
T  decay,
T  release 
)
inlinenoexcept

The curves of the attack, the decay and the release, -1 (slow start) to 1 (fast start), 0 straight (non-finite ignored). A curve that changes in the middle of its stage keeps the output where it is.

Definition at line 147 of file TriggeredEnvelope.h.

◆ setDecay()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setDecay ( T  ms)
inlinenoexcept

Decay, 1 to the sustain, in ms.

Definition at line 95 of file TriggeredEnvelope.h.

◆ setDelay()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setDelay ( T  ms)
inlinenoexcept

Delay before the attack, in ms (>= 0; non-finite ignored).

Definition at line 89 of file TriggeredEnvelope.h.

◆ setHold()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setHold ( T  ms)
inlinenoexcept

Hold at the top, in ms.

Definition at line 93 of file TriggeredEnvelope.h.

◆ setHysteresisDb()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setHysteresisDb ( T  db)
inlinenoexcept

How far below the threshold the key must fall to let go, in dB (0..40; 6 by default).

Definition at line 186 of file TriggeredEnvelope.h.

◆ setRelease()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setRelease ( T  ms)
inlinenoexcept

Release, full scale to 0, in ms (from a lower value it arrives earlier).

Definition at line 97 of file TriggeredEnvelope.h.

◆ setReleaseWaitMs()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setReleaseWaitMs ( T  ms)
inlinenoexcept

How long the key must stay below that before the release, in ms (>= 0; 50 by default).

Definition at line 194 of file TriggeredEnvelope.h.

◆ setSustain()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setSustain ( T  level)
inlinenoexcept

The sustain level, 0..1 (non-finite ignored). During the decay the rest of the decay bends to it; during the sustain the output moves to it at the decay's pace.

Definition at line 114 of file TriggeredEnvelope.h.

◆ setThresholdDb()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setThresholdDb ( T  db)
inlinenoexcept

Level of the key above which the audio trigger starts the envelope, in dB (non-finite ignored).

Definition at line 178 of file TriggeredEnvelope.h.

◆ setTimes()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setTimes ( T  delayMs,
T  attackMs,
T  holdMs,
T  decayMs,
T  releaseMs 
)
inlinenoexcept

All five times at once, in ms.

Definition at line 100 of file TriggeredEnvelope.h.

◆ setTrigger()

template<FloatType T>
void dspark::TriggeredEnvelope< T >::setTrigger ( Trigger  trigger)
inlinenoexcept

Notes (noteOn()/noteOff()) or the audio of the key signal.

Definition at line 174 of file TriggeredEnvelope.h.


The documentation for this class was generated from the following file: