Spectral Flatness in RNBO
Hi all,
I am looking to calculate spectral flatness in RNBO, either in a codebox or graphically, without reinventing the wheel. (Short of an existing example, a relevant codebox or gen example for working with fft buffers would be helpful. The basic codebox FFT examples leave me a bit uncertain about how to access samples across a buffer that is coming in live... ) I've seen the implementation in zsa.descriptors, but of course doesn't work in RNBO.
Thanks!
Jeff
Update: I think I figured out how to do it in codebox.
const fftsize = 256;
const invsize = 3.90625e-3;
@state fft = new fftstream(fftsize, fftsize, 0, {window:"hann"});
@state acc_g = 0.0;
@state acc_a = 0.0;
@state flatness = 0.0;
let fft_out = fft.next(in1);
let bin = fft_out[2];
let power = fft_out[0]*fft_out[0] + fft_out[1]*fft_out[1];
acc_g = acc_g + ln(power);
acc_a = acc_a + power;
if (bin==fftsize-1){
flatness = exp(acc_g*invsize)/(acc_a*invsize);
acc_g = 0;
acc_a = 0;
}
out1 = flatness;
out2 = bin;