SYNTH
by Ehsan Ziya
HTML
<script src="http://cdn.jsdelivr.net/keyboardjs/0.4.0/keyboard.js"></script>
JavaScript
$(document).ready(function(){
var context = new webkitAudioContext();
var mastergain = context.createGain();
mastergain.gain.value = 1;
mastergain.connect(context.destination);
function osc(destination){
this.destination = destination;
this.oscillator = context.createOscillator();
this.gain = context.createGain();
this.gain.gain.value = 0;
this.oscillator.type = "sine";
this.oscillator.frequency.value = 300;
this.oscillator.start(0);
this.oscillator.connect(this.gain);
this.gain.connect(destination);
that = this;
this.start = function(frequency){
var now = context.currentTime;
this.oscillator.frequency.value = frequency;
this.gain.gain.cancelScheduledValues( now );
this.gain.gain.setValueAtTime ( this.gain.gain.value , now );
this.gain.gain.linearRampToValueAtTime ( 1 , now + 0.5 );
};
}
var testing = new osc(mastergain);
//KeyboardJS.on( 'a', testing.start(300) )
});