Solved

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

Posted on 2001-09-11
2
290 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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Recently, in one of the tech-blogs I usually read, I saw a post about the best-selling video games through history. The first place in the list is for the classic, extremely addictive Tetris. Well, a long time ago, in a galaxy far far away, I was…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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

18 Experts available now in Live!

Get 1:1 Help Now