我创建了一个振荡器,它实际上可以播放单个音符,但同时不支持两个或多个音符...我怎样才能使它复音?
$(window).load(function(){
window.AudioContext = window.AudioContext || window.webkitAudioContext;
ctx = new AudioContext();
$('path').on('touchstart mousedown', function(){
$(this).css('fill','lime');
noteON( $(this).attr('data-noteKEY') );
});
$('path').on('touchend mouseup', function(){
$(this).css('fill','');
noteOFF();
});
function noteON(noteKEY){
osc = ctx.createOscillator();
osc.type = 'sine';
osc.frequency.value = noteKEY;
osc.connect(ctx.destination);
osc.start(0);
//osc.connect(ctx.destination);
}
function noteOFF(){
osc.stop(0);
}
});
答案 0 :(得分:2)
就像真正的物理振荡器一样,你不能同时将单个振荡器输出两个单独的音高。您必须为要播放的每个音符创建一个振荡器。在你的情况下,它意味着使用你想要同时播放的单独的noteKEY两次调用noteON。