此代码绘制画布对象中频率数据的线性序列。如何在webaudio上下文中使用 getByteFrequencyData 在对数X轴上显示频率?
var analyser = audioContext.createAnalyser();
[...]
frameLooper();
function frameLooper(){
window.requestAnimationFrame(frameLooper);
fbc_array = new Uint8Array(analyser.frequencyBinCount);
analyser.getByteFrequencyData(fbc_array);
canvas.width = fbc_array.length;
ctx.clearRect(0, 0, canvas.width, canvas.height);
bar_width = 2;
for (var i = 0; i < fbc_array.length; i++) {
bar_x = i;
bar_height = -fbc_array[i];
ctx.fillRect(bar_x, canvas.height, bar_width, bar_height);
}
}