Jump to content
  • Advertisement
Sign in to follow this  
The C modest god

Sound volume question (DirectSound)

This topic is 4818 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

The values you can set of a sound buffer are from -10000 to 0. However, if I set the volume to -5000 it sounds a lot weaker then half the strength of the sound with volume set to 0. So how can I make setting the sound volume linear (in how its strength be)?

Share this post


Link to post
Share on other sites
Advertisement
DirectX uses a modified decibel scale (millibels?), in which the units are in 1/100ths of a decibel (dB). The decibel scale is a little complicated -- for one, it is logarithmic and not linear. Without going into the details, adding 6.02 dB (20*log(2)) makes the sound twice as loud and adding -6.02 dB (20*log(0.5)) makes the sound half as loud. -6.02 dB is -602 in the DirectX system, so setting the volume to -602 will make it half as loud. Setting it to -1204 will make it 1/4 as loud, -1806 will make it 1/8 as loud, and so on.

Fixed typo

[Edited by - JohnBolton on August 7, 2005 4:34:07 PM]

Share this post


Link to post
Share on other sites
Here are functions to convert a linear scale to DirectX units and back:
    int ConvertLinearToDirectX( int value, int max )
{
if ( value == 0 )
{
return -10000;
}
else
{
return (int)floorf( 2000.0f * log10f( (float)(value) / (float)max ) + 0.5f );
}
}

int ConvertDirectXToLinear( int value, int max )
{
if ( value == -10000 )
{
return 0;
}
else
{
return (int)floorf( powf( 10.0f, (float)value / 2000.0f ) * (float)max ) + 0.5f );
}
}
Edit: logf => log10f

[Edited by - JohnBolton on September 4, 2005 8:08:45 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!