fix: getExpEnvelope full adsr
This commit is contained in:
parent
7cf7ebc555
commit
6bcf8b91cc
2 changed files with 5 additions and 4 deletions
|
|
@ -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();
|
const gainNode = getAudioContext().createGain();
|
||||||
gainNode.gain.setValueAtTime(0.0001, begin);
|
gainNode.gain.setValueAtTime(0.0001, begin);
|
||||||
gainNode.gain.exponentialRampToValueAtTime(velocity, begin + attack);
|
gainNode.gain.exponentialRampToValueAtTime(velocity, begin + attack);
|
||||||
gainNode.gain.exponentialRampToValueAtTime(0.0001, begin + attack + decay);
|
gainNode.gain.exponentialRampToValueAtTime(sustain * velocity, begin + attack + decay);
|
||||||
return {
|
return {
|
||||||
node: gainNode,
|
node: gainNode,
|
||||||
stop: (t) => {
|
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);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ export function registerSynthSounds() {
|
||||||
fmVelocity = fmVelocity ?? 1;
|
fmVelocity = fmVelocity ?? 1;
|
||||||
fmEnvelope = getEnvelope(fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity, t);
|
fmEnvelope = getEnvelope(fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity, t);
|
||||||
if (fmEnvelopeType === 'exp') {
|
if (fmEnvelopeType === 'exp') {
|
||||||
fmEnvelope = getExpEnvelope(fmAttack, fmDecay, fmVelocity, t);
|
fmEnvelope = getExpEnvelope(fmAttack, fmDecay, fmSustain, fmRelease, fmVelocity, t);
|
||||||
fmEnvelope.node.maxValue = fmModulationIndex * 2;
|
fmEnvelope.node.maxValue = fmModulationIndex * 2;
|
||||||
fmEnvelope.node.minValue = 0.00001;
|
fmEnvelope.node.minValue = 0.00001;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue