File: FFTFlux.html

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 (80 lines) | stat: -rw-r--r-- 5,421 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<!-- Translation from RTF performed by UnRTF, version 0.21.9 -->
<!--font table contains 0 fonts total-->
<!--invalid font number 0-->
</head>
<body><b><font size="5"><font color="#000000">FFTFlux - Spectral flux statistic<!--invalid font number 1-->
</font></font></b><font size="5"><font color="#000000"><span style="font-size:17pt"><br>
</span></font></font><span style="font-size:11pt"><font color="#000000"><br>
<!--invalid font number 0-->
<b><font size="3"> FFTFlux.kr(chain)<br>
<!--invalid font number 2-->
</font></b><font size="3"><br>
Calculates the<!--invalid font number 0-->
<b>spectral flux<!--invalid font number 2-->
</b> of the signal, which is a measure of the rate of change of the FFT power spectrum. It measures the difference between the current and previous FFT frames, by calculating the 2-norm (the Euclidean distance between the two spectra) after normalising for power.<br>
<br>
For example, a stationary sine wave (or triangle, square, ...) would be expected to exhibit near-zero spectral flux (zero if the period fits neatly into the FFT windowing period). But the boundary between two different musical notes would often be expected to exhibit a peak in spectral flux.<br>
<br>
The comparison is frame-by-frame, so its behaviour will depend to some extent upon your frame size. Also note that this measure only makes sense when used with a continuous stream of FFT frames - so it should be used with the normal [<u>FFT</u>] UGen, not with [<u>FFTTriggered</u>].<br>
<br>
Examples:<br>
</font></font></span><!--invalid font number 1-->
<span style="font-size:9pt"><font color="#000000"><br>
s = <font color="#0000bf">Server<font color="#000000">.internal.boot; <br>
b = <font color="#0000bf">Buffer<font color="#000000">.alloc(s,2048,1);<br>
<br>
<font color="#bf0000">// Move the mouse to vary the frequency.<font color="#000000"><br>
<font color="#bf0000">// Watch the scope to see the change in sp.flux.<font color="#000000"><br>
<font color="#bf0000">// You'll see that it's higher when freq is changing.<font color="#000000"><br>
(<br>
x = {<br>
<font color="#0000bf">var<font color="#000000"> in, chain, flux;<br>
in = <font color="#0000bf">SinOsc<font color="#000000">.ar(<font color="#0000bf">MouseX<font color="#000000">.kr(50, 500, 1), 0, 0.1);<br>
chain = <font color="#0000bf">FFT<font color="#000000">(b.bufnum, in);<br>
flux = <font color="#0000bf">FFTFlux<font color="#000000">.kr(chain, 0.9) * 100; <font color="#bf0000">// Scale by 100 for more humane numbers<font color="#000000"><br>
flux.poll(1, <font color="#606060">&quot;Flux&quot;<font color="#000000">);<br>
<font color="#0000bf">Out<font color="#000000">.ar(0, in.dup);<br>
<font color="#0000bf">Out<font color="#000000">.kr(0, flux);<br>
}.scope;<br>
)<br>
<br>
x.free;<br>
<br>
<br>
<font color="#bf0000">// Same again, but with filtered white noise.<font color="#000000"><br>
<font color="#bf0000">// White noise naturally has a significant level of spectral flux<font color="#000000"><br>
<font color="#bf0000">// but again, the flux is much higher while the spectral qualities are changing.<font color="#000000"><br>
(<br>
x = {<br>
<font color="#0000bf">var<font color="#000000"> in, chain, flux;<br>
in = <font color="#0000bf">LPF<font color="#000000">.ar(<font color="#0000bf">WhiteNoise<font color="#000000">.ar(0.1), <font color="#0000bf">MouseX<font color="#000000">.kr(50, 5000, 1));<br>
chain = <font color="#0000bf">FFT<font color="#000000">(b.bufnum, in);<br>
flux = <font color="#0000bf">FFTFlux<font color="#000000">.kr(chain, 0.9) * 100; <font color="#bf0000">// Scale by 100 for more humane numbers<font color="#000000"><br>
flux.poll(1, <font color="#606060">&quot;Flux&quot;<font color="#000000">);<br>
<font color="#0000bf">Out<font color="#000000">.ar(0, in.dup);<br>
<font color="#0000bf">Out<font color="#000000">.kr(0, flux);<br>
}.scope;<br>
)<br>
<br>
x.free;<br>
<br>
<br>
<font color="#bf0000">// Now you try it! Audio input. NB this time we're taking the log because real signals vary a lot.<font color="#000000"><br>
(<font color="#000000"><br>
x = {<br>
<font color="#0000bf">var<font color="#000000"> in, chain, flux;<br>
in = <font color="#0000bf">AudioIn<font color="#000000">.ar([1,2]).mean;<br>
chain = <font color="#0000bf">FFT<font color="#000000">(b.bufnum, in);<br>
flux = (<font color="#0000bf">FFTFlux<font color="#000000">.kr(chain, 0.9) * 100).log * 0.2;<br>
flux = flux.max(-100); <font color="#bf0000">// This is to avoid an infinity created by the log UGen<font color="#000000"><br>
flux.poll(1, <font color="#606060">&quot;Log flux&quot;<font color="#000000">);<br>
<font color="#0000bf">Out<font color="#000000">.kr(0, flux);<br>
}.scope;<br>
<font color="#000000">)<br>
<br>
x.free;</font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></font></span></body>
</html>