Webaudio test (new)
by jmchen
JavaScript
function Sound (frequency, type) {
this.osc = audioCtx.createOscillator();
this.pressed = false;
if (typeof frequency != 'undefined') {
this.osc.frequency.value = frequency;
// default 440Hz ?!
}
this.osc.type = type || 'triangle';
this.osc.start (0); // not yet connected
};
Sound.prototype.play = function () {
if (! this.pressed) {
this.pressed = true;
this.osc.connect (audioCtx.destination);
}
};
Sound.prototype.stop = function() {
this.pressed = false;
this.osc.disconnect();
};
var audioCtx = new AudioContext();
var a4 = new Sound (440, 'triangle');
debugger;
//a4.play();