Solved

Need equation for converting decibels (dB) to standard scale 0 to 10000

Posted on 2001-09-11
2
291 Views
Last Modified: 2012-06-21
I need to fade volume of a DirectSound buffer but IDirectSoundBuffer:SetVolume 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!!
0
Comment
Question by:mortonsw
2 Comments
 
LVL 1

Author Comment

by:mortonsw
ID: 6475808
0
 

Accepted Solution

by:
c_i_wood earned 100 total points
ID: 6750723
Try this function (I've just written, not tested) to turn a fractional loudness (% volume) into 1/100ths of dB suitable for the SetVolume function:

int soundVolIn_mB(int percentage_volume)
{
  if (percentage_volume<0 || percentage_volume>100)
    return(0);
  if (percentage_volume==0)
    return(DSBVOLUME_MIN);
  if (percentage_volume==100)
    return(DBSVOLUME_MAX);
  return(
    (int)(  2000.0*log10( ((double)
              (percentage_volume))/100.0 )  )
       );
}


I think the log10 function is in math.h so you'll need to include it. It takes a double and returns the same so you need to do some casts. I think the code above should work OK.

Now you can ramp the percentage, run it through the function and insert the answer into the SetVolume function.

Let me know if it doesn't work!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As game developers, we quickly learn that Artificial Intelligence (AI) doesn’t need to be so tough.  To reference Space Ghost: “Moltar, I have a giant brain that is able to reduce any complex machine into a simple yes or no answer. (http://www.youtu…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now