Topic: How to convert volume from dB? (Read 4342 times)
0 Members and 1 Guest are viewing this topic.

## How to convert volume from dB?

##### 2006-08-30 21:50:37
I want to convert volume from dB to [1,100] range, i.e. f(1) = -100.0 dB, f(100) = 0.00dB.
Well, f(x) = 50 * log10(x/100) gives the results close to foobar volume slider shows, but I'd like to know the real formula. Please help!

## How to convert volume from dB?

##### Reply #1 – 2007-07-09 14:30:54
i'am also interested in such a function, how would you implement it in foobar? per plugin? i tried to write a script with panelsui, but it there you don't have ln(x) or exp(x)... i think your formula is quite good...
for converting it back (from foobars db to a user friendly format in %) you need the inverse function...
bye

## How to convert volume from dB?

##### Reply #2 – 2007-07-09 18:23:58
I want to convert volume from dB to [1,100] range, i.e. f(1) = -100.0 dB, f(100) = 0.00dB.

For gain to scale conversion see audio_math::gain_to_scale(). Your example shows the opposite direction (scale to gain), which would be
Code: [Select]
`inline audio_sample scale_to_gain(double p_scale) {return (audio_sample) (20.0 * log10(p_scale));}`

Note: a) The above assumes 0.0 < scale <= 1.0 for both directions. b) The user interface may use a different mapping.

Regarding titleformatting: There are not floating point operations in the titleformat language; that is also a bit out of the scope of the development forum.