Skip to content

Instantly share code, notes, and snippets.

@kistaaa
Last active November 12, 2022 17:59
Show Gist options
  • Save kistaaa/b093f30dccbea70c76438e844f84cfed to your computer and use it in GitHub Desktop.
Save kistaaa/b093f30dccbea70c76438e844f84cfed to your computer and use it in GitHub Desktop.
Fix Web Audio "click" sound
var context = new AudioContext();
var oscillator = context.createOscillator();
var gainNode = context.createGain();
oscillator.connect(gainNode);
gainNode.connect(context.destination)
oscillator.start();
stopButton.addEventListener('click', function() {
// Important! Setting a scheduled parameter value
gainNode.gain.setValueAtTime(gainNode.gain.value, context.currentTime);
gainNode.gain.exponentialRampToValueAtTime(0.0001, context.currentTime + 0.03);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment