Sound volume question (DirectSound)
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)?
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]
Fixed typo
[Edited by - JohnBolton on August 7, 2005 4:34:07 PM]
Here are functions to convert a linear scale to DirectX units and back:
[Edited by - JohnBolton on September 4, 2005 8:08:45 PM]
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]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement