FFTPower - Sum of instantaneous FFT magnitudes

	FFTPower.kr(chain)

Outputs a power measurement (sum of magnitudes) taken from an FFT chain. It can be used for similar purposes as the [Amplitude] UGen but has different characteristics since it operates on the frequency-domain rather than time-domain representation.

The output is scaled by dividing by the number of bins. To scale the power (e.g.) to lie between 0 and 1, you'll need to find an empirical value that suits the application - note the multipliers used in the examples below.

s = Server.internal.boot; 

b = Buffer.alloc(s,2048,1);

(
{
var in, chain;
in = WhiteNoise.ar(MouseX.kr(0,1));
chain = FFT(b.bufnum, in);
Out.ar(0, in * 0.1);
Out.kr(0, (FFTPower.kr(chain) * 0.05955912289792).poll(label:"Noise power"));
}.scope;
)

(
{ // Sine - note how the peak measured power changes with frequency
var in, chain;
in = SinOsc.ar(MouseY.kr(100, 1000, 1), 0, MouseX.kr(0,1));
chain = FFT(b.bufnum, in);
Out.ar(0, in * 0.1);
Out.kr(0, (FFTPower.kr(chain) * 0.66667).poll(label:"Sine power"));
}.scope;
)