Solved

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

Posted on 2001-09-11
5
321 Views
Last Modified: 2013-12-03
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!!

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
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
  • 3
  • 2
5 Comments
 
LVL 5

Expert Comment

by:robpitt
ID: 6476532
Decibels are logarithmic scale - see http://www.phys.unsw.edu.au/music/dB.html

Anyway try something like:-

    db = 10 * log10( percent/100 );
0
 
LVL 5

Expert Comment

by:robpitt
ID: 6476719
and inversely:
  percent = 100 * pow(10,db/10);
0
 
LVL 1

Author Comment

by:mortonsw
ID: 6476800
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?
0
 
LVL 5

Accepted Solution

by:
robpitt earned 100 total points
ID: 6477934
Given an 'inputVolume' measured in hundredths of a percent,
i.e. from 0 (silence) to 10000 (max), try the following:

MySetVolume( DWORD inputVolume)
{
    double decibels;
    DWORD dsVol;

    if (inputVolume==0)
        dsVol = DSBVOLUME_MIN;
    else if (inputVolume>10000)
        dsVol = DSBVOLUME_MAX;
    else
    {
        //convert linear inputVolume to decibels (logarithmic)
        decibels = 10.0 * log10((double)inputVolume / 10000.0);
        dsVol = (DWORD)(decibels * 100.0);
    }

    pDSBuffer->SetVolume( dsVol );
}


...think thats right.
0
 
LVL 1

Author Comment

by:mortonsw
ID: 6478022
20.0 * log10(... worked perfectly. Thanks!!
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
This article surveys and compares options for encoding and decoding base64 data.  It includes source code in C++ as well as examples of how to use standard Windows API functions for these tasks. We'll look at the algorithms — how encoding and decodi…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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