Compare commits

...

1 Commits

Author SHA1 Message Date
Felix Roos e1724158a7 add small fade out to cut groups 2022-11-06 00:31:24 +01:00
+18 -5
View File
@@ -189,7 +189,8 @@ function gainNode(value) {
node.gain.value = value; node.gain.value = value;
return node; return node;
} }
const cutGroups = []; const cutGroupSources = [];
const cutGroupEnvelopes = [];
let delays = {}; let delays = {};
function getDelay(orbit, delaytime, delayfeedback, t) { function getDelay(orbit, delaytime, delayfeedback, t) {
@@ -368,14 +369,26 @@ export const webaudioOutput = async (hap, deadline, hapDuration) => {
t += nudge; t += nudge;
bufferSource.start(t, offset); bufferSource.start(t, offset);
if (cut !== undefined) {
cutGroups[cut]?.stop(t); // fade out?
cutGroups[cut] = bufferSource;
}
chain.push(bufferSource); chain.push(bufferSource);
bufferSource.stop(t + duration + release); bufferSource.stop(t + duration + release);
const adsr = getADSR(attack, decay, sustain, release, 1, t, t + duration); const adsr = getADSR(attack, decay, sustain, release, 1, t, t + duration);
chain.push(adsr); chain.push(adsr);
if (cut !== undefined) {
const cutSource = cutGroupSources[cut];
const cutEnvelope = cutGroupEnvelopes[cut];
const fadeTime = 0.001;
if (cutEnvelope) {
// cutEnvelope.gain.cancelAndHoldAtTime(t);
cutEnvelope.gain.cancelScheduledValues(t);
cutEnvelope.gain.linearRampToValueAtTime(0, t + fadeTime);
// cutEnvelope.gain.exponentialRampToValueAtTime(0.0001, t + fadeTime);
}
if (cutSource) {
cutSource.stop(t + fadeTime);
}
cutGroupSources[cut] = bufferSource;
cutGroupEnvelopes[cut] = adsr;
}
} }
// gain stage // gain stage