I am a software developer, and I am writing a software to measure the average perceived volume of an MP3 file using ReplayGain algorithm. I don't know that much about that topic myself, so if you know more than me, feel free to explain me any concept I might have misunderstood.
With that out of the way, I'd like to make a brief introduction to this topic:
An audio can be represented as a sequence of amplitude values, that is, numbers ranging from -1 to 1 (basically a wave). The ReplayGain algorithm transform these amplitude values using IIR filters to approximate their "absolute" amplitude with the amplitude for which human hears usually perceive the sound as (based on their frequency [Hz] and their overall power). The ReplainGain website has a great explanation of the application of these filters for those who are interested (see here).
As a last step, we calculate the RMS of the transformed audio samples (a very small fraction of a second of an audio) to find its average value. For audios with multiple channels, we just take the average of their channels.
With that said, how can I convert this average amplitude value to a (positive) dB scale? What do I need to know in advance and to consider when performing such conversion?
I am currently using these two functions I found on the internet to do that:
- from a simple value: 20 * log10(x+ 1^-10), where x is the amplitude (ranging from -1 to 1)
- from a squared value: 10 * log10(x + 1^-10), where x is the amplitude
The issue is that these functions convert the amplitude of the audio to dBFS, which is not what I was looking for because users usually expect to see positive dB values, not negative values.
And here am I, asking how can I convert either the amplitude values (-1 to 1) or the dBFS value into the dB scale. If you could explain me how do I figure out what noise floor to use (when calculating dBFS), and how to propertly calculate the dBFS value given the audio amplitude, I would be grateful.
It's important to point out that the software has access to the audio metadata such as bitrate, audio bit depth, etc, so these infos are available (if we need them to calculate these values).
Thanks in advance!