[LAD] Calculate R M S

Jens M Andreasen jens.andreasen at comhem.se
Fri Feb 18 01:15:59 UTC 2011


On Wed, 2011-02-16 at 19:51 +0200, Alfs Kurmis wrote:
> 
> Hi Experts.
> 
> 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 ?

What we /hear/ as loudness are the transients, which you can detect by
summing up the delta values between samples. The following hack
visualizes that the commercials really are annoyingly loud compared to
regular programming:

// samplerate 96k, periodsize 256, updates 25 per second

       
       static long long sum = 0;
       static int previous = 0;
       static int count = 0;

       for(i = 0; i < 256; i++)
	 {
	   long long x = (in_buffer[i][0] - previous);
	   sum += llabs(x);
	   previous = in_buffer[i][0];

	   if(++count > (96000/25))
	     {
	       unsigned int s = sum>>31;      

	       fputs
		 ("\r    :    :    :    :    :    :    :    ]       \r[",
		  stdout);

	       while(s)
		 putchar('|'),
		   s >>= 1,s += (s>>1)+(s>>2);

	       fflush(stdout);

	       sum -= sum >>3; 
	       count = 0;
	     }
	 }

> 
-- 
A Charlatan with a Cembalo and other friends of The Little Matchgirl

http://mx44.linux.dk/charlatan/





More information about the Linux-audio-dev mailing list