Skip to content

Instantly share code, notes, and snippets.

@internetbird
Created January 29, 2015 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save internetbird/795ba2489841f3c926a0 to your computer and use it in GitHub Desktop.
Save internetbird/795ba2489841f3c926a0 to your computer and use it in GitHub Desktop.
AudioAPI sample which play 2 notes (C & A) together
<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