3
我很好奇我怎麼能在web音頻api中做一個叫做「扼流器」的東西。當我用鍵播放聲音時,如果再次按下該鍵,我希望它停止聲音並再次播放。任何想法如何做到這一點?如何使用網絡音頻api重新觸發(阻塞)聲音
我迄今爲止代碼:
$(document).on("keydown", function(e) {
console.log(e);
switch (e.keyCode) {
case 81: // Q
playKick(BUFFERS.kick);
break;
}
})
function playKick(instrument) {
source1 = context.createBufferSource();
source1.buffer = instrument;
source1.loop = true;
source1.connect(context.destination);
if (!source1.start)
source1.start = source1.noteOn;
source1.start(0);
}