Synthlet
Audio Modifiers
npm package

ADSR Amplifier

A Voltage Controlled Amplifier module

A Voltage Controlled Amplifier (VCA) module with an Attack-Decay-Sustain-Release (ADSR) envelope

Use it to add an envelope to the synth voices.

import { AdsrAmp, OscillatorNode } from "synthlet";
 
const osc = new OscillatorNode(audioContext, {
  frequency: 440,
});
const vca = AdsrAmp(audioContext, {
  gain: 0.5,
  attack: 0.1,
  decay: 0.1,
  sustain: 0.5,
  release: 0.1,
});
// Connect the oscillator to the VCA and to the output
osc.connect(vca).connect(audioContext.destination);
// Start the envelope (start attack phase)
vca.gate.value = 1;
// Stop the envelope (start release phase)
vca.gate.value = 0;

Parameters

Same as adsr:

  • attack: The attack time in seconds. Default is 0.1.
  • decay: The decay time in seconds. Default is 0.1.
  • sustain: The sustain level. Default is 0.5.
  • release: The release time in seconds. Default is 0.1.
  • offset: The start offset. Default is 0.
  • gain: The gain. Default is 1. It is the maximum amplitude after the attach and affects the sustain level. For example, a gain of 100 and sustain of 0.5 will make the sustain level to be 50.

Offset is silence

The ADSR will output offset value when the gate is closed. If you want to silence the output, set the offset to 0.

On this page