= t0 + attack; var t3 = t0 + duration - release; var envelope = audioContext.createGain(); oscillator.connect(envelope); envelope.connect(audioContext.destination); oscillator.start(t0); envelope.gain.setValueAtTime(0, t0); envelope.gain.linearRampToValueAtTime(1.0, t1); envelope.gain.setTargetAtTime(sustain, t1, decay); envelope.gain.setTargetAtTime(0, t3, release); oscillator.stop(t0 + duration);