Archived

This topic is now archived and is closed to further replies.

Volume in DirectSound

This topic is 5109 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! In IDirectSoundBuffer8 you can set the volume of the sound playing to a value between -10000 (silence) and 0 (normal). The volume is set in hundredths of a decibel. Now my problem is to work out how to translate this to normal percent so that the user can choose whether they want to play the sound in 50% or 100% (or whatever) of the volume. I''ve tried a number of different times to get it right but I can''t seem to get it. Please help...

Share this post


Link to post
Share on other sites
I''m not sure how you have your sound set up, so for the sake of explanation I''m going to pretend that you have a slider that goes from 0 to 100 (i.e., indicating percent).

The simplest way to get the conversion you want would be to just take the percentage from -9600 (0% volume).

Example: Slider is set to 48% volume. The calculation would simply be -1(0.48*9600).

However, after you do it linearly like this for a while, you''ll find that anything below around 70% is inaudible. If you want to make the volume change a more "natural" sounding way, you''ll want to use a piecewise linear function, say one that maps the lower 25% of available volume on the slider to lower 70% of actual reflected volume; this leaves the remaining 30% of actual volume to the other 75% on the slider. Draw yourself a few graphs, and I''m sure you can figure out how to make this work. If not, post again and I''ll give you some pointers (you''ll learn it best if you can figure it out on your own).

Aida ~
http://rainydayart.com

Share this post


Link to post
Share on other sites
The more "natural" way of doing it was actually the one I wanted to know about. Guess I''m bad at explaining how I want things done...

Anyway I''ve actually have drawn a few graphs, some that look pretty good on paper but when I tried to implement them it didn''t work.

Thanks for the reply.

Share this post


Link to post
Share on other sites
I would say that you should use the following formulas:

Percent = (Volume+10000)/100
Volume = 100*Percent - 10000

I''m sorry but I get a kick out of the fact that we have two complex ways of doing this (including a sound physics link!) and this seems like simple algebra...

Share this post


Link to post
Share on other sites
quote:
Original post by ms291052
I would say that you should use the following formulas:

Percent = (Volume+10000)/100
Volume = 100*Percent - 10000

I''m sorry but I get a kick out of the fact that we have two complex ways of doing this (including a sound physics link!) and this seems like simple algebra...


sound in decibels is a logarithmic measurement, not linear. that will not get the effect he wants. the link I provided should give some helpful info for getting a more accurate conversion from a percent.

Share this post


Link to post
Share on other sites
I''ll give you some numbers that reflect the "natural" scenario I mentioned earlier. I''m using -9600 to 0 in this example, because I''d been doing this work with DirectMusic and with the function IDirectMusicAudioPath8::SetVolume(). If you''re using IDirectSoundBuffer8::SetVolume(), you''ll want to change the 9600''s to 10,000''s.


First, I''ll define my magic numbers:

- The 2.8 used in the formulas comes from 70%/25%, because we want to map the lower 25% of slider volume to lower 70% of decible volume.

- The value of 1 1/3 used in the forumlas comes from 100%/75%, to cover the remaining volume.

- The value "percentage" is what''s on the slider, e.g., if the slider reads 48%, percentage == 0.48f.


Now, we have two separate volume forumlas, the first for the lower 25% on the SLIDER, and the second for the top 70%.


If the slider''s position is 25% or below:
desired volume = (percentage * 2.8 * 9600) - 9600

If the slider''s position is greater than 25%:
range = -1 * ( (9600 * 0.7) - 9600)
offset = ( (percentage - 0.25) * 1 1/3) * range
desired volume = offset - range


I appologize if it seems a bit confusing. Since you''ve already drawn a few graphs, put these formulas down next to them and work them through with a few sample percentages and you''ll be able to figure it out. Hope this helps! And let me know if I messed up my logic; it _is_ late over here, after all ^^

Aida ~
http://rainydayart.com

Share this post


Link to post
Share on other sites
Here''s a great article/rant about this problem:

"Notice to Programmers of Audio Software and Hardware"

http://www.dr-lex.34sp.com/info-stuff/volumecontrols.html

Dunno how to make it clicky.


I used that in my tools and it''s a good approximation.

Share this post


Link to post
Share on other sites