File: Crest.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 (70 lines) | stat: -rw-r--r-- 5,385 bytes parent folder | download | duplicates (3)
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
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="824.48">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 13.0px Helvetica}
p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px}
p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
p.p4 {margin: 0.0px 0.0px 0.0px 66.0px; text-indent: -66.0px; font: 12.0px Helvetica}
p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bb0e03}
p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #bf0000}
p.p9 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #000000}
span.s1 {font: 18.0px Helvetica}
span.s2 {color: #0013fe}
span.s3 {text-decoration: underline ; color: #0011ed}
span.s4 {color: #000000}
span.s5 {color: #000ebe}
span.s6 {color: #0000bf}
span.Apple-tab-span {white-space:pre}
</style>
</head>
<body>
<p class="p1"><span class="s1"><b>Crest<span class="Apple-tab-span">	</span><span class="Apple-tab-span">	</span></b></span><b>Measure the temporal crest factor of a signal</b></p>
<p class="p2"><br></p>
<p class="p3"><b>Crest.kr(in, numsamps, gate)</b></p>
<p class="p2"><br></p>
<p class="p3">This UGen measures the "crest factor" of a time-domain signal (not to be confused with <a href="FFTCrest.html"><span class="s2">FFTCrest</span></a> which does the same thing for spectral data). The "crest factor" is the ratio of the absolute peak to the absolute mean over a certain time period. In pseudocode:</p>
<p class="p2"><br></p>
<p class="p3"><span class="Apple-converted-space">      </span>crest = (samples.abs.max) / (samples.abs.mean)</p>
<p class="p2"><span class="Apple-converted-space">      </span></p>
<p class="p3">For <a href="SC://Pulse"><span class="s2">Pulse</span></a> waves the value will be 1 - because the mean and the maximum are the same. For <a href="SC://SinOsc"><span class="s3">SinOsc</span></a> the theoretical value is 2.sqrt. For <a href="SC://Saw"><span class="s2">Saw</span></a> it is 3.sqrt. These exact values might not occur in practice, because of anti-aliasing and other sampling factors.</p>
<p class="p2"><br></p>
<p class="p4"><span class="Apple-tab-span">	</span><b>in</b><span class="Apple-converted-space">  </span>- the signal to analyse. Can be audio rate or control rate.</p>
<p class="p4"><span class="Apple-tab-span">	</span><b>numsamps</b><span class="Apple-converted-space">  </span>- the number of samples over which to take the measurement. A buffer of this size is created internally (so be careful about specifying a massive number here). This value cannot be modulated.</p>
<p class="p4"><span class="Apple-tab-span">	</span><b>gate</b><span class="Apple-converted-space">  </span>- normally the statistic is calculated on every control block cycle. If you want it less often (eg to reduce CPU usage) you can modulate this - calculation only occurs if gate&gt;0</p>
<p class="p2"><br></p>
<p class="p3">The crest factor that is returned is given on a linear scale. Sometimes it is required in dB values, for which you can simply use .<a href="SC://ampdb"><span class="s2">ampdb</span></a> to convert the data.</p>
<p class="p2"><br></p>
<p class="p3">You may also wish to add a slight <b><i>lag</i></b> to the values you produce, if your window is short and/or your signal includes strong low frequencies, because the phase of the signal may affect the result.</p>
<p class="p2"><br></p>
<p class="p3"><b>Example</b></p>
<p class="p2"><br></p>
<p class="p5">s.boot;</p>
<p class="p5">(</p>
<p class="p5">{</p>
<p class="p6"><span class="s4"><span class="Apple-tab-span">	</span></span>// Move the mouse. This varies from sinewave (left) to almost-square (right)</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s5">var</span> sig = (<span class="s5">SinOsc</span>.ar(<span class="s5">MouseY</span>.kr(100, 1000, 1)) * <span class="s5">MouseX</span>.kr(1,10)).clip2(1);</p>
<p class="p5"><span class="Apple-tab-span">	</span><span class="s5">var</span> val = <span class="s5">Crest</span>.kr(sig, 440).poll;</p>
<p class="p5"><span class="Apple-tab-span">	</span>(sig * 0.1).dup</p>
<p class="p5">}.play</p>
<p class="p5">)</p>
<p class="p7"><br></p>
<p class="p5">(</p>
<p class="p8">// Or as a plot (which shows the odd results you get over the first few samples):</p>
<p class="p9">{</p>
<p class="p9"><span class="Apple-tab-span">	</span><span class="s6">var</span> sig = (<span class="s6">SinOsc</span>.ar(440, pi.rand) * <span class="s6">XLine</span>.kr(1,10, 5)).clip2(1);</p>
<p class="p9"><span class="Apple-tab-span">	</span><span class="s6">var</span> val = <span class="s6">Crest</span>.kr(sig, 440).poll;</p>
<p class="p9"><span class="Apple-tab-span">	</span><span class="s6">Out</span>.ar(0, sig * 0.1.dup);</p>
<p class="p9"><span class="Apple-tab-span">	</span><span class="s6">K2A</span>.ar(val);</p>
<p class="p9">}.plot(5, minval:1, maxval: 4)</p>
<p class="p5">)</p>
<p class="p2"><br></p>
</body>
</html>