# Normalizing loudness level of a set of songs

I like to listen to instrumental music while trying to sleep. So, I've selected 20 songs from my music archive to listen to when I go to bed. The problem is that the loudness levels of the songs differ. Therefore, I have difficulty listening to some songs while the others disturb me for a specific volume level. I want to normalize the loudness of them and set it to a common value programmatically (e.g. using MATLAB).

I thought the following:

n <- number of songs
a <- an array of values initially 0 (length n)
for i = 1 to n
partition song i into overlapping windows (e.g. window length of 1024, shift of 512)
let s_j's involve the values in j'th window where j = 1 to #windows
a(i) <- max_j sum(abs(s_j))
end for
m <- mean(a)
for i = 1 to n
rescale all the amplitude values of song i by m/a(i)
end for


What should I take into consideration to normalize the songs' loudness levels? What strategy do you recommend? I can write the MATLAB code easily from a pseudocode.

• You'll probably need a psychoacoustic measure of loudness rather than amplitude, e.g. en.wikipedia.org/wiki/Sones Commented May 25, 2012 at 7:48
• You don't need to roll your own program in MATLAB to do this in 2012; you can use off-the-shelf software
– Emre
Commented May 25, 2012 at 7:55
• Thanks Emre, that works great. You saved me a lot of time. Commented May 25, 2012 at 8:46
• @datageist I wasn't aware of that. Thanks! Commented May 25, 2012 at 8:47