Created
January 29, 2015 01:14
-
-
Save internetbird/795ba2489841f3c926a0 to your computer and use it in GitHub Desktop.
AudioAPI sample which play 2 notes (C & A) together
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
<script> | |
var audioContext = new AudioContext(); | |
var osc = audioContext.createOscillator(); | |
var osc2 = audioContext.createOscillator(); | |
var gainOsc = audioContext.createGain(); | |
var gainOsc2 = audioContext.createGain(); | |
var gainMix = audioContext.createGain(); | |
gainOsc.gain.value = 0.1; | |
gainOsc2.gain.value = 0.1; | |
gainMix.gain.value = 0.1; | |
osc.type="sawtooth"; | |
osc.frequency.value = 440; //A | |
osc2.frequency.value = 261.626 //C | |
osc.connect(gainOsc); | |
osc2.connect(gainOsc2) | |
gainOsc.connect(gainMix); | |
gainOsc2.connect(gainMix); | |
gainMix.connect(audioContext.destination); | |
osc.start(audioContext.currentTime); | |
osc2.start(audioContext.currentTime); | |
setTimeout(function(){ | |
osc.stop(); | |
osc2.stop(); | |
}, 2000); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment