Skip to content

Instantly share code, notes, and snippets.

@vabarbosa
Created January 3, 2019 16:00
Show Gist options
  • Save vabarbosa/a03e34edfb051e4486e00692d6a683c7 to your computer and use it in GitHub Desktop.
Save vabarbosa/a03e34edfb051e4486e00692d6a683c7 to your computer and use it in GitHub Desktop.
// instantiate audio context
let audioCtx = new (window.AudioContext || window.webkitAudioContext)()
// create gain node (volume)
let gainNode = audioCtx.createGain()
// create oscillator
let oscillator = audioCtx.createOscillator()
// connect audio nodes
oscillator.connect(gainNode)
gainNode.connect(audioCtx.destination)
// set frequency
oscillator.frequency.setValueAtTime(440, audioCtx.currentTime)
// set volume
gainNode.gain.setValueAtTime(0.5, audioCtx.currentTime)
oscillator.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment