envelopes on fmsynth

This commit is contained in:
Raphael Forment 2023-08-29 13:46:43 +02:00
parent 94bcfb11de
commit 8fc7688585
2 changed files with 58 additions and 7 deletions

View file

@ -39,6 +39,19 @@ export const getEnvelope = (attack, decay, sustain, release, velocity, begin) =>
};
};
export const getExpEnvelope = (attack, decay, 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);
return {
node: gainNode,
stop: (t) => {
gainNode.gain.exponentialRampToValueAtTime(0.0001, t + decay);
},
};
};
export const getADSR = (attack, decay, sustain, release, velocity, begin, end) => {
const gainNode = getAudioContext().createGain();
gainNode.gain.setValueAtTime(0, begin);