I'm trying to implement Replay Gain (that is, responding to replaygain tags in music files) into the stock Android/AOSP music player app. This is just a personal project but down the line I could offer it as a patch or maybe make a lib or player of my own. I'm only looking at Track Gain in the first instance. The nature of my question is probably down to the fact I flunked maths ;)
The task is to do two things: A) Before playback starts, clamp the volume to device maximum -14dB (or maybe more, some sources advise -23dB). B) Before playback of each track begins, read its tag and adjust by that number of dB.
I see that adjusting the playback volume in Android involves logarithm scaling as well, but since I'm new to logarithms I'm not sure if that makes things easier or twice (10x?) as hard.
Can anyone please give me the clue I lack on how to translate the decibel values to usable params for MediaPlayer.setVolume()? Thanks for any tips.
EDIT: I have some (probably shaky) assertions that might make the connection needed, but I badly need to be told if any of them are harebrained.
If these hold water, I'd turn a Track Gain value of -1.3 into the appropriate parameter for MediaPlayer.setVolume() as follows:
Is this remotely on the right track?
So once you got a common point between your two scales, they then evolve the same. You basically defined a ratio between the reference acoustic pressures of your two scales by saying that -14dbFS = 89 dBSPL.
Because multiplicative scales are a hassle, we take the logarithm of these multiplicative values, and divide them by 10, which gives us the additive values called decibels (the extra 2 factor comes from the fact we compare the square of acoustic pressures, not acoustic pressures themselves).
Now finally, if you consider you have a range of 103 dB that is mapped logarithmically (as are your dB) from 0.0f to 1.0f (which is what seams to be the case for playback volume in Android), then -14dBFS is (103 - 14)/103.
You need to get into the math of log's only if you want to make a linear scale out of this : 80% of max sound on a linear scale would be 1-log(20)/log(100) on your output scale.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With