Last active
August 1, 2018 05:18
-
-
Save hkitago/7c2eb11f22922b2f57d2657b32940f35 to your computer and use it in GitHub Desktop.
making beep 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
const audioCtx = new(window.AudioContext || window.webkitAudioContext)(); | |
const beep = function(){ | |
if(settings.beep === 1) { | |
return false; | |
} | |
const volume = 0.1 | |
, duration = 200 | |
, type = 'square' | |
, frequency = 2000 /*1000*/; | |
const oscillator = audioCtx.createOscillator(); | |
const gainNode = audioCtx.createGain(); | |
oscillator.connect(gainNode); | |
gainNode.connect(audioCtx.destination); | |
gainNode.gain.value = volume; | |
oscillator.frequency.value = frequency; | |
oscillator.type = type; | |
oscillator.start(); | |
setTimeout(function() { | |
oscillator.stop(); | |
}, duration); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment