Skip to content

Instantly share code, notes, and snippets.

@kalibora
Created July 27, 2015 12:02
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 kalibora/cd9314833f9574b78353 to your computer and use it in GitHub Desktop.
Save kalibora/cd9314833f9574b78353 to your computer and use it in GitHub Desktop.
audio-test-3
var ctx = new AudioContext();
var osc = ctx.createOscillator();
var freqs = [261.63, 293.67, 329.63, 349.23, 392.00, 440.00, 493.88, 523.23];
var freqIdx = 0;
var timerId = setInterval(function () {
if (freqIdx >= freqs.length) {
clearInterval(timerId);
return;
}
console.log(freqs[freqIdx]);
osc.frequency.value = freqs[freqIdx]; // set frequency
if (freqIdx === 0) {
osc.start(0);
osc.stop(ctx.currentTime + freqs.length * 1);
}
freqIdx++;
}, 1000);
osc.connect(ctx.destination);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment