UNPKG

@trackr/effects-gain

Version:

A subpackage of trackr that contains gain effects.

24 lines (23 loc) 789 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.envelope = void 0; exports.envelope = (options) => { return (audioContext, eo) => { const adsr = audioContext.createGain(); if (options) { const t0 = eo.startTime; // vol:0 adsr.gain.setValueAtTime(0, t0); // attack const t1 = t0 + options.attack; adsr.gain.linearRampToValueAtTime(1, t1); // decay const t2 = options.decay; adsr.gain.setTargetAtTime(options.sustainLevel, t1, t2); // release adsr.gain.setTargetAtTime(0, t1 + t2, options.release); } eo.latestSource.connect(adsr); return adsr; }; };