2 summary:: Spectral Flatness measure
4 related:: Classes/SpecCentroid, Classes/SpecPcile
7 Given an link::Classes/FFT:: strong::chain:: this calculates the emphasis::Spectral Flatness:: 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.
9 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.
15 an link::Classes/FFT:: chain.
20 s = Server.internal.boot;
21 b = Buffer.alloc(s,2048,1);
24 { // Example - vary mixture of white noise and pure tone with the mouse
25 var in, chain, flat, flatdb, flatdbsquish;
26 in = XFade2.ar(WhiteNoise.ar, SinOsc.ar, MouseX.kr(-1,1));
30 flat = SpecFlatness.kr(chain);
32 flatdb = 10 * flat.log; // Convert to decibels
33 flatdbsquish = LinLin.kr(flatdb, -45, -1.6, 0, 1).max(-10); // Rescale db roughly to 0...1.
35 flat.poll(10, "flatness: ");
36 flatdb.poll(10, "flatness (db): ");
38 Out.kr(0, [flat, flatdbsquish]);
43 { // Now try with your own voice
45 in = SoundIn.ar([0,1]).mean;
47 Out.kr(0, [in, SpecFlatness.kr(chain).poll(1, "flatness: ")]);