How do I convert a linear volume scale 0->64 to the logarithmic dB scale 0->10000(hundredths of a decibel).
Message from above:
Damn, my hair is grey!
how do I convert from linear to logarithmic
Using the log function. C''s log() function is the natural logarithm, and you want base 2, but it''s easy to convert betwen the two. E.g. you can use
#define logbase2(a) (log(a) / log(2))
and then you just need
hundredths_of_a_decibel = 100 * 10 * logbase2(volume);
[the ''100'' comes from wanting hundredths, while the 10 comes from wanting _deci_bels]
Note that this may not work for a volume of zero: it may crash or produce an infinite result. If you expect 0 volumes you should probably handle them seperately.
#define logbase2(a) (log(a) / log(2))
and then you just need
hundredths_of_a_decibel = 100 * 10 * logbase2(volume);
[the ''100'' comes from wanting hundredths, while the 10 comes from wanting _deci_bels]
Note that this may not work for a volume of zero: it may crash or produce an infinite result. If you expect 0 volumes you should probably handle them seperately.
John BlackburneProgrammer, The Pitbull Syndicate
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement