Created
June 14, 2013 06:44
-
-
Save srikumarks/5779926 to your computer and use it in GitHub Desktop.
Simple Ping using Web Audio API
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 audioContext = new AudioContext(); | |
var kFreq = 660, kDecayTime = 0.5, kStartTime = 1.5, kGain = 0.25; | |
var oscNode = audioContext.createOscillator(); | |
oscNode.frequency.value = kFreq; | |
var gainNode = audioContext.createGain(); | |
gainNode.gain.value = kGain; | |
gainNode.gain.setTargetAtTime(0.0, audioContext.currentTime, kDecayTime); | |
oscNode.connect(gainNode); | |
gainNode.connect(audioContext.destination); | |
oscNode.start(audioContext.currentTime + kStartTime); // Start a little into the future. | |
oscNode.stop(audioContext.currentTime + kStartTime + 12 * kDecayTime); // Stop when the sound decays by enough. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment