I'm hoping some folks here can help me get my head around the task of adding ReplayGain functionality to the stock Android music player app. My lack of training in maths and audio science is making it hard for me to ask the right questions probably, so please bear with me if you can.

I've read through the replaygain spec (original proposal on your minisite and the updated version in the wiki) but there's still a lot that I'm unclear on. A sound engineeer friend helped me along a little further, but I think I exhausted his patience :(

Now I understand that all replaygain adjustments start from -14 dBFS, and RG treats this as equivalent to 89 dB (SPL). Where I get lost is how I'd translate that to the logarithmic scale used by the volume control function I have to work with, which takes a float value (0-1 = mute-max) to attenuate the playback volume for the app (normally it stays at 1 and is used mainly for fading; it's independent of the master volume controls for the device). It can be abstracted to a linear scale (of the type that a physical volume control would use, I believe) of 0-<number of your choice>. The value is calculated from a linear-scale value like this:

But to get to that point, I need somehow to abstract that starting-point of -14 dBFS / 89 dB SPL onto that linear scale. From what I've read so far, I get the feeling there is no "pure" way to do this and I'll be required to make some educated guesses. So that's where being uneducated lets me down :(

I'd just be grateful for any suggestions, help or references in how I might understand the task better and construct a *reasonably* accurate equation for it.

Well, the collection I have comprises a couple of decades' worth of CDs ripped to mp3 (about 1200 tracks) tagged using mp3gain, and there are plenty of +ve gain values in there (though most are -ve).

The problem is, I'm starting from 1 = max volume so to accommodate the +ve gains I necessarily have to reduce before I can increase. From reading the spec I thought this was the purpose of the -14dB, but it's becoming clear that it's not that simple :(

The problem is, I'm starting from 1 = max volume so to accommodate the +ve gains I necessarily have to reduce before I can increase.

Why? A number greater than 1 just means you have gain, which is what should happen if the replaygain value is positive.

Edit: to be clear, replaygain doesn't adjust the volume, it changes the gain. If the function you mentioned above is just adjusting the Android volume, thats likely not what you want. You're supposed to scale the actual the samples in your decoded PCM. If you try to do it by adjusting the player volume, you won't benefit from things like clipping protection. Once you compute the gain, just multiply it by each sample. If its less than 1.0, you'll have attenuation. If its greater, you'll have amplification.