   Converting decibel to percent.
  Hello.Im looking for a formula to convert decibells to percent.Im using the dsound api and it sets the volume of a sound stream in decibells. The scale is from -10000 to 0 i think.What i want, is to convert this into percent. From 0 to 100 that is. Where 50 is half of the sounds volume. (Like the winamp volume meter, for instance.)But the decibel scale isn't linear (duh!). Anyone know the formula for converting between the two?Thanks in advance!   
  Well the decibel scale isn't upper or even LOWER bound.  That is you can theoretically have like -10,000 dB or 1,000,000 dB.  So you first have to define a range of acceptable values, (say between 10 and 80 dB or something you feel is realistic for the situation)The equation for getting the dB is dependant on what is defined as the Threshold of Hearing for humans.  Which is 2 x 10e-5 pascals where a pascal is a measurement  of pressure(which makes sense cause that's all sound is, a change in pressure)dB = 10log10(I/Io)where Io is the Threshold of Hearing, I is the current pressure, and dB is the decibel amount.  So let's say your range is 10 to 80 dB(you'll want to find out what you believe is reasonable) then you'd solve for I for both of these to give you the 'range' of pressures. Solving for I we get(10^(dB/10))*Io = ISo 10dB = 2e-4 PascalesAnd 80dB = 2000 pascalesgiving a range of practically (2000-2e-4) equals approximately... 2000 pascalesSo if you had 50 dB you'd have 2 pascales.  2/ 2000 is 0.1% of your range.  So you can see there is a very large range of sounds.   ;  oh yeah a ton of good info at wikipediahttp://en.wikipedia.org/wiki/Decibelit's where I got that info.a good passageQuote:Psychologists have found that our perception of loudness is roughly logarithmic — see the Weber-Fechner law. In other words, you have to multiply the sound pressure by the same factor to have the same increase in loudness. This is why the numbers around the volume control dial on a typical audio amplifier are related not to the voltage amplification, but to its logarithm.As you can see, "Percentage of volume" is a very nebulous concept that is based entirely on how you define the limits.  even though dB are logorithmic and not linear in nearly every practical application we use the log because it's closer to what we perceive on a day to day life.   ;  Hey Peter, this is what you need.Say you have a value X in DirectSound units.  It uses values in hundredths of decibels (which is millibels or mB), so -10000 corresponds to -100 dB, or -10 B.So your value X corresponds to (X / 1000) bels.  -1 bel corresponds to a reduction in volume by a factor of 10; -2 bels corresponds to a factor of 100, etc.So X mB corresponds to a volume factor of pow(10, X / 1000.0).For instance, X = -10000 corresponds to vol = pow(10, -10), or 0.0000000001.X = 0 means vol = 1.   ;Quote:The following is from 'DirectX C++ Documentation' for IDirectSoundBuffer8::SetVolume(LONG lVolume)RemarksAllowable values are between DSBVOLUME_MAX (no attenuation) and DSBVOLUME_MIN (silence). These values are defined in Dsound.h as 0 and –10,000 respectively. The value DSBVOLUME_MAX represents the original, unadjusted volume of the stream. The value DSBVOLUME_MIN indicates an audio volume attenuated by 100 dB, which, for all practical purposes, is silence. DirectSound does not support amplification.  I haven't worked with directSound to be honest, but the SPL (sound pressure level) ratio in decibels is given by 20*log(actual_value/reference_value), where the logarithm is to base 10.   In most audio edit applications, programmers use as reference_value the maximum value for an audio sample, because this is the easiest approach when you want to turn dB into amplitude percentage.  Generally when you double the sound's amplitude, the ratio in decibels is increased by +6dB (which is 20*log(2)), and when you halven the value the ratio is decreased by 6dB (-6==20*log(.5))(this is why audio most apps have reference lines in their graphs at -6dB,-12dB etc.)Personally, I would suggest you use the following:Since each unit is 1/100 of a dB, divide the dsound value by 100 to turn it into decibels, call it e.g. dB, and then your percentage is:pctg = 100*pow(10,dB/20)The 'pow(10,dB/20)' comes from solving : dB = 20*log( pctg ) for pctg, and multiply it by an extra 100 to turn it into a percentage. Just don't forget that dB must be negative. Generally negative dB means smaller than reference_value (that's why people often use the max amplitude for that one)edit:The above function would return 100 for dB==0, 50 for dB=-6, 25 for dB=-12, etc, which I believe is what you were asking for in the first place.I hope this helps[Edited by - someusername on November 17, 2005 1:32:49 AM]