Int to dB for sliders?


#1

Does anyone have a little sippet of code to turn the integer value of a control (like a slider) into dB?

If that doesn’t exist, it’s easy enough to implement, but I thought perhaps
I could avoid duplicating someone else’s work.


#2

Into a dB? Database? Or what type definition is dB?


#3

From memory - and i could be wrong

remember dBs are relative units, so in this example, your output value in dBs would be 0dB when slider_value == max_slider_value. At any other value, your output will be negative.

If you want your slider to represent some other range, you’ll need to adjust the expression in the log10 call.


#4

Actually, you multiply by 20.0, not 10.0.

Even this isn’t right; log10 will blow up if slider_value is zero.

The Slider class will do this for you; just call Slider::setSkewFactor.


#5

[quote=“matt”]Actually, you multiply by 20.0, not 10.0.
[/quote]
yeah, i was thinking something didn’t look quite right. :oops:

true. my oversight… so you do a check for slider_value >0 before you do the calculation… else you have -infinity for your output.

[quote=“matt”]
The Slider class will do this for you; just call Slider::setSkewFactor.[/quote]
I’m not sure setSkewFactor guarantees any specific operation on the linear slider position(though internally i believe it is using log10). Also, using the factor parameter is not intuitive for generating the required output in dBs, unless you are sure of the internal workings of the class (which of course are subject to change). I certainly wouldn’t encourage using it for evaluating specific mathematical expressions.

i would of course encourage using the correct math :smiley: :oops:


#6

that's exactly what I needed, with the exception that you have to set
your lower threshold and assign values below that manually. In this
case, you want to avoid the log10(0).

that’s exactly what I needed, with the exception that you have to set
your lower threshold and assign values below that manually. In this
case, you want to avoid the log10(0).


#7

[quote=“daniel78”]
I’m not sure setSkewFactor guarantees any specific operation on the linear slider position(though internally i believe it is using log10). Also, using the factor parameter is not intuitive for generating the required output in dBs, unless you are sure of the internal workings of the class (which of course are subject to change). I certainly wouldn’t encourage using it for evaluating specific mathematical expressions.

i would of course encourage using the correct math :smiley: :oops:[/quote]

That’s a good point. Now that I think about it, I used the skew factor in the slider to get a non-linear scale and then did the conversion myself.

Matt


#8