FFTCentroid Spectral centroid
FFTCentroid.kr(chain)
Given an FFT chain, this measures the spectral centroid, which is the magnitude-weighted mean frequency, or the "centre of mass" of the spectrum. (DC is excluded.)
This can be a useful indicator of the perceptual brightness of a signal.
Example
// Very artificial example - just filtering some noise.
s.boot;
b = Buffer.alloc(s,2048,1);
(
x = {
var in, chain, freq, rq, centroid;
//freq = LFPar.kr(0.3).exprange(100, 1000);
freq = MouseY.kr(1000, 100, 1);
rq = MouseX.kr(0.01, 10);
in = BPF.ar(WhiteNoise.ar, freq, rq);
chain = FFT(b.bufnum, in);
centroid = FFTCentroid.kr(chain);
Out.ar(0, in.dup * 0.1);
centroid.poll(10);
}.play(s);
)
x.free;