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 &lt;- number of songs
a &lt;- 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) &lt;- max_j sum(abs(s_j))
end for
m &lt;- 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 can spare yourself time by using off-the-shelf software such as http://mp3gain.sourceforge.net/