var context = null; var usingWebAudio = true; if (typeof AudioContext !== 'undefined') { context = new AudioContext(); } else if (typeof webkitAudioContext !== 'undefined') { context = new webkitAudioContext(); } else { usingWebAudio = false; } var playing = false; var osc = null; var freq = 1; var STEP_CONSTANT = Math.pow(2.0, 1.0/12.0); function toggle() { var button = document.getElementById("toggle"); if (playing && osc) { playing = false; osc.stop(0); button.value = "Play"; } else { playing = true; osc = context.createOscillator(); osc.connect(context.destination); osc.frequency.value = freq; osc.start(0); button.value = "Stop"; } } function updateFreq(newFreq) { freq = newFreq; if (osc) { osc.frequency.value = freq; } var text = document.getElementById("freqText").value = freq; var range = document.getElementById("freqRange").value = freq; } window.onload = function() { if (!usingWebAudio) { document.getElementById("audioControls").innerHTML = "

Web audio required.

" } }