iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | List of all members
ADSREnvelope< T > Class Template Reference

Public Types

enum  EStage {
  kReleasedToEndEarly = -3 , kReleasedToRetrigger = -2 , kIdle = -1 , kAttack ,
  kDecay , kSustain , kRelease
}
 

Public Member Functions

 ADSREnvelope (const char *name="", std::function< void()> resetFunc=nullptr, bool sustainEnabled=true)
 Constructs an ADSREnvelope object. More...
 
void SetStageTime (int stage, T timeMS)
 Sets the time for a particular envelope stage. More...
 
bool GetBusy () const
 
bool GetReleased () const
 
GetPrevOutput () const
 
void Start (T level, T timeScalar=1.)
 Trigger/Start the envelope. More...
 
void Release ()
 Release the envelope. More...
 
void Retrigger (T newStartLevel, T timeScalar=1.)
 Retrigger the envelope. More...
 
void Kill (bool hard)
 Kill the envelope. More...
 
void SetSampleRate (T sr)
 Set the sample rate for processing, with updates the early release time and retrigger release time coefficents. More...
 
void SetResetFunc (std::function< void()> func)
 Sets a function to call when the envelope gets retriggered, called when the fade out ramp is at zero, useful for example to reset an oscillator's phase WARNING: don't call this on the audio thread, std::function can malloc. More...
 
void SetEndReleaseFunc (std::function< void()> func)
 Sets a function to call when the envelope gets released, called when the ramp is at zero WARNING: don't call this on the audio thread, std::function can malloc. More...
 
Process (T sustainLevel=0.)
 Process the envelope, returning the value according to the current envelope stage. More...
 

Static Public Attributes

static constexpr T EARLY_RELEASE_TIME = 20.
 
static constexpr T RETRIGGER_RELEASE_TIME = 3.
 
static constexpr T MIN_ENV_TIME_MS = 0.022675736961451
 
static constexpr T MAX_ENV_TIME_MS = 60000.
 
static constexpr T ENV_VALUE_LOW = 0.000001
 
static constexpr T ENV_VALUE_HIGH = 0.999
 

Detailed Description

template<typename T>
class ADSREnvelope< T >

Definition at line 22 of file ADSREnvelope.h.

Member Enumeration Documentation

◆ EStage

template<typename T >
enum ADSREnvelope::EStage

Definition at line 25 of file ADSREnvelope.h.

Constructor & Destructor Documentation

◆ ADSREnvelope()

template<typename T >
ADSREnvelope< T >::ADSREnvelope ( const char *  name = "",
std::function< void()>  resetFunc = nullptr,
bool  sustainEnabled = true 
)
inline

Constructs an ADSREnvelope object.

Parameters
nameCString to identify the envelope in debug mode, when DEBUG_ENV=1 is set as a global preprocessor macro
resetFuncA function to call when the envelope gets retriggered, called when the fade out ramp is at zero, useful for example to reset an oscillator's phase
sustainEnabledif true the envelope is an ADSR envelope. If false, it's is an AD envelope (suitable for drums).

Definition at line 74 of file ADSREnvelope.h.

References ADSREnvelope< T >::SetSampleRate().

Member Function Documentation

◆ GetBusy()

template<typename T >
bool ADSREnvelope< T >::GetBusy ( ) const
inline
Returns
/c true if the envelope is not idle

Definition at line 105 of file ADSREnvelope.h.

◆ GetPrevOutput()

template<typename T >
T ADSREnvelope< T >::GetPrevOutput ( ) const
inline
Returns
the previously output value

Definition at line 117 of file ADSREnvelope.h.

◆ GetReleased()

template<typename T >
bool ADSREnvelope< T >::GetReleased ( ) const
inline
Returns
/c true if the envelope is released

Definition at line 111 of file ADSREnvelope.h.

◆ Kill()

template<typename T >
void ADSREnvelope< T >::Kill ( bool  hard)
inline

Kill the envelope.

Parameters
hardIf true, the envelope will get reset automatically, probably causing an audible glitch. If false, it's a "soft kill", which will fade out in EARLY_RELEASE_TIME

Definition at line 162 of file ADSREnvelope.h.

◆ Process()

template<typename T >
T ADSREnvelope< T >::Process ( sustainLevel = 0.)
inline

Process the envelope, returning the value according to the current envelope stage.

Parameters
sustainLevelSince the sustain level could be changed during processing, it is supplied as an argument, so that it can be smoothed extenally if nessecary, to avoid discontinuities

Definition at line 214 of file ADSREnvelope.h.

References ADSREnvelope< T >::Release().

◆ Release()

template<typename T >
void ADSREnvelope< T >::Release ( )
inline

Release the envelope.

Definition at line 135 of file ADSREnvelope.h.

Referenced by ADSREnvelope< T >::Process().

◆ Retrigger()

template<typename T >
void ADSREnvelope< T >::Retrigger ( newStartLevel,
timeScalar = 1. 
)
inline

Retrigger the envelope.

This method will cause the envelope to move to a "releasedToRetrigger" stage, which is a fast ramp to zero in RETRIGGER_RELEASE_TIME, used when voices are stolen to avoid clicks.

Parameters
newStartLevelthe overall level when the envelope restarts (usually linked to MIDI velocity)
timeScalarFactor to scale the envelope's rates. Use this, for example to adjust the envelope stage rates based on the key pressed

Definition at line 146 of file ADSREnvelope.h.

◆ SetEndReleaseFunc()

template<typename T >
void ADSREnvelope< T >::SetEndReleaseFunc ( std::function< void()>  func)
inline

Sets a function to call when the envelope gets released, called when the ramp is at zero WARNING: don't call this on the audio thread, std::function can malloc.

Parameters
functhe release function, or nullptr for none

Definition at line 210 of file ADSREnvelope.h.

◆ SetResetFunc()

template<typename T >
void ADSREnvelope< T >::SetResetFunc ( std::function< void()>  func)
inline

Sets a function to call when the envelope gets retriggered, called when the fade out ramp is at zero, useful for example to reset an oscillator's phase WARNING: don't call this on the audio thread, std::function can malloc.

Parameters
functhe reset function, or nullptr for none

Definition at line 205 of file ADSREnvelope.h.

◆ SetSampleRate()

template<typename T >
void ADSREnvelope< T >::SetSampleRate ( sr)
inline

Set the sample rate for processing, with updates the early release time and retrigger release time coefficents.

NOTE: you also need to think about updating the Attack, Decay and Release times when the sample rate changes

Parameters
srSampleRate in samples per second

Definition at line 195 of file ADSREnvelope.h.

Referenced by ADSREnvelope< T >::ADSREnvelope().

◆ SetStageTime()

template<typename T >
void ADSREnvelope< T >::SetStageTime ( int  stage,
timeMS 
)
inline

Sets the time for a particular envelope stage.

Parameters
stageThe stage to set the time for /see EStage
timeMSThe time in milliseconds for that stage

Definition at line 85 of file ADSREnvelope.h.

References Clip().

◆ Start()

template<typename T >
void ADSREnvelope< T >::Start ( level,
timeScalar = 1. 
)
inline

Trigger/Start the envelope.

Parameters
levelThe overall depth of the envelope (usually linked to MIDI velocity)
timeScalarFactor to scale the envelope's rates. Use this, for example to adjust the envelope stage rates based on the key pressed

Definition at line 125 of file ADSREnvelope.h.

Member Data Documentation

◆ EARLY_RELEASE_TIME

template<typename T >
constexpr T ADSREnvelope< T >::EARLY_RELEASE_TIME = 20.
staticconstexpr

Definition at line 36 of file ADSREnvelope.h.

◆ ENV_VALUE_HIGH

template<typename T >
constexpr T ADSREnvelope< T >::ENV_VALUE_HIGH = 0.999
staticconstexpr

Definition at line 41 of file ADSREnvelope.h.

◆ ENV_VALUE_LOW

template<typename T >
constexpr T ADSREnvelope< T >::ENV_VALUE_LOW = 0.000001
staticconstexpr

Definition at line 40 of file ADSREnvelope.h.

◆ MAX_ENV_TIME_MS

template<typename T >
constexpr T ADSREnvelope< T >::MAX_ENV_TIME_MS = 60000.
staticconstexpr

Definition at line 39 of file ADSREnvelope.h.

◆ MIN_ENV_TIME_MS

template<typename T >
constexpr T ADSREnvelope< T >::MIN_ENV_TIME_MS = 0.022675736961451
staticconstexpr

Definition at line 38 of file ADSREnvelope.h.

◆ RETRIGGER_RELEASE_TIME

template<typename T >
constexpr T ADSREnvelope< T >::RETRIGGER_RELEASE_TIME = 3.
staticconstexpr

Definition at line 37 of file ADSREnvelope.h.


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