supernova: fixes for boost-1.49 and gcc-4.7
[supercollider.git] / Help / UGens / Filters / AmpComp.html
blobc2a2c7a0a232524c3c48a9698d835fa3430dd4b4
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="824.41">
9 <style type="text/css">
10 p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.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: 11.0px Monaco}
13 p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; min-height: 12.0px}
14 p.p5 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #982316; min-height: 12.0px}
15 p.p6 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #982316}
16 p.p7 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco}
17 p.p8 {margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco; color: #0025b2}
18 span.s1 {font: 18.0px Helvetica}
19 span.s2 {font: 9.0px Monaco}
20 span.s3 {font: 12.0px Helvetica}
21 span.s4 {color: #0024f8}
22 span.s5 {color: #0025b2}
23 span.s6 {color: #000000}
24 span.s7 {color: #606060}
25 span.s8 {color: #416d1f}
26 span.Apple-tab-span {white-space:pre}
27 </style>
28 </head>
29 <body>
30 <p class="p1"><span class="s1"><b>AmpComp</b></span><span class="s2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></span><b>basic psychoacoustic amplitude compensation</b></p>
31 <p class="p2"><br></p>
32 <p class="p2"><br></p>
33 <p class="p1">superclass: UGen</p>
34 <p class="p2"><br></p>
35 <p class="p3"><span class="s3"><span class="Apple-tab-span"> </span>implements the (optimized) formula: <span class="Apple-tab-span"> </span></span>compensationFactor = (root / freq) ** exp<span class="Apple-converted-space"> </span></p>
36 <p class="p2"><span class="Apple-tab-span"> </span></p>
37 <p class="p1"><span class="Apple-tab-span"> </span>Higher frequencies are normally perceived as louder, which AmpComp compensates.<span class="Apple-converted-space"> </span></p>
38 <p class="p2"><span class="Apple-tab-span"> </span></p>
39 <p class="p1"><span class="Apple-tab-span"> </span>see also <a href="AmpCompA.html"><span class="s4">AmpCompA</span></a></p>
40 <p class="p2"><br></p>
41 <p class="p1"><b><span class="Apple-tab-span"> </span>*ar(freq, root, exp)</b></p>
42 <p class="p1"><b><span class="Apple-tab-span"> </span>*kr(freq, root, exp)</b></p>
43 <p class="p1"><b><span class="Apple-tab-span"> </span>*ir(freq, root, exp)</b></p>
44 <p class="p2"><span class="Apple-tab-span"> </span></p>
45 <p class="p1"><span class="Apple-tab-span"> </span><b>freq</b> <span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>input frequency value. For freq == root, the output is 1.0.</p>
46 <p class="p1"><span class="Apple-tab-span"> </span><b>root</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>root freq relative to which the curve is calculated (usually lowest freq)</p>
47 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>default value: C (60.midicps)</p>
48 <p class="p1"><span class="Apple-tab-span"> </span><b>exp</b><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>exponent: how steep the curve decreases for increasing freq (see plots below)</p>
49 <p class="p1"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>default value 0.3333</p>
50 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
51 <p class="p1"><span class="Apple-tab-span"> </span>Note that for frequencies <b>very much smaller than root </b>the amplitudes can become very high.<span class="Apple-converted-space"> </span></p>
52 <p class="p1"><span class="Apple-tab-span"> </span>In this case limit the freq with <b>freq.max(minval)</b>, or use AmpCompA.</p>
53 <p class="p2"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span></p>
54 <p class="p4"><span class="Apple-tab-span"> </span></p>
55 <p class="p2"><br></p>
56 <p class="p4"><br></p>
57 <p class="p5"><br></p>
58 <p class="p5"><br></p>
59 <p class="p6">// compare a sine without compensation</p>
60 <p class="p4"><br></p>
61 <p class="p7">{ <span class="s5">SinOsc</span>.ar(<span class="s5">MouseX</span>.kr(300, 15000, 1)) * 0.1 }.play;</p>
62 <p class="p4"><br></p>
63 <p class="p6">// with one that uses amplitude compensation</p>
64 <p class="p7">(</p>
65 <p class="p7">{<span class="Apple-converted-space"> </span></p>
66 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">var</span> freq;</p>
67 <p class="p7"><span class="Apple-tab-span"> </span>freq = <span class="s5">MouseX</span>.kr(300, 15000, 1);</p>
68 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq) * 0.1 * <span class="s5">AmpComp</span>.kr(freq, 300)<span class="Apple-converted-space"> </span></p>
69 <p class="p7">}.play;</p>
70 <p class="p7">)</p>
71 <p class="p4"><br></p>
72 <p class="p4"><br></p>
73 <p class="p6">// different sounds cause quite different loudness perception,<span class="Apple-converted-space"> </span></p>
74 <p class="p6">// and the desired musical behavior can vary, so the exponent can be tuned:</p>
75 <p class="p7">(</p>
76 <p class="p7">{<span class="Apple-converted-space"> </span></p>
77 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">var</span> freq;</p>
78 <p class="p7"><span class="Apple-tab-span"> </span>freq = <span class="s5">MouseX</span>.kr(300, 15000, 1);</p>
79 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">Pulse</span>.ar(freq) * 0.1 * <span class="s5">AmpComp</span>.kr(freq, 300, 1.3)<span class="Apple-converted-space"> </span></p>
80 <p class="p7">}.play;</p>
81 <p class="p7">)</p>
82 <p class="p4"><br></p>
83 <p class="p6">// the curves:</p>
84 <p class="p4"><br></p>
85 <p class="p7">// exp = 0.3333</p>
86 <p class="p7">(200,210..10000).collect {<span class="s5">|freq|</span> (200/freq) ** 0.3333 }.plot;</p>
87 <p class="p4"><br></p>
88 <p class="p6">// nearly linear for semitone steps:</p>
89 <p class="p4"><br></p>
90 <p class="p7">(48..72).midicps.collect {<span class="s5">|freq|</span> (48.midicps/freq) ** 0.3333 }.plot;<span class="Apple-converted-space"> </span></p>
91 <p class="p7">{ <span class="s5">AmpComp</span>.ar(<span class="s5">Line</span>.ar(48, 72, 1).midicps, 48.midicps) }.plot(1.0);</p>
92 <p class="p4"><br></p>
93 <p class="p6">// exp = 1.2</p>
94 <p class="p7">(200,210..10000).collect {<span class="s5">|freq|</span> (200/freq) ** 1.2 }.plot;</p>
95 <p class="p7">(48..72).midicps.collect {<span class="s5">|freq|</span> (200/freq) ** 1.2 }.plot;</p>
96 <p class="p7">{ <span class="s5">AmpComp</span>.ar(<span class="s5">Line</span>.ar(48, 72, 1).midicps, 48.midicps, 1.2) }.plot(1.0);</p>
97 <p class="p4"><br></p>
98 <p class="p4"><br></p>
99 <p class="p6">// amplitude compensation in frequency modulation</p>
100 <p class="p7">(</p>
101 <p class="p7">{<span class="Apple-converted-space"> </span></p>
102 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">var</span> freq;</p>
103 <p class="p7"><span class="Apple-tab-span"> </span>freq = <span class="s5">MouseX</span>.kr(300, 15000, 1);</p>
104 <p class="p7"><span class="Apple-tab-span"> </span>freq = freq * <span class="s5">SinOsc</span>.ar(<span class="s5">MouseY</span>.kr(3, 200, 1), 0, 0.5, 1);</p>
105 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq) * 0.1 * <span class="s5">AmpComp</span>.ar(freq, 300)<span class="Apple-converted-space"> </span></p>
106 <p class="p7">}.play;</p>
107 <p class="p7">)</p>
108 <p class="p4"><br></p>
109 <p class="p6">// without amplitude compensation</p>
110 <p class="p7">(</p>
111 <p class="p7">{<span class="Apple-converted-space"> </span></p>
112 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">var</span> freq;</p>
113 <p class="p7"><span class="Apple-tab-span"> </span>freq = <span class="s5">MouseX</span>.kr(300, 15000, 1);</p>
114 <p class="p7"><span class="Apple-tab-span"> </span>freq = freq * <span class="s5">SinOsc</span>.ar(<span class="s5">MouseY</span>.kr(3, 200, 1), 0, 0.5, 1);</p>
115 <p class="p7"><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq) * 0.1</p>
116 <p class="p7">}.play;</p>
117 <p class="p7">)</p>
118 <p class="p4"><br></p>
119 <p class="p6">// in granular synthesis:</p>
120 <p class="p7">(</p>
121 <p class="p8">SynthDef<span class="s6">(</span><span class="s7">"pgrain"</span><span class="s6">,<span class="Apple-converted-space"> </span></span></p>
122 <p class="p7"><span class="Apple-tab-span"> </span>{ <span class="s5">arg</span> out = 0, sustain=0.01, amp=0.5, pan = 0;</p>
123 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>var freq = MouseX.kr(300, 7000, 1);</p>
124 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>var window = <span class="s5">Env</span>.sine(sustain, amp * <span class="s5">AmpComp</span>.ir(freq));</p>
125 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Out</span>.ar(out,<span class="Apple-converted-space"> </span></p>
126 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Pan2</span>.ar(</p>
127 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq),</p>
128 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>pan</p>
129 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>) * <span class="s5">EnvGen</span>.ar(window, doneAction:2)</p>
130 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
131 <p class="p7"><span class="Apple-tab-span"> </span>}</p>
132 <p class="p7">).send(s);</p>
133 <p class="p7">)</p>
134 <p class="p4"><br></p>
135 <p class="p6">// send grains</p>
136 <p class="p7">(</p>
137 <p class="p7">fork {</p>
138 <p class="p7"><span class="Apple-tab-span"> </span>loop {</p>
139 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>s.sendBundle(0.1, [<span class="s8">\s_new</span>, <span class="s8">\pgrain</span>, -1,1,1]);</p>
140 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>0.02.wait;</p>
141 <p class="p7"><span class="Apple-tab-span"> </span>};</p>
142 <p class="p7">}</p>
143 <p class="p7">)</p>
144 <p class="p4"><br></p>
145 <p class="p4"><br></p>
146 <p class="p6">// try different synth defs:</p>
147 <p class="p5"><br></p>
148 <p class="p4"><br></p>
149 <p class="p6">// without AmpComp:</p>
150 <p class="p4"><br></p>
151 <p class="p7">(</p>
152 <p class="p8">SynthDef<span class="s6">(</span><span class="s7">"pgrain"</span><span class="s6">,<span class="Apple-converted-space"> </span></span></p>
153 <p class="p7"><span class="Apple-tab-span"> </span>{ <span class="s5">arg</span> out = 0, sustain=0.01, amp=0.5, pan = 0;</p>
154 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">var</span> freq = <span class="s5">MouseX</span>.kr(300, 7000, 1);</p>
155 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">var</span> window = <span class="s5">Env</span>.sine(sustain, amp);</p>
156 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Out</span>.ar(out,<span class="Apple-converted-space"> </span></p>
157 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Pan2</span>.ar(</p>
158 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq),</p>
159 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>pan</p>
160 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>) * <span class="s5">EnvGen</span>.ar(window, doneAction:2)</p>
161 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
162 <p class="p7"><span class="Apple-tab-span"> </span>}</p>
163 <p class="p7">).send(s);</p>
164 <p class="p7">)</p>
165 <p class="p4"><br></p>
166 <p class="p6">// with AmpCompA</p>
167 <p class="p7">(</p>
168 <p class="p8">SynthDef<span class="s6">(</span><span class="s7">"pgrain"</span><span class="s6">,<span class="Apple-converted-space"> </span></span></p>
169 <p class="p7"><span class="Apple-tab-span"> </span>{ <span class="s5">arg</span> out = 0, sustain=0.01, amp=0.5, pan = 0;</p>
170 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">var</span> freq = <span class="s5">MouseX</span>.kr(300, 7000, 1);</p>
171 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">var</span> window = <span class="s5">Env</span>.sine(sustain, amp * <span class="s5">AmpCompA</span>.ir(freq));</p>
172 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Out</span>.ar(out,<span class="Apple-converted-space"> </span></p>
173 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">Pan2</span>.ar(</p>
174 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="s5">SinOsc</span>.ar(freq),</p>
175 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>pan</p>
176 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>) * <span class="s5">EnvGen</span>.ar(window, doneAction:2)</p>
177 <p class="p7"><span class="Apple-tab-span"> </span><span class="Apple-tab-span"> </span>)</p>
178 <p class="p7"><span class="Apple-tab-span"> </span>}</p>
179 <p class="p7">).send(s);</p>
180 <p class="p7">)</p>
181 <p class="p4"><br></p>
182 <p class="p4"><br></p>
183 </body>
184 </html>