Class fx_adsr_envelope

Inheritance Relationships

Base Type

Class Documentation

class fx_adsr_envelope : public fx_effect

Effect: Envelope generator.

An envelope generator creates a volume envelope that can applied to either the audio from the instrument or an oscillator. The volume envelope has four components: (A)ttack, (D)ecay, (S)ustain, (R)elease. These parameters can be adjusted to make short tight notes or long swells.

Here’s more information about how these work: https://en.wikipedia.org/wiki/Envelope_(music)

The ADSR envelope is triggered / kicked-off with an event. This is typically a new note event from the pedal.

#include <dreammakerfx.h>

// Add your fx module declarations here
fx_adsr_envelope  env(250.0,  // Attack is 250ms
                      10.0,   // Decay is 10ms
                      10.0,   // Sustain is 10ms
                      500.0,  // Release is 500ms 
                      1.0,    // Sustain ratio
                      1.0,    // Full volume
                      true);  // Enable look-ahead buffer to suppress initial plucks

void setup() {
  // put your setup code here, to run once:

  // Initialize the pedal!
  pedal.init(MSG_INFO, true);

  // Route audio through effects from pedal.instr_in to pedal.amp_out
  pedal.route_audio(pedal.instr_in, env.input);
  pedal.route_audio(env.output, pedal.amp_out);  

  // IMPORTANT!  route the new note event from the pedal to the start node of the ADSR
  pedal.route_control(pedal.new_note, env.start);

  // left footswitch is bypass
  pedal.add_bypass_button(FOOTSWITCH_LEFT);

  // Run this effect
  pedal.run();

}

Public Functions

fx_adsr_envelope(float attack_ms, float decay_ms, float sustain_ms, float release_ms, float sustain_ratio, float gain_out, bool look_ahead)

constructor/initializer for the ADSR envelope

// Add your fx module declarations here
 fx_adsr_envelope  env(250.0,  // Attack is 250ms
                       10.0,   // Decay is 10ms
                       10.0,   // Sustain is 10ms
                       500.0,  // Release is 500ms 
                       1.0,    // Sustain ratio
                       1.0,    // Full volume
                       true);  // Enable look-ahead buffer 

Parameters
  • [in] attack_ms: The attack in milliseconds

  • [in] decay_ms: The decay in milliseconds

  • [in] sustain_ms: The sustain in milliseconds

  • [in] release_ms: The release in milliseconds

  • [in] sustain_ratio: Ratio of sustain volume to peak volume between attack / decay

  • [in] gain_out: The gain out (linear: 0.0 to 1.0)

  • [in] look_ahead: When set to true, a small look-ahead buffer is used such that the initial impulse of a plucked note is suppressed

void enable()

Enable the this_effect (it is enabled by default)

void bypass()

Bypass the this_effect (will just pass clean audio through)

void set_attack_ms(float attack)

Sets the attack time in milliseconds.

Parameters
  • [in] attack: The attack time in milliseconds

void set_decay_ms(float decay)

Sets the decay time in milliseconds.

Parameters
  • [in] decay: The decay time in milliseconds

void set_sustain_ms(float sustain)

Sets the release time in milliseconds.

Parameters
  • [in] sustain: The sustain time in milliseconds

void set_release_ms(float release)
void set_output_gain(float gain)

Sets the output gain (linear)

Parameters
  • [in] gain: The gain value (linear)

Public Members

fx_audio_node *input

Audio routing node: primary audio input

fx_audio_node *output

Audio routing node: primary audio output

fx_control_node *attack_ms

Control routing node [input]: envelope attack in milliseconds

fx_control_node *decay_ms

Control routing node [input]: envelope decay in milliseconds

fx_control_node *sustain_ms

Control routing node [input]: envelope sustain in milliseconds

fx_control_node *release_ms

Control routing node [input]: envelope release in milliseconds

fx_control_node *peak_ratio

Control routing node [input]: relative volume after attack (0.0 to 1.0) - will be scaled by output volume

fx_control_node *sustain_ratio

Control routing node [input]: relative volume during sustain (0.0 to 1.0) - will be scaled by output volume

fx_control_node *gain_out

Control routing node [input]: output pain

fx_control_node *start

Control routing node [input]: start - start a new ADSR envelope run

fx_control_node *value

Control routing node [output]: value of the envelope