Skip to content

Envelope & panning

Envelope

Each synthesizer comes with a default basic ADSR envelope that has zero attack and decay, a full volume sustain, and zero release. This is defined like so:

gml
synth = synth_create();

// How long a note takes to "fade in" to full volume
var _attack = 0;

// How long it takes to go from full volume after the attack to the sustain level
var _decay = 0;

// How loud the volume should be when a note is held after the attack and decay
var _sustain = 1;

// How long the note takes to fade out
var _release = 0;

// Apply the envelope
synth_amp_envelope_adsr(synth, _attack, _decay, _sustain, _release);

Attack, decay, and release are all given in terms of seconds (with a minimum of 0 meaning instant). Sustain is given as a value between 0 and 1, where 1 is full volume and 0 is silence.

Note that volume of a synthesizer is affected by many things, not just the envelope. For example, SynthEngine will play notes slightly quieter for higher polyphony counts, so that when full polyphony is achieved (all allowed notes are played at once) the volume doesn't get so loud that it becomes distorted. Each individual note can have it's own amp value applied as well which affects it's volume.

Panning

You can control the global panning of your synth if it supports stereo (which is the default, see Creating a synthesizer). This is done with synth_set_panning():

gml
synth = synth_create();

// Pan the synth evenly in the middle (default)
synth_set_panning(synth, 0);

// Pan the synth all the way to the left
synth_set_panning(synth, -1);

// Pan the synth all the way to the right
synth_set_panning(synth, 1);

Panning can also be affected by LFOs, see the section