# Calculate a continuous running RMS at 48kHz

I’m trying to sample a signal but I can’t made it work continuously and tell me the RMS value once a second. There is a delay somewhere and it takes 3 seconds…

I saw in the examples that this should be possible, but I don’t understand why it is not working, can anyone help me?

The Code::
`
buffer1 <- blob(6000);
buffer2 <- blob(6000);

Total_avg<-0;
Total_rms<-0;
AVG<-1.678;
b<-0;//nº buffer

function Actuacion(V_AVG,V_RMS){ //RUIDO

``````server.log (V_AVG+" "+V_RMS);
agent.send("SendSound", V_RMS)
}
``````

function Signal_Procesing(buffer, length){
if (length > 0) {
::b++;//nº de buffer

``````local avg=0;
local rms=0

for (local i=0;i<length;i+=2) {
local MuestraI = buffer[i]+buffer[i+1]*256;
MuestraI = MuestraI/65536.0*3.3;//volts
local MuestraRMS=(MuestraI-AVG)*(MuestraI-AVG);

avg=avg+MuestraI;
rms=rms+MuestraRMS
}
::Total_avg+=avg/(buffer.len()/2.0);
::Total_rms+=rms

if(b==16){
::Total_avg=::Total_avg/b;
::AVG=::Total_avg;
::Total_rms=math.sqrt(::Total_rms/(::b*buffer.len()))

Actuacion(::Total_avg,::Total_rms);

::b=0;
::Total_avg=0;
}
``````

}}
hardware.pinA.configure(ANALOG_IN);
hardware.sampler.configure(hardware.pinA, 48000, [buffer1,buffer2], Signal_Procesing);
//FREC_SAMPLEO:=48KHz*2bytes/sampleo/[16 buffer *1 sampleos/sec] ==6000 bytes/buffer x sec;

hardware.sampler.start();`