fix: getExpEnvelope full adsr

This commit is contained in:
Felix Roos 2023-08-31 04:22:54 +02:00
parent 7cf7ebc555
commit 6bcf8b91cc
2 changed files with 5 additions and 4 deletions

View File

@ -39,15 +39,16 @@ export const getEnvelope = (attack, decay, sustain, release, velocity, begin) =>
};
};
export const getExpEnvelope = (attack, decay, velocity, begin) => {
export const getExpEnvelope = (attack, decay, sustain, release, velocity, begin) => {
const gainNode = getAudioContext().createGain();
gainNode.gain.setValueAtTime(0.0001, begin);
gainNode.gain.exponentialRampToValueAtTime(velocity, begin + attack);
gainNode.gain.exponentialRampToValueAtTime(0.0001, begin + attack + decay);
gainNode.gain.exponentialRampToValueAtTime(sustain * velocity, begin + attack + decay);
return {
node: gainNode,
stop: (t) => {
gainNode.gain.exponentialRampToValueAtTime(0.0001, t + decay);
// similar to getEnvelope, this will glitch if sustain level has not been reached
gainNode.gain.exponentialRampToValueAtTime(0.0001, t + release);
},
};
};

View File

@ -70,7 +70,7 @@ export function registerSynthSounds() {
fmVelocity = fmVelocity ?? 1;
fmEnvelope = getEnvelope(fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity, t);
if (fmEnvelopeType === 'exp') {
fmEnvelope = getExpEnvelope(fmAttack, fmDecay, fmVelocity, t);
fmEnvelope = getExpEnvelope(fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity, t);
fmEnvelope.node.maxValue = fmModulationIndex * 2;
fmEnvelope.node.minValue = 0.00001;
}