revert exponential adsr
This commit is contained in:
parent
d3645f6c63
commit
8977c5cef4
1 changed files with 8 additions and 2 deletions
|
|
@ -33,7 +33,13 @@ const getFilter = (type, frequency, Q) => {
|
||||||
|
|
||||||
const getADSR = (attack, decay, sustain, release, velocity, begin, end) => {
|
const getADSR = (attack, decay, sustain, release, velocity, begin, end) => {
|
||||||
const gainNode = getAudioContext().createGain();
|
const gainNode = getAudioContext().createGain();
|
||||||
let t = begin;
|
gainNode.gain.setValueAtTime(0, begin);
|
||||||
|
gainNode.gain.linearRampToValueAtTime(velocity, begin + attack); // attack
|
||||||
|
gainNode.gain.linearRampToValueAtTime(sustain * velocity, begin + attack + decay); // sustain start
|
||||||
|
gainNode.gain.setValueAtTime(sustain * velocity, end); // sustain end
|
||||||
|
gainNode.gain.linearRampToValueAtTime(0, end + release); // release
|
||||||
|
// for some reason, using exponential ramping creates little cracklings
|
||||||
|
/* let t = begin;
|
||||||
gainNode.gain.setValueAtTime(0, t);
|
gainNode.gain.setValueAtTime(0, t);
|
||||||
gainNode.gain.exponentialRampToValueAtTime(velocity, (t += attack));
|
gainNode.gain.exponentialRampToValueAtTime(velocity, (t += attack));
|
||||||
const sustainGain = Math.max(sustain * velocity, 0.001);
|
const sustainGain = Math.max(sustain * velocity, 0.001);
|
||||||
|
|
@ -43,7 +49,7 @@ const getADSR = (attack, decay, sustain, release, velocity, begin, end) => {
|
||||||
} else {
|
} else {
|
||||||
gainNode.gain.setValueAtTime(sustainGain, end);
|
gainNode.gain.setValueAtTime(sustainGain, end);
|
||||||
}
|
}
|
||||||
gainNode.gain.exponentialRampToValueAtTime(0.001, end + release); // release
|
gainNode.gain.exponentialRampToValueAtTime(0.001, end + release); // release */
|
||||||
return gainNode;
|
return gainNode;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue