Get maximum magnitude values from fft over time


#1

Hello,

i am trying to manipulate an fft chain, the goal is to check for every bin if the magnitude is a new maximum, and to hold onto all the maximum magnitude values in an array.
I tried this code:

c.free; c = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

(
{
	var in = PlayBuf.ar(1, c, BufRateScale.kr(c), loop: 1),
	chain = FFT(LocalBuf(1024), in),
	maxMag = (0!512);

	chain = chain.pvcollect(1024, {|mag, phase, index|

		maxMag[index] = if ( (mag > maxMag[index]), mag, maxMag[index]);

		[maxMag[index], phase]
	}, frombin: 0, tobin: 250, zeroothers: 0);
	0.5 * IFFT(chain).dup
}.play
)

Can someone help me out?


#2

I found a solution:


c.free; c = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");

(
{
	var in = PlayBuf.ar(1, c, BufRateScale.kr(c), loop: 1) *
	EnvGen.ar(Env([0,1],1)),
	chain = FFT(LocalBuf(1024), in),
	maxMag = (0!512);

	chain = chain.pvcollect(1024, {|mag, phase, index|

		var val = Demand.kr(chain > -1, 0, mag);
		maxMag[index] = RunningMax.kr(val);

		[maxMag[index], phase]
	}, frombin: 0, tobin: 25, zeroothers: 1);
	0.05 * IFFT(chain).dup
}.play
)