OscillatorNode#start on Firefox
HTML
<pre>
Firefox は destination に接続していなくても動作する.
以下の例だと noweherprocess で生成したオシレーターは
接続していないのに動作するため
しばらくすると処理過多で動作しなくなる.
</pre>
<button id="start">start</button>
<div id="report"></div>
CSS
pre { font-size: 12px }
JavaScript
var audioContext = new AudioContext();
var $report = document.getElementById("report");
var timerId = 0;
var osc = null;
var counter = 0;
function start() {
timerId = setInterval(noweherprocess, 50);
}
function stop() {
clearInterval(timerId);
}
function noweherprocess() {
osc = audioContext.createOscillator();
osc.frequency.value=200+(counter*10)%200;
osc.start(audioContext.currentTime);
counter += 1;
$report.textContent = counter;
}
var isPlaying = false;
document.getElementById("start").onclick = function(e) {
isPlaying = !isPlaying;
if (isPlaying) {
start();
e.target.textContent = "stop";
} else {
stop();
e.target.textContent = "start";
}
};