[gst-devel] Express volume in db instead of percent...

Maarten Bosmans mkbosmans at gmail.com
Tue Jan 12 11:03:54 CET 2010


2010/1/4 Yogesh Marwaha <yogeshm.007 at gmail.com>:
> http://en.wikipedia.org/wiki/DBFS is not clear enough for me. Now I'll
> try to be more specific on my question.
> I am to use volume element as preamp for gstiirequalizer plugin and
> as you must know that volume is expressed in percent whereas I want it
> to be expressed in db. So, I want a formula to convert to and from
> percent to decibel.

As Sjoerd said, db = 20 * log (percent/100) is correct.
You'll get 0dB = 100% and attenuation with dB < 0 and a volume  gain
with dB > 0.

> Here is what I got from searching the net:
> volume_in_db = 20 * log (volume_in_percent / 100)
> volume_in_percent = 10 ^ (volume_in_db / 20) * 100
>
> When I peeked into gstreamer source, I get to see something like this
> in gstiirequalizer.c
>
> static inline gdouble
> arg_to_scale (gdouble arg)
> {
>  return (pow (10.0, arg / 40.0));
> }

This has changed in
http://cgit.freedesktop.org/gstreamer/gst-plugins-good/commit/?id=27ea0b076a1f1d44c3da1c677eddf62d01eef1f1
It seems that the calculated value is not proportional to pressure or
voltage, but rather to the square root of it. It is a bit of a unusual
quantity, but used in the filters on which the GStreamer equalizer is
based, as described here:
http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt

> while peeking into banshee source, I get following code in gstiirequalizer.c
>
> static inline gdouble
> arg_to_scale (gdouble arg)
> {
>  return (pow (10.0, arg / 20.0));
> }
>
> I have no idea about how above code is being used but banshee's
> formula seems similar to what I got from internet.
>
> Any ideas??
>
> Regards,

Take home message: use the 20.

Maarten




More information about the gstreamer-devel mailing list