Archived

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

How can use float value to mark volumn?

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

Recommended Posts

(Sorry!My English is poor,but I''ll try my best to express my notion.) In directsound,the DSBVOLUMN_MAX is defined as 0 and the DSBVOLUME_MIN is defined as -10000. Now , I am writing a sound manager.I want to define the maximum volumn as 1.0f and minimum volumn as 0.0f , but I do not know how to transfer. Would you please tell me how can I do?

Share on other sites
Uhh, I really don''t see what the problem is, but you could scale your float with a macro or something like

#define FLOATTOVOL(fv, lv) { lv = (long)(fv * 10000) - 10000; }

Share on other sites
but I do not think the translation is linear.

because I heard the sound(-5000) is more light than half sound(0).

Share on other sites
not used direct sound but can you directly program into it?

and use cast operation eg

int a = 9;
int b = 5;
float c;

c = (float)a/b;

that will let you take a different datatype

im not sure thats all the programming i can help with until i have a look at direct sound myself

Share on other sites
The MS value represents attenuation of the volume in one hundredths of a decibel, -10000 = 100 dB (effectively silence),
-5000 = 50 dB, etc. This is a linear transition.

Share on other sites
Hey Coolzhao, the MS value is in hundredths of a decibel, or millibels (mB). Decibels are a logarithmic scale, because human hearing works logarithmically. To translate, you can use:

MilliBelFigure = (int) (1000 * log10(FloatFigure))

and

FloatFigure = pow(10, MilliBelFigure / 1000)

Hope this helps.

Note that if FloatFigure is very small, log10(FlostFigure) will become a very large -ve value. If it goes below -10, say, you want to clamp it to lie in range.

1. 1
Rutin
67
2. 2
3. 3
4. 4
5. 5

• 21
• 10
• 33
• 20
• 9
• Forum Statistics

• Total Topics
633420
• Total Posts
3011791
• Who's Online (See full list)

There are no registered users currently online

×