Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
word search puzzle 2 1,191
How are Tech stock earnings calculated? 2 72
Stocks - How do I research and choose a Spider stock, and how does it make money? 3 90
count8 challlenge 13 187
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

685 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