Sound volume question (DirectSound)

Started by
4 comments, last by JohnBolton 18 years, 7 months ago
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)?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
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]
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
Thanks alot!
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
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?
It's all about the wheel.Never blindly trust technoligy.I love my internal organs.Real men don't shower.Quote:Original post by Toolmaker Quote:Original post by The C modest godHow is my improoved signature?It sucks, just like you.
Yes, that was a typo. It should be log10f. Sorry.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!

This topic is closed to new replies.

Advertisement