Envelope 101 - updating the freq PROBMEM
by Ehsan Ziya
HTML
<input type="button" value="On" id="button">
JavaScript
$(document).ready(function(){
var context = new webkitAudioContext();
var osc = context.createOscillator();
var gain = context.createGain();
osc.frequency.value = 500;
osc.connect(gain);
gain.connect(context.destination);
osc.start(0);
gain.gain.value = 0;
var oscStart = function(freq){
var now = context.currentTime;
gain.gain.cancelScheduledValues( now );
gain.gain.setValueAtTime(gain.gain.value, now);
gain.gain.linearRampToValueAtTime(1 , now + 0.2);
osc.frequency.value = freq;
};
var oscOff = function(){
var now = context.currentTime;
gain.gain.cancelScheduledValues( now );
gain.gain.setValueAtTime(gain.gain.value, now);
gain.gain.linearRampToValueAtTime(0 , now + 0.2);
};
});