Skip to content

Instantly share code, notes, and snippets.

@usefulthink
Created March 11, 2013 21:30
Show Gist options
  • Save usefulthink/5137953 to your computer and use it in GitHub Desktop.
Save usefulthink/5137953 to your computer and use it in GitHub Desktop.
simplistic demo for using the audioContext of the webaudio-api
var audioContext = new webkitAudioContext(),
osc1 = audioContext.createOscillator(),
osc2 = audioContext.createOscillator();
osc1.frequency.value = 440; // Hz
osc2.frequency.value = 220; // one octave down
osc1.connect(audioContext.destination);
osc2.connect(audioContext.destination);
osc1.noteOn(0); // zeit in sek. nach start der internen clock des AudioContext (currentTime)
osc1.noteOff(1);
osc2.noteOn(.5);
osc2.noteOff(2);
// noch ein Beispiel für programmierte Verläufe von AudioParams
osc2.frequency.setValueAtTime(220, 1);
osc2.frequency.exponentialRampToValueAtTime(440, 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment