Created
January 3, 2019 16:00
-
-
Save vabarbosa/a03e34edfb051e4486e00692d6a683c7 to your computer and use it in GitHub Desktop.
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
// 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