Writing FFT Plugin with 2 outputs

Hi,

I’ve been working on an FFT Plugin that splits a chain into partials and residual. The plugin takes two FFT chains as argument, where the second one is ‘empty’, together with a fundamental frequency and number of partials to split, and outputs two chains:

var partials, residual, chain, freq=220;
chain = FFT(LocalBuf(2048), SinOsc.ar(freq * (1..8), mul:0.1) + WhiteNoise.ar(0.02));
#partials, residual = PV_SplitPartials(chain, FFT(LocalBuf(2048), DC.ar), freq, 8);

Now, this seems to work, but I’m having occasional initialization glitches, where the IFFT of the residual chain is outputting NaN’s when the synth is starting. I’m thinking it might have to do with garbage data in the buffer, but I’m struggling to figure out why this is only happening in the second chain.

Do I need to clear the buffers on plugin initialization, or are there other issues that is causing those NaN’s? Greatful for any pointers on where to start digging.

The plugin code is below, and the whole project is over at https://github.com/jpburstrom/pvplugins