From 014c258c57439f24bfa4936737441142e3bf7199 Mon Sep 17 00:00:00 2001 From: Felix Roos Date: Thu, 22 Sep 2022 15:33:06 +0200 Subject: [PATCH] sample adsr support --- packages/webaudio/webaudio.mjs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/packages/webaudio/webaudio.mjs b/packages/webaudio/webaudio.mjs index 17563bba..d02a5928 100644 --- a/packages/webaudio/webaudio.mjs +++ b/packages/webaudio/webaudio.mjs @@ -181,10 +181,10 @@ Pattern.prototype.out = function () { crush, shape, pan, - attack = 0.001, - decay = 0.05, - sustain = 0.5, - release = 0.001, + attack = 0.0001, + decay = 0.0001, + sustain = 1, + release = 0.0001, speed = 1, // sample playback speed begin = 0, end = 1, @@ -284,18 +284,9 @@ Pattern.prototype.out = function () { cutGroups[cut] = bufferSource; } chain.push(bufferSource); - if (soundfont || clip) { - const env = ac.createGain(); - const releaseLength = 0.1; - env.gain.value = 0.6; - env.gain.setValueAtTime(env.gain.value, t + duration); - env.gain.linearRampToValueAtTime(0, t + duration + releaseLength); - // env.gain.linearRampToValueAtTime(0, t + duration + releaseLength); - chain.push(env); - bufferSource.stop(t + duration + releaseLength); - } else { - bufferSource.stop(t + duration); - } + bufferSource.stop(t + duration + release); + const adsr = getADSR(attack, decay, sustain, release, 1, t, t + duration); + chain.push(adsr); } // master out const master = ac.createGain();