2 summary:: Unpack an FFT chain into separate demand-rate FFT bin streams
4 related:: Classes/PackFFT, Classes/Unpack1FFT
7 Takes an FFT chain and separates the magnitude and phase data into separate demand-rate streams, for arithmetic manipulation etc.
9 This is technically a demand-rate UGen. The actual "demand" is usually created by PackFFT later on in the graph, which requests the values in order to re-pack the data. This allows for processing to occur imbetween...
11 See also pvcollect, pvcalc and pvcalc2 methods ( in link::Classes/PV_ChainUGen:: ) which provide convenient ways to process audio in the frequency domain. The help for pvcollect includes notes on efficiency considerations.
22 limiting analysis to the bins of interest
24 limiting analysis to the bins of interest
26 A list from DC up to Nyquist of code:: [mag[0], phase[0], mag[1], phase[1], ... mag[nyquist], phase[nyquist]]. ::
28 Note that you do have to decide your FFT buffer size in advance, since this determines how many values the UGen will output.
30 #magsphases = UnpackFFT(chain, bufsize)
38 b = Buffer.alloc(s, fftsize, 1);
39 c = Buffer.read(s, Platform.resourceDir +/+ "sounds/a11wlk01.wav");
43 // This one just drags out various the values and posts them - a little bit pointless!
48 sig = PlayBuf.ar(1, c, BufRateScale.kr(c), loop: 1);
51 // Using the frombin & tobin args makes it much more efficient, limiting analysis to the bins of interest
52 unp = UnpackFFT(chain, b.numFrames, frombin: 0, tobin: 4);
54 // Demand some data from the unpacker.
55 // NOTE: At present, Demand.kr is unable to handle more than 32 inputs,
56 // so using frombin & tobin to limit the number of bins is compulsory.
57 Demand.kr(chain>=0, 0, unp).collect{|anunp, index|
58 anunp.poll(chain>=0, if(index % 2 == 0, "Magnitude", "Phase")+(index/2).floor);
66 // Now a simple frequency-domain manipulation, square-rooting the magnitudes AND phases.
69 var in, chain, magsphases;
70 in = PlayBuf.ar(1, c, BufRateScale.kr(c), loop: 1);
72 magsphases = UnpackFFT(chain, b.numFrames);
73 magsphases = magsphases.collect(_.sqrt);
74 PackFFT(chain, b.numFrames, magsphases);
75 Out.ar(0, 0.25 * IFFT(chain).dup);