Help - Search - Members - Calendar
Full Version: How to convert volume from dB?
Hydrogenaudio Forums > Hosted Forums > foobar2000 > Development - (fb2k)
andrew_smolko
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! smile.gif
plukin
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
foosion
QUOTE(andrew_smolko @ Aug 30 2006, 22:50) *
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
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.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.