Loudness of PCM stream
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.