cmake build system: visiblity support for clang
[supercollider.git] / Help / UGens / FFT / PV_HainsworthFoote.html
blob41927acecddf842f304652477b5ff5b948668434
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="949.35">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 22.0px Helvetica}
11 p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.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; color: #0021e7}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #ad140d}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
18 p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
19 p.p10 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #001bb9}
20 p.p11 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000; min-height: 12.0px}
21 p.p12 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
22 span.s1 {color: #000000}
23 span.s2 {text-decoration: underline}
24 span.s3 {color: #001bb9}
25 span.s4 {color: #0000bf}
26 span.Apple-tab-span {white-space:pre}
27 </style>
28 </head>
29 <body>
30 <p class="p1"><b>PV_HainsworthFoote</b></p>
31 <p class="p2"><br></p>
32 <p class="p3">FFT onset detector based on work described in<span class="Apple-converted-space"> </span></p>
33 <p class="p2"><br></p>
34 <p class="p3">Hainsworth, S. (2003) Techniques for the Automated Analysis of Musical Audio. PhD, University of Cambridge engineering dept. See especially p128. The Hainsworth metric is a modification of the Kullback Liebler distance.<span class="Apple-converted-space"> </span></p>
35 <p class="p2"><br></p>
36 <p class="p3">The onset detector has general ability to spot spectral change, so may have some ability to track chord changes<span class="Apple-converted-space">  </span>aside from obvious transient jolts, but there's no guarantee it won't be confused by frequency modulation artifacts.<span class="Apple-converted-space">   </span></p>
37 <p class="p2"><br></p>
38 <p class="p3">Hainsworth metric on it's own gives good results but Foote might be useful in some situations: experimental.<span class="Apple-converted-space"> </span></p>
39 <p class="p2"><br></p>
40 <p class="p2"><br></p>
41 <p class="p3"><b>*ar(buffer, proph=0.0, propf=0.0, threshold=1.0, waittime=0.04)</b></p>
42 <p class="p2"><br></p>
43 <p class="p3"><b>buffer-</b> FFT buffer to read from</p>
44 <p class="p2"><br></p>
45 <p class="p3"><b>proph-</b> What strength of detection signal from Hainsworth metric to use.</p>
46 <p class="p2"><br></p>
47 <p class="p3"><b>propf-</b> What strength of detection signal from Foote metric to use. The Foote metric is normalised to [0.0,1.0]</p>
48 <p class="p2"><br></p>
49 <p class="p3"><b>threshold-</b> Threshold hold level for allowing a detection</p>
50 <p class="p2"><br></p>
51 <p class="p3"><b>waittime-</b> If triggered, minimum wait until a further frame can cause another spot (useful to stop multiple detects on heavy signals)</p>
52 <p class="p2"><br></p>
53 <p class="p4"><span class="s1">See also <a href="FFT Overview.html"><span class="s2">FFT Overview</span></a>.</span></p>
54 <p class="p2"><br></p>
55 <p class="p5"><br></p>
56 <p class="p5"><br></p>
57 <p class="p6">// Examples</p>
58 <p class="p7"><br></p>
59 <p class="p7"><br></p>
60 <p class="p6">// just Hainsworth metric with low threshold</p>
61 <p class="p8">// external sound in</p>
62 <p class="p9">(</p>
63 <p class="p9">{</p>
64 <p class="p9"><span class="Apple-tab-span"> </span><span class="s3">var</span> source1, signal, detect;</p>
65 <p class="p7"><span class="Apple-tab-span"> </span></p>
66 <p class="p9"><span class="Apple-tab-span"> </span>source1 = <span class="s3">SoundIn</span>.ar(0);</p>
67 <p class="p9"><span class="Apple-tab-span"> </span>detect = <span class="s3">PV_HainsworthFoote</span>.ar(<span class="s3">FFT</span>(<span class="s3">LocalBuf</span>(2048), source1), 1.0, 0.0);</p>
68 <p class="p9"><span class="Apple-tab-span"> </span>signal = <span class="s3">SinOsc</span>.ar([440,445], 0, <span class="s3">Decay</span>.ar(0.1 * detect, 0.1));</p>
69 <p class="p10"><span class="s1"><span class="Apple-tab-span"> </span></span>signal</p>
70 <p class="p9">}.play;<span class="Apple-tab-span"> </span></p>
71 <p class="p9">)<span class="Apple-tab-span"> </span></p>
72 <p class="p7"><br></p>
73 <p class="p7"><br></p>
74 <p class="p11"><br></p>
75 <p class="p8">// spot note transitions<span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
76 <p class="p12">(</p>
77 <p class="p12">{</p>
78 <p class="p12"><span class="Apple-converted-space"> </span><span class="s4">var</span> source1, signal, detect;</p>
79 <p class="p11"><span class="Apple-tab-span"> </span></p>
80 <p class="p12"><span class="Apple-tab-span"> </span>source1 = <span class="s4">LFSaw</span>.ar(<span class="s4">LFNoise0</span>.kr(1, 90, 400), 0, 0.5);</p>
81 <p class="p12"><span class="Apple-tab-span"> </span>detect = <span class="s4">PV_HainsworthFoote</span>.ar(<span class="s4">FFT</span>(<span class="s4">LocalBuf</span>(2048), source1), 1.0, 0.0, 0.9, 0.5);</p>
82 <p class="p12"><span class="Apple-tab-span"> </span>signal = <span class="s4">SinOsc</span>.ar(440, 0, <span class="s4">Decay</span>.ar(0.1 * detect, 0.1));</p>
83 <p class="p12"><span class="Apple-tab-span"> </span>[source1, signal];</p>
84 <p class="p12">}.play;<span class="Apple-tab-span"> </span></p>
85 <p class="p12">)</p>
86 <p class="p11"><br></p>
87 <p class="p8">// not so sucessful with this test sound:<span class="Apple-converted-space"> </span></p>
88 <p class="p8">// mouse y is difficulty, mouse x is threshold</p>
89 <p class="p12">(</p>
90 <p class="p12">{</p>
91 <p class="p12"><span class="Apple-tab-span"> </span><span class="s4">var</span> source1, detect, difficulty, rate, trig, n = 20;</p>
92 <p class="p12"><span class="Apple-tab-span"> </span>rate = <span class="s4">LFNoise1</span>.kr(0.3).exprange(1, 5);</p>
93 <p class="p12"><span class="Apple-tab-span"> </span>difficulty = <span class="s4">MouseY</span>.kr(0, 1);</p>
94 <p class="p12"><span class="Apple-tab-span"> </span>trig = <span class="s4">Impulse</span>.kr(rate);</p>
95 <p class="p12"><span class="Apple-tab-span"> </span>source1 = { <span class="s4">|i|</span></p>
96 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">var</span> t = <span class="s4">CoinGate</span>.kr(1 - difficulty, trig);</p>
97 <p class="p12"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s4">SinOsc</span>.ar(<span class="s4">TExpRand</span>.kr(300, 1000, t) * (i + 1)) * <span class="s4">TRand</span>.kr(0, 1, t)<span class="Apple-converted-space"> </span></p>
98 <p class="p12"><span class="Apple-tab-span"> </span>}.dup(10).sum;</p>
99 <p class="p8"><span class="s1"><span class="Apple-tab-span"> </span></span>// source1 = source1 * Decay.kr(trig, 0.5);</p>
100 <p class="p12"><span class="Apple-tab-span"> </span>detect = <span class="s4">PV_HainsworthFoote</span>.ar(<span class="s4">FFT</span>(<span class="s4">LocalBuf</span>(2048), source1), threshold: <span class="s4">MouseX</span>.kr(0.01, 1.0));</p>
101 <p class="p12"><span class="Apple-tab-span"> </span><span class="s4">WhiteNoise</span>.ar * <span class="s4">Decay</span>.ar(detect, 0.1) + (source1 * 0.2);</p>
102 <p class="p12">}.play;<span class="Apple-tab-span"> </span></p>
103 <p class="p12">)</p>
104 <p class="p11"><br></p>
105 <p class="p11"><br></p>
106 <p class="p6">// tests using sound in</p>
107 <p class="p7"><br></p>
108 <p class="p6">// Foote solo - never triggers with threshold over 1.0, threshold under mouse control</p>
109 <p class="p5"><span class="Apple-tab-span"> </span></p>
110 <p class="p9">(</p>
111 <p class="p9">{</p>
112 <p class="p9"><span class="Apple-converted-space"> </span><span class="s3">var</span> source1, signal, detect;</p>
113 <p class="p7"><span class="Apple-tab-span"> </span></p>
114 <p class="p9"><span class="Apple-tab-span"> </span>source1 = <span class="s3">SoundIn</span>.ar(0);<span class="Apple-converted-space"> </span></p>
115 <p class="p7"><span class="Apple-tab-span"> </span></p>
116 <p class="p9"><span class="Apple-tab-span"> </span>detect = <span class="s3">PV_HainsworthFoote</span>.ar(<span class="s3">FFT</span>(<span class="s3">LocalBuf</span>(2048), source1), 0.0, 1.0,<span class="Apple-converted-space"> </span></p>
117 <p class="p9"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s3">MouseX</span>.kr(0.0,1.1), 0.02);</p>
118 <p class="p9"><span class="Apple-tab-span"> </span>signal = <span class="s3">SinOsc</span>.ar(440, 0, <span class="s3">Decay</span>.ar(0.1 * detect, 0.1));</p>
119 <p class="p9"><span class="Apple-tab-span"> </span>[source1, signal];</p>
120 <p class="p9">}.play;<span class="Apple-tab-span"> </span></p>
121 <p class="p9">)</p>
122 <p class="p7"><br></p>
123 <p class="p7"><br></p>
124 <p class="p6">// compare to Amplitude UGen</p>
125 <p class="p9">(</p>
126 <p class="p9">{</p>
127 <p class="p9"><span class="Apple-converted-space"> </span><span class="s3">var</span> source1, signal, detect;</p>
128 <p class="p7"><span class="Apple-tab-span"> </span></p>
129 <p class="p9"><span class="Apple-tab-span"> </span>source1= <span class="s3">SoundIn</span>.ar(0);<span class="Apple-converted-space"> </span></p>
130 <p class="p7"><span class="Apple-tab-span"> </span></p>
131 <p class="p9"><span class="Apple-tab-span"> </span>detect= (<span class="s3">Amplitude</span>.ar(source1)) &gt; (<span class="s3">MouseX</span>.kr(0.0,1.1));</p>
132 <p class="p9"><span class="Apple-tab-span"> </span>signal = <span class="s3">SinOsc</span>.ar(440, 0, <span class="s3">Decay</span>.ar(0.1 * detect, 0.1));</p>
133 <p class="p9"><span class="Apple-tab-span"> </span>[source1, signal];</p>
134 <p class="p9">}.play;<span class="Apple-tab-span"> </span></p>
135 <p class="p9">)</p>
136 <p class="p7"><br></p>
137 <p class="p7"><br></p>
138 <p class="p7"><br></p>
139 <p class="p7"><br></p>
140 <p class="p7"><br></p>
141 <p class="p7"><br></p>
142 <p class="p7"><br></p>
143 </body>
144 </html>