supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / UGens / FFT / PackFFT.html
blobdce933e88fc7a629d7505e701e6b58cfd259952d
1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2 <html>
3 <head>
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <meta http-equiv="Content-Style-Type" content="text/css">
6 <title></title>
7 <meta name="Generator" content="Cocoa HTML Writer">
8 <meta name="CocoaVersion" content="949.35">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
15 span.s1 {font: 15.0px Helvetica}
16 span.s2 {color: #002bf0}
17 span.s3 {color: #0000bf}
18 span.s4 {color: #000000}
19 span.Apple-tab-span {white-space:pre}
20 </style>
21 </head>
22 <body>
23 <p class="p1"><span class="s1"><b>PackFFT<span class="Apple-tab-span"> </span></b></span><b>Pack separate demand-rate FFT bin streams into an FFT chain buffer</b></p>
24 <p class="p2"><br></p>
25 <p class="p1"><b>PackFFT(chain, bufsize, magsphases)</b></p>
26 <p class="p2"><br></p>
27 <p class="p1">Takes an array of magnitudes and phases, and packs them into an <a href="FFT.html"><span class="s2">FFT</span></a> buffer ready for transforming back into time-domain audio using <a href="IFFT.html"><span class="s2">IFFT</span></a>.</p>
28 <p class="p2"><br></p>
29 <p class="p1">Most people won't need to use this directly - instead, use <a href="pvcollect.html"><span class="s2">pvcollect</span></a>, <a href="pvcalc.html"><span class="s2">pvcalc</span></a>, or <a href="pvcalc2.html"><span class="s2">pvcalc2</span></a>.</p>
30 <p class="p2"><br></p>
31 <p class="p1">The input data is <b>magsphases</b>, which should be a flat array containing magnitude and phase of all bins in ascending order.<span class="Apple-converted-space"> </span></p>
32 <p class="p1"><span class="Apple-tab-span"> </span>e.g. [mag0, phase0, mag1, phase1, mag2, phase2, ... magN, phaseN]</p>
33 <p class="p1">This input is typically demand-rate.</p>
34 <p class="p2"><br></p>
35 <p class="p1">This is technically similar to <a href="../Synth control/Demand Rate/Demand.html"><span class="s2">Demand</span></a> or <a href="../Synth control/Demand Rate/Duty.html"><span class="s2">Duty</span></a> in that it calls demand-rate UGens further up the graph to process the values, eventually calling <a href="UnpackFFT.html"><span class="s2">UnpackFFT</span></a>. These two ends of the process must in most cases see the same chain...! Otherwise behaviour is undefined and, who knows, possibly unpleasant.</p>
36 <p class="p2"><br></p>
37 <p class="p1">Optional parameters: <b>frombin</b> and <b>tobin</b> allow you to fill the supplied data only into a subset of the FFT bins (i.e. a single delimited frequency band), and if you do this, you can also optionally set <b>zeroothers</b> to 1 to zero all the magnitudes outside this band (otherwise they stay intact).</p>
38 <p class="p2"><br></p>
39 <p class="p1">For usage examples, see <a href="UnpackFFT.html"><span class="s2">UnpackFFT</span></a>, but also <a href="pvcollect.html"><span class="s2">pvcollect</span></a>, <a href="pvcalc.html"><span class="s2">pvcalc</span></a>, <a href="pvcalc2.html"><span class="s2">pvcalc2</span></a>.</p>
40 <p class="p2"><br></p>
41 <p class="p2"><br></p>
42 <p class="p2"><br></p>
43 <p class="p1">Here's an unusual example which uses PackFFT <i>without</i> using UnpackFFT first - essentially creating our FFT data from scratch.</p>
44 <p class="p2"><br></p>
45 <p class="p3"><br></p>
46 <p class="p4">// Reminder: This isn't the intended typical usage! It's OK to do this though.</p>
47 <p class="p5">(</p>
48 <p class="p5">x = {</p>
49 <p class="p5"><span class="Apple-tab-span"> </span><span class="s3">var</span> mags, phases, chain, sig;</p>
50 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// Create simple undulating magnitudes</p>
51 <p class="p5"><span class="Apple-tab-span"> </span>mags = {<span class="s3">FSinOsc</span>.kr(<span class="s3">ExpRand</span>(0.1, 1)).range(0, 1)}.dup(100);</p>
52 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// Then give them a "rolloff" to make the sound less unpleasant</p>
53 <p class="p5"><span class="Apple-tab-span"> </span>mags = mags<span class="Apple-converted-space">  </span>* ((1, 0.99 .. 0.01).squared);</p>
54 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// Let's turn the bins on and off at different rates, I'm *sure* that'll sound interesting</p>
55 <p class="p5"><span class="Apple-tab-span"> </span>mags = mags * {<span class="s3">LFPulse</span>.kr(2 ** <span class="s3">IRand</span>(-3, 5)).range(0, 1)}.dup(100);</p>
56 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// Let's ignore phase for now</p>
57 <p class="p5"><span class="Apple-tab-span"> </span>phases = 0.dup(100);</p>
58 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// We need to create an FFT chain to feed our data in to.</p>
59 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// The easiest way is to do an FFT on some signal which we then ignore!</p>
60 <p class="p5"><span class="Apple-tab-span"> </span>chain = <span class="s3">FFT</span>(<span class="s3">LocalBuf</span>(512), <span class="s3">FSinOsc</span>.ar);</p>
61 <p class="p4"><span class="s4"><span class="Apple-tab-span"> </span></span>// Now we can do the packing</p>
62 <p class="p5"><span class="Apple-tab-span"> </span>chain = <span class="s3">PackFFT</span>(chain, 512, [mags, phases].flop.flatten, 0, 99, 1);</p>
63 <p class="p5"><span class="Apple-tab-span"> </span>sig = <span class="s3">IFFT</span>(chain);</p>
64 <p class="p5"><span class="Apple-tab-span"> </span><span class="s3">Out</span>.ar(0, sig.dup);</p>
65 <p class="p5">}.play(s);</p>
66 <p class="p5">)</p>
67 <p class="p5">x.free;</p>
68 </body>
69 </html>