Solved

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

Posted on 2001-09-11
2
297 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

What is RenderMan: RenderMan is a not any particular piece of software. RenderMan is an industry standard, defining set of rules that any rendering software should use, to be RenderMan-compliant. Pixar's RenderMan is a flagship implementation of …
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

615 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