mortonsw
asked on
Need equation for converting decibels (dB) to standard scale 0 to 10000
I need to fade volume of a DirectSound buffer but IDirectSoundBuffer:SetVolu me wants the volume level specified in in hundredths of decibels (dB). Allowable values are between DSBVOLUME_MAX (no attenuation) and DSBVOLUME_MIN (silence). These values are currently defined in Dsound.h as 0 and -10,000 respectively. The value DSBVOLUME_MAX represents the original, unadjusted volume of the stream. The value DSBVOLUME_MIN indicates an audio volume attenuated by 100 dB, which, for all practical purposes, is silence.
Ramping SetVolume between -10000 and 0 (to fade in) results in a audibility between about -4000 and 0 and gives me a quick fade at the end of my ramp. I need a steady fade throughough. How do I convert say 0 to 10000 to necessary SetVolume argument that gives me a steady ramp? Thanks!!
I found two leads that may help but unsure how to translate into c:
http://picard.coma.sbg.ac.at/coma/docu/AF/docs/man3/AFdBtoLin.html
http://picard.coma.sbg.ac.at/coma/docu/AF/docs/man3/AFLintodB.html
Ramping SetVolume between -10000 and 0 (to fade in) results in a audibility between about -4000 and 0 and gives me a quick fade at the end of my ramp. I need a steady fade throughough. How do I convert say 0 to 10000 to necessary SetVolume argument that gives me a steady ramp? Thanks!!
I found two leads that may help but unsure how to translate into c:
http://picard.coma.sbg.ac.at/coma/docu/AF/docs/man3/AFdBtoLin.html
http://picard.coma.sbg.ac.at/coma/docu/AF/docs/man3/AFLintodB.html
and inversely:
percent = 100 * pow(10,db/10);
percent = 100 * pow(10,db/10);
ASKER
I know very little C (I write in ASM and interface) but my func to call DirectX SetVolume is in C and accepts arg (0 to 10000) which it subtracts 10000 from in order to pass to SetVolume (since it wants -10000 to 0).
extern "C" BOOL FAR PASCAL DXSBSetVolume( LPDIRECTSOUNDBUFFER lpBuffObj , DWORD Volume)
{
dsrval = lpBuffObj->SetVolume( Volume-10000 );
if(dsrval == DS_OK) return TRUE;
return FALSE;
}
What's the necessary code to use to handle calling argument as 100ths of percent (ie, 10000 = 100.00%), convert to decibel scale and pass to SetVolume as -10000 to 0?
extern "C" BOOL FAR PASCAL DXSBSetVolume( LPDIRECTSOUNDBUFFER lpBuffObj , DWORD Volume)
{
dsrval = lpBuffObj->SetVolume( Volume-10000 );
if(dsrval == DS_OK) return TRUE;
return FALSE;
}
What's the necessary code to use to handle calling argument as 100ths of percent (ie, 10000 = 100.00%), convert to decibel scale and pass to SetVolume as -10000 to 0?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
20.0 * log10(... worked perfectly. Thanks!!
Anyway try something like:-
db = 10 * log10( percent/100 );