Skip to content

Instantly share code, notes, and snippets.

@kalibora
Created July 27, 2015 12:27
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/fb152e4406f89f1a02ba to your computer and use it in GitHub Desktop.
Save kalibora/fb152e4406f89f1a02ba to your computer and use it in GitHub Desktop.
audio-test-4
var ctx = new AudioContext();
var osc = ctx.createOscillator();
var gain = ctx.createGain();
var levels = [1.0, 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1];
var levelIdx = 0;
var timerId = setInterval(function () {
if (levelIdx >= levels.length) {
clearInterval(timerId);
return;
}
console.log(levels[levelIdx]);
gain.gain.value = levels[levelIdx]; // set gain
if (levelIdx === 0) {
osc.start(0);
osc.stop(ctx.currentTime + levels.length * 0.5);
}
levelIdx++;
}, 500);
osc.connect(gain);
gain.connect(ctx.destination);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment