spectral centroid with rnbo
Hi there,
https://rnbo.cycling74.com/learn/using-the-fft is quite clear.
But I'm probably still missing something.
I'm just trying to adapt the gen~.centroid example patch to rnbo.
fftinfo is not available in rnbo so injecting parameters is ok but what would be the best practice here ?
Note that the main difference between RNBO and gen~ is that inside of gen, the vector size is one sample. In RNBO, the vector size is Max's Vector size.
I would first try a centroid in RNBO using magic numbers (hard-coded 512 or 1024...) then optimize the code after a first basic version is working.
Interesting question, so I tried a quick and dirty version. Not sure that helps, but here is what I have:
Hi Jean-François, yes about 1 sample vs vector size.
Setting the static vector size.
rampsmoothed the result a bit.
Checking a cycle~ for testing, value changing a lot.
Doesn't understand it.
Can we share ideas by email if you don't mind ?
Yes, the value is jittery, but it's pretty close. Since it's a computed value, it makes sense that it's jittery: the fft values are not exactly the same over time (since for each window we are analyzing a different set of samples).
Here is test patch, using fft size 1024 instead of 512.
It works pretty much the same for me regardless of the vector size.
Hi Jean-François and thanks for your help.
I don't understand why that is jittering, compared to our basic gen~.centroid example.
I did this, doesn't work even worst.




OK, I think the main thing causing the "instability" or oscillation in the result is the fact that with the [fft~] object, there is no built-in windowing. With pfft~, the default [fftin~] includes windowing that helps reducing the variability.
Here is an example using [fft~] in Max (not rnbo here). Without the windowing of the input (green cycle~), you get the same instabilities as the ones in rnbo. This is a proof of concept patch, which includes both hard-coded numbers for FFT size and some needed synchronization requiring you to use a vector size of 1024 (or greater). Here, I'm using some Jitter objects for convenience, but it's possible to translate that into rnbo using accum~ like in the first examples. The point is to apply a window to the input before realizing the [fft~].