1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
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 span
.s1
{color: #1531e8}
18 span
.s2
{color: #0000bf}
19 span
.s3
{color: #000000}
20 span
.s4
{color: #bf0000}
21 span
.s5
{color: #606060}
22 span
.Apple-tab-span
{white-space:pre
}
26 <p class=
"p1"><b>SpecFlatness
<span class=
"Apple-tab-span"> </span>Spectral Flatness measure
</b></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p3"><b><span class=
"Apple-tab-span"> </span>SpecFlatness.kr(chain)
</b></p>
29 <p class=
"p4"><br></p>
30 <p class=
"p3">Given an
<a href=
"FFT.html"><span class=
"s1">FFT
</span></a> chain this calculates the
<i>Spectral Flatness
</i> measure, defined as a power spectrum's geometric mean divided by its arithmetic mean. This gives a measure which ranges from approx
0 for a pure sinusoid, to approx
1 for white noise.
</p>
31 <p class=
"p4"><br></p>
32 <p class=
"p3">The measure is calculated linearly. For some applications you may wish to convert the value to a decibel scale - an example of such conversion is shown below.
</p>
33 <p class=
"p4"><br></p>
34 <p class=
"p4"><br></p>
35 <p class=
"p3"><b>Examples
</b></p>
36 <p class=
"p2"><br></p>
37 <p class=
"p5">s =
<span class=
"s2">Server
</span>.internal.boot;
</p>
38 <p class=
"p5">b =
<span class=
"s2">Buffer
</span>.alloc(s,
2048,
1);
</p>
39 <p class=
"p6"><br></p>
41 <p class=
"p7"><span class=
"s3">{
</span>// Example - vary mixture of white noise and pure tone with the mouse
</p>
42 <p class=
"p5"><span class=
"s2">var
</span> in, chain, flat, flatdb, flatdbsquish;
</p>
43 <p class=
"p5">in =
<span class=
"s2">XFade2
</span>.ar(
<span class=
"s2">WhiteNoise
</span>.ar,
<span class=
"s2">SinOsc
</span>.ar,
<span class=
"s2">MouseX
</span>.kr(-
1,
1));
</p>
44 <p class=
"p5">chain =
<span class=
"s2">FFT
</span>(b, in);
</p>
45 <p class=
"p5"><span class=
"s2">Out
</span>.ar(
0, in *
0.1);
</p>
46 <p class=
"p6"><br></p>
47 <p class=
"p5">flat =
<span class=
"s2">SpecFlatness
</span>.kr(chain);
</p>
48 <p class=
"p6"><br></p>
49 <p class=
"p5">flatdb =
10 * flat.log;
<span class=
"s4">// Convert to decibels
</span></p>
50 <p class=
"p5">flatdbsquish =
<span class=
"s2">LinLin
</span>.kr(flatdb, -
45, -
1.6,
0,
1).max(-
10);
<span class=
"s4">// Rescale db roughly to
0..
.1.
</span></p>
51 <p class=
"p6"><br></p>
52 <p class=
"p5">flat.poll(
10,
<span class=
"s5">"flatness: "</span>);
</p>
53 <p class=
"p5">flatdb.poll(
10,
<span class=
"s5">"flatness (db): "</span>);
</p>
54 <p class=
"p6"><br></p>
55 <p class=
"p5"><span class=
"s2">Out
</span>.kr(
0, [flat, flatdbsquish]);
</p>
56 <p class=
"p5">}.scope;
</p>
58 <p class=
"p6"><br></p>
60 <p class=
"p7"><span class=
"s3">{
</span>// Now try with your own voice
</p>
61 <p class=
"p5"><span class=
"s2">var
</span> in, chain;
</p>
62 <p class=
"p5">in =
<span class=
"s2">SoundIn
</span>.ar([
0,
1]).mean;
</p>
63 <p class=
"p5">chain =
<span class=
"s2">FFT
</span>(b, in);
</p>
64 <p class=
"p5"><span class=
"s2">Out
</span>.kr(
0, [in,
<span class=
"s2">SpecFlatness
</span>.kr(chain).poll(
1,
<span class=
"s5">"flatness: "</span>)]);
</p>
65 <p class=
"p5">}.scope;
</p>