fix: envelope in chrome

This commit is contained in:
Felix Roos 2023-03-17 08:56:05 +01:00
parent 18d62b32c2
commit 33d35e47a6
2 changed files with 10 additions and 9 deletions

View File

@ -27,12 +27,13 @@ export const getEnvelope = (attack, decay, sustain, release, velocity, begin) =>
return { return {
node: gainNode, node: gainNode,
stop: (t) => { stop: (t) => {
if (typeof gainNode.gain.cancelAndHoldAtTime === 'function') { //if (typeof gainNode.gain.cancelAndHoldAtTime === 'function') {
gainNode.gain.cancelAndHoldAtTime(t); // gainNode.gain.cancelAndHoldAtTime(t); // this seems to release instantly....
} else { // see https://discord.com/channels/779427371270275082/937365093082079272/1086053607360712735
// firefox: this will glitch when the sustain has not been reached yet at the time of release //} else {
gainNode.gain.setValueAtTime(sustain * velocity, t); // firefox: this will glitch when the sustain has not been reached yet at the time of release
} gainNode.gain.setValueAtTime(sustain * velocity, t);
//}
gainNode.gain.linearRampToValueAtTime(0, t + release); gainNode.gain.linearRampToValueAtTime(0, t + release);
}, },
}; };

View File

@ -32,9 +32,9 @@ export function registerSynthSounds() {
}; };
return { return {
node: o.connect(g).connect(envelope), node: o.connect(g).connect(envelope),
stop: (t) => { stop: (releaseTime) => {
releaseEnvelope(t); releaseEnvelope(releaseTime);
stop(t + release); stop(releaseTime + release);
}, },
}; };
}, },