// Gen RMS calculator.
// Input buffer.
Delay input(8192, 1, feedback=0);
// Amount of samples to average.
acc = 0;
// Step through all samples.
for(idx = 0; idx < n; idx += 1)
// Read next value from input buffer.
v = input.read(idx, 0, interp="spline");
// Add square of value to accumulator.
acc += (v * v);
// Store next value we read from the input.
// Output RMS of n samples.
out1 = sqrt(acc / n);
while this works correctly, it gets insanely expensive for larger averaging windows.
i would propose something like the code below.
caveat: averaging size is fixed, as i don’t know an easy way to reset a delay line in gen~.
you could make it work with a buffer, though.
n = 2000;
rdiv = 1 / n;