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: Conversion between volume in % and dB (Read 9634 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Conversion between volume in % and dB

Hello,

I'm working on a media player which uses MPlayer as backend. MPlayer accepts volume in dB (range -200 to 60 dB). I won't use values above 0.

I need to get volume from slider and calculate the dB value for MPlayer. Unfortunately I'm not able to find any suitable function. The problem is, that with about -50 dB the sound is already almost silent. So linear scale is bad, exponential also.

How is the volume usually calculated in media players?


Conversion between volume in % and dB

Reply #2
Use dBs.
If you want, use the scale between -40dB and 0dB, but use dBs.
The linear amplitude scale is not adecuate for a volume control, since the first half almost doesn't attenuate (6dB), while the other half decreases faster and faster.


Edit: As a reference, the conversion is:

db = 20*log10(amplitude)
In computers, generally what is done instead is 6.02*log2(Amplitude). From this is where it comes the saying that each bit is 6dBs.
(6.02 is the approximation of 20*log10(2), and log2(x) is the log function that is faster in computers)

The reverse is, i guess, obvious:  amplitude =  pow(2,dB/6.02) , or  pow(10,dB/20)

Conversion between volume in % and dB

Reply #3

Edit: As a reference, the conversion is:

db = 20*log10(amplitude)
In computers, generally what is done instead is 6.02*log2(Amplitude). From this is where it comes the saying that each bit is 6dBs.

More correct to say
+6 db = 20log(2º1bit)

It rather comes from signal theory.
Hm. I actually know this rule (+1bit is +6dBs of S/N  in digital modulation or quantization) from books of telecomunications and so.

Conversion between volume in % and dB

Reply #4
log10(2) = 0.301029996

20 x log10(2) = 6.020599913.

Hence doubling amplitude is an increase of 6.020599913dB.

Conversion between volume in % and dB

Reply #5
We talk about the same thing but doing it just different ways.
JAZ's formula (6.log2(Amp)) works as well though the original/classic formula is 20log10(2ºnbit). That's where the rule (+6db is +1 bit) comes from.

Conversion between volume in % and dB

Reply #6
When you write º, do you mean power? as in 2 power nbit?  I am more familiar with the ^ sign for that.

If it's that, then, we say almost the same. 2^1bit = 2 and 20*log10(2) i've said that it's approximately 6.02.
As such, since log2(amplitude) does returns the number of bits for an amplitude, multiplying by 6.02 calculates the dBs for an amplitude.


Maybe your sentence is more correct as it represents exactly a conversion between bits and dBs.
Signal theory is not necesarily expressed in bits, except if we talk about DSP, and then, we're talking about computers, sort of...

Conversion between volume in % and dB

Reply #7

When you write º, do you mean power? as in 2 power nbit?  I am more familiar with the ^ sign for that.

Correct.



Signal theory is not necesarily expressed in bits, except if we talk about DSP, and then, we're talking about computers, sort of...

I think more aprropriate word will be information theory which lays  somewhere between signal theory and computers as you say (informatics more appropriate not only computers).

Conversion between volume in % and dB

Reply #8
If you use a linear scale for mapping slider position to %, the dB steps near 0% are too big — fail.
If you use a decibel scale, you'll have to constrain the scale to -x dB, cannot achieve 0 volume — fail.

Recommendation: don't use linear, don't use dB — use power scale. It has the best perceptual friendliness: % = sliderpos ^ 2.

Conversion between volume in % and dB

Reply #9
If you use a decibel scale, you'll have to constrain the scale to -x dB, cannot achieve 0 volume — fail.


In theory, yes, you cannot. But in practice you actually can!

Code: [Select]
var x: double;
    i: integer;

begin
  x:=1;
  i:=0;
  repeat
    x:=0.5*x;
    inc(i);
  until x = 0;
  writeln('-', round(6.020599*i),
          ' dB equals zero on this machine at double precision.');
end.


Code: [Select]
-6472 dB equals zero on this machine at double precision.




Conversion between volume in % and dB

Reply #10
If you use a linear scale for mapping slider position to %, the dB steps near 0% are too big — fail.
If you use a decibel scale, you'll have to constrain the scale to -x dB, cannot achieve 0 volume — fail.

Recommendation: don't use linear, don't use dB — use power scale. It has the best perceptual friendliness: % = sliderpos ^ 2.


This seems to be the best solution so far. I'll have to figure out what is the best value for "silence". I set it to -120dB, I'll try to figure out if other values (possibly lower) aren't better.

The algorith I use is dB = (100-sliderValue)^2/83, where the slider return 0 for silence and 100 fo full volume, the result value is 120 - 0 dB.

Also at the upper side, the change is quite small. Lowering the volume by 10% makes only 1 dB change. Wouldn't it be better to use values other then 0 - 100 for the volume slider? Maybe 10 - 110 would be better...

 

Conversion between volume in % and dB

Reply #11
Real volume controls aren't based on dBs over their entire range. Neither are they logarithmic over their entire range. They're just approximations.

http://www.geofex.com/article_folders/pots...ts/potscret.htm
see "Which leads us to tapering.".

Typical mixing desks go from +10dB to -48dB in a scale that attempts to be in straight dBs from -48 to 0, and then more gentle above that. Below that (i.e. below -48dB) it goes rapidly to silence.


You'd think this would be such obvious basic stuff that it was documented everywhere, but I can't find a plot of the response on-line!

Cheers,
David.