File: FFTCrest.schelp

package info (click to toggle)
supercollider-sc3-plugins 3.7.1~repack-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,332 kB
  • ctags: 11,704
  • sloc: cpp: 140,180; lisp: 14,746; ansic: 2,133; xml: 86; makefile: 82; haskell: 21; sh: 8
file content (58 lines) | stat: -rw-r--r-- 1,717 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
CLASS:: FFTCrest
summary:: Spectral crest measure
categories:: UGens>Analysis, UGens>FFT

DESCRIPTION::
Given an FFT chain, this produces the spectral crest measure, which is an indicator of the "peakiness" of the spectral energy distribution. For example, white noise should produce a flat (non-peaky) spectrum, and therefore a low value for the spectral crest.

Optionally, freqlo and freqhi indicate the lower and upper frequency limits of the band to look at; by default, the whole FFT range (excluding DC and nyquist) is analysed.

In pseudo-equation form, the measure is calculated as follows:

Crest = S.maxItem / S.mean

where "S" is a list of the squared magnitudes in the spectral band. Note that this limits the value to being greater than or equal to 1. (Some research uses a logarithmic scale - you can apply the logarithm yourself if required.)

CLASSMETHODS::

METHOD:: kr
argument:: chain
FFT chain
argument:: freqlo
argument:: freqhi


EXAMPLES::

code::
s.boot;
b = Buffer.alloc(s,2048,1);

(
{ // Example - vary mixture of white noise and pure tone with the mouse
var in, chain, crest;
in = XFade2.ar(WhiteNoise.ar, SinOsc.ar, MouseX.kr(-1,1));
chain = FFT(b.bufnum, in);
Out.ar(0, in.dup * 0.1);

crest = FFTCrest.kr(chain);

Out.kr(0, crest.poll(10, "crest"));
}.play;
)

(
{ // Same as above but subbands rather than whole spectrum. move mouse up&down too...
var in, chain, crest1, crest2;
in = XFade2.ar(WhiteNoise.ar, Blip.ar(numharm: MouseY.kr(200, 1, 1)), MouseX.kr(-1,1));
chain = FFT(b.bufnum, in);
Out.ar(0, in.dup * 0.1);

crest1 = FFTCrest.kr(chain, 100, 2000);
crest2 = FFTCrest.kr(chain, 2000, 10000);

Out.kr(0, [crest1.poll(10, "crest1"), crest2.poll(10, "crest2")]);
}.play;
)
::