prevent clicks
This commit is contained in:
parent
3b6e3624be
commit
7691403fd0
1 changed files with 9 additions and 2 deletions
|
|
@ -106,6 +106,7 @@ export function registerSynthSounds() {
|
||||||
const attackhold = 0.02;
|
const attackhold = 0.02;
|
||||||
const noiselvl = 1.2;
|
const noiselvl = 1.2;
|
||||||
const noisedecay = 0.025;
|
const noisedecay = 0.025;
|
||||||
|
const mixGain = 1;
|
||||||
|
|
||||||
const o = ctx.createOscillator();
|
const o = ctx.createOscillator();
|
||||||
o.type = 'triangle';
|
o.type = 'triangle';
|
||||||
|
|
@ -127,7 +128,8 @@ export function registerSynthSounds() {
|
||||||
// tri to sine diode shaper emulation
|
// tri to sine diode shaper emulation
|
||||||
sat.curve = makeDistortionCurve(2);
|
sat.curve = makeDistortionCurve(2);
|
||||||
|
|
||||||
const mix = gainNode(1);
|
const mix = gainNode(mixGain);
|
||||||
|
|
||||||
o.onended = () => {
|
o.onended = () => {
|
||||||
o.disconnect();
|
o.disconnect();
|
||||||
g.disconnect();
|
g.disconnect();
|
||||||
|
|
@ -140,12 +142,17 @@ export function registerSynthSounds() {
|
||||||
|
|
||||||
const node = o.connect(sat).connect(g).connect(mix);
|
const node = o.connect(sat).connect(g).connect(mix);
|
||||||
noise.node.connect(noiseGain).connect(mix);
|
noise.node.connect(noiseGain).connect(mix);
|
||||||
const holdEnd = t + decay;
|
|
||||||
|
|
||||||
|
const holdEnd = t + decay;
|
||||||
let end = holdEnd + 0.01;
|
let end = holdEnd + 0.01;
|
||||||
if (clip != null) {
|
if (clip != null) {
|
||||||
end = Math.min(t + clip * duration, end);
|
end = Math.min(t + clip * duration, end);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// prevent clicking
|
||||||
|
mix.gain.setValueAtTime(mixGain, end - 0.01);
|
||||||
|
mix.gain.linearRampToValueAtTime(0, end);
|
||||||
|
|
||||||
o.stop(end);
|
o.stop(end);
|
||||||
noise.stop(end);
|
noise.stop(end);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue