-
-
Save kalibora/fb152e4406f89f1a02ba to your computer and use it in GitHub Desktop.
audio-test-4
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
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