[LAD] Calculate R M S

Fons Adriaensen fons at linuxaudio.org
Wed Feb 16 18:45:07 UTC 2011


On Wed, Feb 16, 2011 at 07:51:09PM +0200, Alfs Kurmis wrote:

>  I wanna normalize my sound stream by loudness (energy / pressure /
>  intensity) , not by peaks.
>  How i do it ?
>  Is available Jack plugin for so what ?
>  What is (we hear as) "loudness" ?
>  RMS or +(average) or something else ?

If you have some patience, I will present and app that measures
loudness to ITU/EBU standards at the next LAC (if the paper is
accepted).

Some filtering followed by RMS detection will provide a good
approximation to subjective loudness.


>  Is it done simlpe by :
>   int i, n;  double sums, rms;
>   sums=0.0;  n=10;  rms=0;
>   for(i=0; i<n;i++)
>   {   sums = sums + ( (double)i * (double)i );  }
>   rms = sqrt(sums / n);
>   printf("         
>  rms = %12.12fnn", rms );

Basically correct. If you do this on a file then 'n' is the length
in samples. If you do it realtime, the sum is replaced by a lowpass
filter. For realtime RMS measurement you can use jkmeter.

>  Is so sipmple algo good enough for frequencies > 10 kHz ?
>  How to calculate RMS with hi-precision for frequencies > 10 kHz ?
>  With inerpolation or so ?

Nothing special is needed for high frequencies. 

>  What is reference ( 0dB ) RMS for example for 16bit PCM signal 1024
>  samples ?

Normally to do the calculations you convert first to floating point
in the range +/- 1.0. If you read a file libsndfile will do that for
you, for realtime if you use Jack all samples are already in that
format.

The reference for dB is what you make it. Normally full scale for a
sine wave is set to '0 dB'  The EBU 'target' loudness is -23 dB on
that scale (which is quite low for most popular music, but probably
OK for general purpose use).

>  How to calc RMS for stereo signal ?

Take the sum of the squares, not the square of the sum.


-- 
FA




More information about the Linux-audio-dev mailing list