cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / FFT / SpecPcile.html
blobd7dfa40d210091ee8914236c4de3e17be65bfe7f
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="824.44">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 18.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Monaco; min-height: 15.0px}
12 p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 10.0px Monaco; color: #000000}
18 span.s1 {color: #0522ef}
19 span.s2 {color: #0000bf}
20 span.s3 {color: #606060}
21 span.s4 {font: 9.0px Monaco}
22 span.s5 {color: #000000}
23 span.Apple-tab-span {white-space:pre}
24 </style>
25 </head>
26 <body>
27 <p class="p1"><b>SpecPcile<span class="Apple-tab-span"> </span>Find a percentile of FFT magnitude spectrum</b></p>
28 <p class="p2"><br></p>
29 <p class="p3"><b><span class="Apple-tab-span"> </span>SpecPcile.kr(chain, fraction)</b></p>
30 <p class="p4"><br></p>
31 <p class="p3">Given an <a href="FFT.html"><span class="s1">FFT</span></a> chain this calculates the cumulative distribution of the frequency spectrum, and outputs the frequency value which corresponds to the desired percentile.</p>
32 <p class="p4"><br></p>
33 <p class="p3">For example, to find the frequency at which 90% of the spectral energy lies below that frequency, you want the 90-percentile, which means the value of <i>fraction</i> should be 0.9. The 90-percentile or 95-percentile is often used as a measure of <b><i>spectral roll-off</i></b>.</p>
34 <p class="p4"><br></p>
35 <p class="p3">The optional third argument <b>interpolate</b> specifies whether interpolation should be used to try and make the percentile frequency estimate more accurate, at the cost of a little higher CPU usage. Set it to 1 to enable this.</p>
36 <p class="p4"><br></p>
37 <p class="p4"><br></p>
38 <p class="p3"><b>Examples:</b></p>
39 <p class="p2"><br></p>
40 <p class="p5">s = <span class="s2">Server</span>.internal.boot;<span class="Apple-converted-space"> </span></p>
41 <p class="p5">b = <span class="s2">Buffer</span>.alloc(s,2048,1);</p>
42 <p class="p6"><br></p>
43 <p class="p7">// Simple demo with filtering white noise, and trying to infer the cutoff freq.</p>
44 <p class="p7">// Move the mouse.</p>
45 <p class="p5">(</p>
46 <p class="p5">{</p>
47 <p class="p5"><span class="s2">var</span> in, chain, realcutoff, estcutoff;</p>
48 <p class="p5">realcutoff = <span class="s2">MouseX</span>.kr(0.00001,22050);</p>
49 <p class="p5">in = <span class="s2">LPF</span>.ar(<span class="s2">WhiteNoise</span>.ar, realcutoff);</p>
50 <p class="p5">chain = <span class="s2">FFT</span>(b, in);</p>
51 <p class="p5">estcutoff = <span class="s2">Lag</span>.kr(<span class="s2">SpecPcile</span>.kr(chain, 0.9), 1);</p>
52 <p class="p5">realcutoff.poll(<span class="s2">Impulse</span>.kr(1), <span class="s3">"real cutoff"</span>);</p>
53 <p class="p5">estcutoff.poll(<span class="s2">Impulse</span>.kr(1), <span class="s3">"estimated cutoff"</span>);</p>
54 <p class="p5"><span class="s2">Out</span>.ar(0, in);</p>
55 <p class="p5"><span class="s2">Out</span>.kr(0, estcutoff * 22050.0.reciprocal);</p>
56 <p class="p5">}.scope;</p>
57 <p class="p5">)</p>
58 <p class="p6"><br></p>
59 <p class="p7">// Audio input - try different vowel/long-consonant sounds and see what comes out.</p>
60 <p class="p7">// Specifically, change from "ssss" through to "aaaa" through to "wwww".</p>
61 <p class="p5">(</p>
62 <p class="p5">{</p>
63 <p class="p5"><span class="s2">var</span> in, chain, perc;</p>
64 <p class="p5">in = <span class="s2">SoundIn</span>.ar([0,1]).mean;</p>
65 <p class="p5">chain = <span class="s2">FFT</span>(b, in);</p>
66 <p class="p7">//Out.ar(0, in * 0.1);</p>
67 <p class="p8"><span class="s4">perc = </span><span class="s2">SpecPcile</span>.kr(chain, 0.5);</p>
68 <p class="p7"><span class="s2">Out</span><span class="s5">.ar(1, </span><span class="s2">LPF</span><span class="s5">.ar(</span><span class="s2">WhiteNoise</span><span class="s5">.ar, perc)); </span>//NB Outputting to right channel - handy on PowerBooks</p>
69 <p class="p5"><span class="s2">Out</span>.kr(0, perc * 22050.0.reciprocal);</p>
70 <p class="p5">}.scope;</p>
71 <p class="p5">)</p>
72 </body>
73 </html>