假如将播放器的控制音量切割成0-100的话,由于IDirectSoundBuffer::SetVolume(LONG lVolume)中参数的输入值是[-10000,0]
MySetVolume( DWORD inputVolume)
{
double decibels;
DWORD dsVol;
if (inputVolume==0)
dsVol = DSBVOLUME_MIN;
else if (inputVolume>10000)
dsVol = DSBVOLUME_MAX;
else
{
decibels = 20.0 * log10((double)inputVolume / 100.0);
dsVol = (DWORD)(decibels * 100.0);
}
pDSBuffer->SetVolume( dsVol );
}
当然,也可以将音量控制分割成0--10000了,基本的公式就是这样的。
有篇文章可以参考参考:http://www.animations.physics.unsw.edu.au/jw/dB.htm#definition