Class thl::dsp::utils::ADSR#

class ADSR#

ADSR envelope generator class.

This class implements a classic ADSR (Attack, Decay, Sustain, Release) envelope for audio signal processing. It can be used to shape the amplitude of audio signals over time, particularly useful for synthesizers and granular processing.

Public Types

enum class State#

ADSR envelope state.

Values:

enumerator IDLE#
enumerator ATTACK#
enumerator DECAY#
enumerator SUSTAIN#
enumerator RELEASE#

Public Functions

ADSR()#
void set_parameters(float attack_time, float decay_time, float sustain_level, float release_time)#

Set all ADSR parameters at once.

Parameters:
  • attack_time – Attack time in milliseconds

  • decay_time – Decay time in milliseconds

  • sustain_level – Sustain level (0.0-1.0)

  • release_time – Release time in milliseconds

void set_parameters(float attack_time, float decay_time, float sustain_level, float release_time, float attack_curve, float decay_curve, float release_curve)#

Set all ADSR parameters including curve shapes at once.

Parameters:
  • attack_time – Attack time in milliseconds

  • decay_time – Decay time in milliseconds

  • sustain_level – Sustain level (0.0-1.0)

  • release_time – Release time in milliseconds

  • attack_curve – Attack curve blend (0.0 = linear, 1.0 = exponential)

  • decay_curve – Decay curve blend (0.0 = linear, 1.0 = exponential)

  • release_curve – Release curve blend (0.0 = linear, 1.0 = exponential)

void set_attack(float time_ms)#

Set attack time.

Parameters:

time_ms – Attack time in milliseconds

void set_decay(float time_ms)#

Set decay time.

Parameters:

time_ms – Decay time in milliseconds

void set_sustain(float level)#

Set sustain level.

Parameters:

level – Sustain level (0.0-1.0)

void set_release(float time_ms)#

Set release time.

Parameters:

time_ms – Release time in milliseconds

void set_sample_rate(float sample_rate)#

Set sample rate for timing calculations.

Parameters:

sample_rate – The sample rate in Hz

void note_on()#

Start the envelope.

void note_off()#

End the envelope (begin release phase)

void reset()#

Reset the envelope to IDLE state.

float process()#

Process a single sample and return the envelope value.

Returns:

The current envelope amplitude (0.0-1.0)

bool is_active() const#

Check if the envelope is active.

Returns:

True if the envelope is in any stage except IDLE

State get_state() const#

Get the current state of the envelope.

Returns:

The current state (IDLE, ATTACK, DECAY, SUSTAIN, RELEASE)

inline float get_current_level() const#

Get the current envelope level without advancing the state.

void set_attack_curve(float curve_blend)#

Set the attack curve shape.

Parameters:

curve_blend – Blend factor between linear (0.0) and exponential (1.0)

void set_decay_curve(float curve_blend)#

Set the decay curve shape.

Parameters:

curve_blend – Blend factor between linear (0.0) and exponential (1.0)

void set_release_curve(float curve_blend)#

Set the release curve shape.

Parameters:

curve_blend – Blend factor between linear (0.0) and exponential (1.0)

void set_curves(float attack_curve, float decay_curve, float release_curve)#

Set all curve shapes at once.

Parameters:
  • attack_curve – Attack curve blend (0.0 = linear, 1.0 = exponential)

  • decay_curve – Decay curve blend (0.0 = linear, 1.0 = exponential)

  • release_curve – Release curve blend (0.0 = linear, 1.0 = exponential)