Loudness of PCM stream I'm receiving PCM samples through stream which is one channel, 8000 samples per second. I figured out way of finding out loudness by calculating 'force' of signal by adding abs value of every next 1000 samples and then dividing by samples count which is 1000. It works somewhat good but sometimes my calculations are going crazy, my sum of absolute values of samples seems to constantly build up and reach ridiculous values... so I think that I'm doing something wrong there. Funny thing is that when calculations are going crazy everything will go back to normal when I hit 'sound input device' with my hand ;)

Anyway. My question is: how to properly calculate loudness of set of PCM samples?
To measure the energy (which is closely related to, but not the same as, "loudness"), calculate the RMS (Root-Mean-Square).

$ E = \sqrt{\frac{\displaystyle\sum\limits_{n=0}^{N-1} s[n]^2}{N}}$

$N$ is the number of samples and $s[n]$ is the sample at time $n$.

You can do this in any block size of samples.  You can do it on all the samples at once to get an average energy, or you can break your sample set into chunks to see how the energy changes with time.

There are also more sophisticated methods that take into account the body and brain's quirks.  You can find more information about that here.