adding linear and exponential envelope for fm synthesis

This commit is contained in:
Raphael Forment 2023-08-29 17:25:27 +02:00
parent c87c3c6672
commit c3cd5d08c9
2 changed files with 44 additions and 14 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);