spectral centroid with rnbo

Julien Bayle's icon

Hi there,

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 ?

Jean-Francois Charles's icon

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:

Max Patch
Copy patch and select New From Clipboard in Max.
Julien Bayle's icon

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 ?

Jean-Francois Charles's icon

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.

Max Patch
Copy patch and select New From Clipboard in Max.
Julien Bayle's icon

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.


main one

the rnbo one

the processor part for easier fft params



the gen~ one with hardcoded things


Jean-Francois Charles's icon

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~].

Max Patch
Copy patch and select New From Clipboard in Max.