Solved

# Need equation for converting decibels (dB) to standard scale 0 to 10000

Posted on 2001-09-11
292 Views
I need to fade volume of a DirectSound buffer but IDirectSoundBuffer:SetVolume wants the volume level specified in in hundredths of decibels (dB). Allowable values are between DSBVOLUME_MAX (no attenuation) and DSBVOLUME_MIN (silence). These values are currently 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.

Ramping SetVolume between -10000 and 0 (to fade in) results in a audibility between about -4000 and 0 and gives me a quick fade at the end of my ramp. I need a steady fade throughough. How do I convert say 0 to 10000 to necessary SetVolume argument that gives me a steady ramp? Thanks!!
0
Question by:mortonsw

LVL 1

Author Comment

ID: 6475808
0

Accepted Solution

c_i_wood earned 100 total points
ID: 6750723
Try this function (I've just written, not tested) to turn a fractional loudness (% volume) into 1/100ths of dB suitable for the SetVolume function:

int soundVolIn_mB(int percentage_volume)
{
if (percentage_volume<0 || percentage_volume>100)
return(0);
if (percentage_volume==0)
return(DSBVOLUME_MIN);
if (percentage_volume==100)
return(DBSVOLUME_MAX);
return(
(int)(  2000.0*log10( ((double)
(percentage_volume))/100.0 )  )
);
}

I think the log10 function is in math.h so you'll need to include it. It takes a double and returns the same so you need to do some casts. I think the code above should work OK.

Now you can ramp the percentage, run it through the function and insert the answer into the SetVolume function.

Let me know if it doesn't work!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

### Suggested Solutions

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…