Oscillator
by Aqilah Misuary
HTML
</script>
</head>
<body>
<p>Oscillator</p>
<button onclick="play()">Play</button>
<button onclick="stop()">Stop</button>
</body>
</html>
JavaScript
var context = new AudioContext();
var oscillator = context.createOscillator();
oscillator.type = 'sine';
oscillator.start(0);
var gain = context.createGain();
gain.gain.value = 0;
getSample('https://dl.dropboxusercontent.com/u/30075450/Greek%207%20Echo%20Hall.wav', function(impulse){
var convolver = context.createConvolver()
var buffer = context.createBufferSource()
convolver.buffer = impulse
/* Connections */
oscillator.connect(gain);
gain.connect(convolver);
convolver.connect(context.destination);
});
function getSample(url, cb) {
var request = new XMLHttpRequest()
request.open('GET', url)
request.responseType = 'arraybuffer'
request.onload = function() {
context.decodeAudioData(request.response, cb)
}
request.send()
}
function play() {
oscillator.frequency.value = 200;
gain.gain.value = 1;
}
function stop() {
gain.gain.value = 0;
}