Skip to content

Instantly share code, notes, and snippets.

@odino
Created June 15, 2018 04:09
Show Gist options
  • Save odino/017d6e21a8d7ce35c3aa8a4a4798e2be to your computer and use it in GitHub Desktop.
Save odino/017d6e21a8d7ce35c3aa8a4a4798e2be to your computer and use it in GitHub Desktop.
a=new AudioContext() // browsers limit the number of concurrent audio contexts, so you better re-use'em
function beep(vol, freq, duration){
v=a.createOscillator()
u=a.createGain()
v.connect(u)
v.frequency.value=freq
v.type="square"
u.connect(a.destination)
u.gain.value=vol*0.01
v.start(a.currentTime)
v.stop(a.currentTime+duration*0.001)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment