I hope someone can help me, I've found this JS function which im using to plot a logarithmic EQ scale onto HTML 5 canvas.
I now am getting back the horizontal cursor position, in px, but have no idea how to convert this back to it's corresponding frequency value.
I have been googling for hours and trying loads of things in codepen, but my maths is abysmal so I need help!!
I am tying this into HTML5 web audio api, to control a filter.
This is the function im using, over a scale of 1000px.
Code: Select all
var width_px = 1000;
function frequency_to_px(frequency) {
var min_f = Math.log(20) / Math.log(10),
max_f = Math.log(16000) / Math.log(10),
range = max_f - min_f,
position_px = (Math.log(frequency) / Math.log(10) - min_f) / range * width_px;
return position_px;
}
Any help greatly appreciated!