Skip to main content

Notice

Please note that most of the software linked on this forum is likely to be safe to use. If you are unsure, feel free to ask in the relevant topics, or send a private message to an administrator or moderator. To help curb the problems of false positives, or in the event that you do find actual malware, you can contribute through the article linked here.
Topic: How to convert volume from dB? (Read 5230 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

How to convert volume from dB?

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
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
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.