Last active
November 12, 2022 17:59
-
-
Save kistaaa/b093f30dccbea70c76438e844f84cfed to your computer and use it in GitHub Desktop.
Fix Web Audio "click" sound
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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