PV_RecordBuf FFT data format?

Hi,

I’m using PV_RecordBuf to retrieve data from FFT and send it to other app and I would like to be sure how is this data stored. Is it DC, mag[0], phase[0]… etc? Where could I find a more precise information about this?

Also, is this the best approach to retrieve FFT information from SC to other apps through OSC? (tried pvcollect, UnpackFFT, and other approaches, none of them did help me very much)

Here’s what I’m trying…

(
~fftsize = 256;
~hop = 1;

n = NetAddr("localhost", 12345);                  


x = { var in, chain,magphases;                            
	in = SinOsc.ar(((MouseX.kr(1,255).round).poll*(SampleRate.ir/~fftsize)));
	chain = FFT(LocalBuf(~fftsize,1), in,~hop);
	/*magphases = UnpackFFT(chain, ~fftsize);*/
	PV_RecordBuf(chain,c,0,1,1,~hop);
	/*SendReply.ar(Impulse.ar(1),values:magphases);*/
	/*chain = PackFFT(chain, 2048, magphases);*/
    0.9 * Pan2.ar(IFFT(chain));
}.play(s);




~oscRoutine = Routine({                           // Routine to send buffer data every 100ms (could be faster)
    inf.do{arg i;
        c.getToFloatArray(action: { arg array;

			array = ["/myFFTdata"] ++ array;     // adding an OSC address before the floats
						/*array.postln;*/
			n.sendMsg(*array)                    // * passes the array as arguments to the n.sendMsg method
		});
		(1/(s.sampleRate/~fftsize)).wait;
	}
}).play()
)

Currently I’m checking the data in PD:
image

Thanks in advance for any clues/suggestions!

It isn’t documented – currently, to find this out, it’s necessary to read the source code.

	if(unit->first){
	    databufData[0] = buf->samples;
	    databufData[1] = IN0(5); // hop
	    databufData[2] = IN0(6); // wintype
	    unit->first = false;
	    }

Meaning: in the buffer, index 0 = frame size; index 1 = hop ratio (e.g. 0.5); index 2 = window ID.

So the first three values are not FFT data at all. This explains why the first value in your PD plot is so much larger than everything else: I expect it’s 256, matching the FFT buffer size.

Then:

	    databufData[frameadd] = p->dc;
	    databufData[frameadd + 1] = p->nyq;
	    for(int i = 1, j = 0; i <= numbins; i++, j++){
		itwo = i * 2;
		databufData[frameadd + itwo] = p->bin[j].phase;
		databufData[frameadd + (itwo + 1)]= p->bin[j].mag;
		}

Index (framenum * framesize) + 3: DC mag
Index (framenum * framesize) + 4: Nyquist mag
Index (framenum * framesize) + 5: Bin 1 phase
Index (framenum * framesize) + 6: Bin 1 mag
Index (framenum * framesize) + 7: Bin 2 phase
Index (framenum * framesize) + 8: Bin 2 mag
… etc.

BTW MultiSliderView can display array data natively within SC; no need to pass it over to Pd.

hjh

1 Like

Thank you very much!!