How to calculate the logarithmic marks for the VU scale?

I am writing a meter widget using a canvas, and you need to calculate the label values ​​for the scale. No problem, except when I try to recreate the scale for the VU meter. I understand that it is logarithmic, but the values ​​are not equal to 10 on this type of counter.

see: https://en.wikipedia.org/wiki/VU_meter

Function i has min and max values ​​for the scale. For normal scales, a step between the values ​​is also given. For example, if you set the value to -20 and 30 in increments of 10, it will create labels:

-20 -10 0 10 20 30

For the VU meter given -20 and 6, I need to create labels:

-20 -10 -5 -3 0 3 6

And the gap between these values ​​does not match.

I am not asking for code examples, but instead of thinking about how to best implement this.

Do I have to write a function so that one of the parameters is a list of labels, and then draw them in a logarithmic scale? This does not work properly, because the numbers do not fall into the correct places, as shown in the image above the corresponding VU meter.

Is there any special formula for dB levels only that is not a simple log function?

Again, I am not asking for code examples, just for some help, to understand the best approach to use.

Thank!

+4
source share
1 answer

I suppose you have a value-pixel function. What you need to write is the inverse function of this.

, N ( 6 ). X . , .

, - 3.434 11.34 - prettyfier, "" (, ).

.

:

function value2px(value, valueMin, valueMax, pxMin, pxMax) {
    var valueWidth = sigLog(valueMax) - sigLog(valueMin);
    var pixelWidth = pxMax - pxMin;
    var ratio = pixelWidth / valueWidth;

    return ratio * (sigLog(value) - sigLog(valueMin)) + pxMin;
}

function px2value(px, valueMin, valueMax, pxMin, pxMax) {
    var valueWidth = sigLog(valueMax) - sigLog(valueMin);
    var pixelWidth = pxMax - pxMin;
    var ratio = pixelWidth / valueWidth;

    return sigExp((px - pxMin) / ratio + sigLog(valueMin));
}

: http://jsfiddle.net/ambcwoLg/1/

+2

All Articles