# Getting loudness of a track with RMS

I'm trying to calculate the loudness of an audio track I have stored in a buffer. The buffer contains PCM data of the signal and I want to get how 'loud' it is by using Root Mean Squared. I assume I can do this in the time-domain instead of having to switch to the frequency domain. What would be the pseudo-code for doing this?

Would I simply sample for one second (audio[0] - audio[44099], audio[44099] - audio[88199] etc..) and calculate the RMS of those values? So, for example, would I do this:

$$RMS = \sqrt{\frac{\text{audio}[0]^2 + \text{audio}[1]^2 + \text{audio}[2]^2.....\text{audio}[44099]^2}{44100}}$$

for each second?

• There's a missing bracket in the expression above - I'd add it myself but edits need to be at least 6 characters apparently... – Paul R Sep 22 '11 at 7:39
• @PaulR - You can add an <!-- html comment --> to work around the character restriction in the rare case that an otherwise perfect post has a tiny but very important error. This need occurs very rarely: there's usually more than 6 characters of improvement to be done. For example, when there are missing brackets, it's usually better to use the \sqrt{} and \frac{}{} constructs in TeX. – Kevin Vermeer Sep 22 '11 at 12:12
• @Kevin: thanks for the tip - I will use your HTML comment suggestion in future. – Paul R Sep 22 '11 at 12:15
• @PaulR - This has been discussed before: The restriction is intentional, designed to prevent incomplete or pointless edits (see a defense here), but has its opponents (see discussion here). – Kevin Vermeer Sep 22 '11 at 12:24
• Note that RMS alone doesn't tell you loudness. Extremely low or high frequencies sound lower in volume than 3 kHz of the same RMS value. An A-weighting filter will give you a more accurate estimation. gist.github.com/148112 – endolith Sep 22 '11 at 14:26