# 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.

## 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 on other sites
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 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]

Thanks alot!

##### Share on other sites
I have to revive this thread.
Jhon, in translating linear into decibal you used logf, but I think logf is on e base and not 10 base. Therefore log10 should be used.
Am I right?

##### Share on other sites
Yes, that was a typo. It should be log10f. Sorry.

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633298
• Total Posts
3011259
• ### Who's Online (See full list)

There are no registered users currently online

×