1 <!DOCTYPE html PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
4 <meta http-equiv=
"Content-Type" content=
"text/html; charset=UTF-8">
5 <meta http-equiv=
"Content-Style-Type" content=
"text/css">
7 <meta name=
"Generator" content=
"Cocoa HTML Writer">
8 <meta name=
"CocoaVersion" content=
"824.42">
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: 9.0px Monaco
; min-height: 12.0px}
13 p
.p4
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #a71e12; min-height: 12.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #a71e12}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
16 span
.s1
{font: 18.0px Helvetica
}
17 span
.s2
{font: 9.0px Monaco
}
18 span
.s3
{color: #0000ff}
19 span
.s4
{color: #0019b7}
20 span
.s5
{text-decoration: underline
}
21 span
.Apple-tab-span
{white-space:pre
}
25 <p class=
"p1"><span class=
"s1"><b>AmpCompA
</b></span><span class=
"s2"><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span></span><b>ANSI A-weighting curve
</b></p>
26 <p class=
"p1"><b><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=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>basic psychoacoustic amplitude compensation
</b></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p2"><br></p>
29 <p class=
"p1">superclass: UGen
</p>
30 <p class=
"p2"><br></p>
31 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
32 <p class=
"p1"><span class=
"Apple-tab-span"> </span>Higher frequencies are normally perceived as louder, which AmpCompA compensates.
<span class=
"Apple-converted-space"> </span></p>
33 <p class=
"p1"><span class=
"Apple-tab-span"> </span>Following the measurings by Fletcher and Munson, the ANSI standard describes
<span class=
"Apple-converted-space"> </span></p>
34 <p class=
"p1"><span class=
"Apple-tab-span"> </span>a function for loudness vs. frequency.
<span class=
"Apple-converted-space"> </span></p>
35 <p class=
"p1"><span class=
"Apple-tab-span"> </span>Note that this curve is only valid for standardized amplitude. [
1]
</p>
36 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
37 <p class=
"p1"><span class=
"Apple-tab-span"> </span>For a simpler but more flexible curve, see
<a href=
"AmpComp.html"><span class=
"s3">AmpComp
</span></a></p>
38 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
39 <p class=
"p2"><br></p>
40 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>*ar(freq, root, minAmp, rootAmp)
</b></p>
41 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>*kr(freq, root, minAmp, rootAmp)
</b></p>
42 <p class=
"p1"><b><span class=
"Apple-tab-span"> </span>*ir(freq, root, minAmp, rootAmp)
</b></p>
43 <p class=
"p2"><span class=
"Apple-tab-span"> </span></p>
44 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>freq
</b> <span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>input frequency value. For freq == root, the output is rootAmp. (default freq
0 Hz)
</p>
45 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>root
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>root freq relative to which the curve is calculated (usually lowest freq) (default
0 Hz)
</p>
46 <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>
47 <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>
48 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>minAmp
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>amplitude at the minimum point of the curve (around
2512 Hz) (default -
10dB)
</p>
49 <p class=
"p1"><span class=
"Apple-tab-span"> </span><b>rootAmp
</b><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>amplitude at the root frequency. (default
1)
</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=
"s2"><span class=
"Apple-tab-span"> </span></span>apart from
<i>freq
</i>, the values are not modulatable
</p>
52 <p class=
"p3"><br></p>
53 <p class=
"p3"><br></p>
54 <p class=
"p4"><br></p>
55 <p class=
"p4"><br></p>
56 <p class=
"p5">// compare a sine without compensation
</p>
57 <p class=
"p3"><br></p>
58 <p class=
"p6">{
<span class=
"s4">SinOsc
</span>.ar(
<span class=
"s4">MouseX
</span>.kr(
300,
15000,
1)) *
0.1 }.play;
</p>
59 <p class=
"p3"><br></p>
60 <p class=
"p5">// with one that uses amplitude compensation
</p>
62 <p class=
"p6">{
<span class=
"Apple-converted-space"> </span></p>
63 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> freq;
</p>
64 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s4">MouseX
</span>.kr(
300,
15000,
1);
</p>
65 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">SinOsc
</span>.ar(freq) *
0.3 *
<span class=
"s4">AmpCompA
</span>.kr(freq)
<span class=
"Apple-converted-space"> </span></p>
66 <p class=
"p6">}.play;
</p>
68 <p class=
"p3"><br></p>
69 <p class=
"p3"><br></p>
70 <p class=
"p5">// adjust the minimum and root amp
<span class=
"Apple-converted-space"> </span></p>
71 <p class=
"p5">// (in this way one can flatten out the curve for higher amplitudes)
<span class=
"Apple-converted-space"> </span></p>
72 <p class=
"p3"><br></p>
74 <p class=
"p6">{
<span class=
"Apple-converted-space"> </span></p>
75 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> freq;
</p>
76 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s4">MouseX
</span>.kr(
300,
18000,
1);
</p>
77 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">Formant
</span>.ar(
300, freq,
20,
0.1) *
<span class=
"s4">AmpCompA
</span>.kr(freq,
300,
0.6,
0.3)
</p>
78 <p class=
"p6">}.play;
</p>
80 <p class=
"p3"><br></p>
81 <p class=
"p5">// the curve:
</p>
82 <p class=
"p3"><br></p>
83 <p class=
"p6">{
<span class=
"s4">AmpCompA
</span>.ar(
<span class=
"s4">Line
</span>.ar(
48,
120,
1).midicps,
48.midicps) }.plot(
1.0);
</p>
84 <p class=
"p3"><br></p>
85 <p class=
"p5">// freqs:
</p>
86 <p class=
"p3"><br></p>
87 <p class=
"p6">{
<span class=
"s4">AmpCompA
</span>.ar(
<span class=
"s4">Line
</span>.ar(
0,
20000,
1)) }.plot(
1.0);
</p>
88 <p class=
"p3"><br></p>
89 <p class=
"p5">// compare with AmpComp (exponential decay)
</p>
90 <p class=
"p3"><br></p>
91 <p class=
"p6">{
<span class=
"s4">AmpComp
</span>.ar(
<span class=
"s4">Line
</span>.ar(
48,
120,
1).midicps,
48.midicps) }.plot(
1.0);
</p>
92 <p class=
"p4"><br></p>
93 <p class=
"p5">// freqs:
</p>
94 <p class=
"p3"><br></p>
95 <p class=
"p6">{
<span class=
"s4">AmpComp
</span>.ar(
<span class=
"s4">Line
</span>.ar(
40,
20000,
1),
40) }.plot(
1.0);
</p>
96 <p class=
"p3"><br></p>
97 <p class=
"p3"><br></p>
98 <p class=
"p3"><br></p>
99 <p class=
"p5">// amplitude compensation in frequency modulation (using Fletscher-Munson curve)
</p>
101 <p class=
"p6">{
<span class=
"Apple-converted-space"> </span></p>
102 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> freq;
</p>
103 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s4">MouseX
</span>.kr(
300,
15000,
1);
</p>
104 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq = freq *
<span class=
"s4">SinOsc
</span>.ar(
<span class=
"s4">MouseY
</span>.kr(
3,
200,
1),
0,
0.5,
1);
</p>
105 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">SinOsc
</span>.ar(freq) *
0.1 *
<span class=
"s4">AmpCompA
</span>.ar(freq,
300)
<span class=
"Apple-converted-space"> </span></p>
106 <p class=
"p6">}.play;
</p>
108 <p class=
"p3"><br></p>
109 <p class=
"p5">// amplitude compensation in frequency modulation (using AmpComp exponential decay)
</p>
111 <p class=
"p6">{
<span class=
"Apple-converted-space"> </span></p>
112 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> freq;
</p>
113 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s4">MouseX
</span>.kr(
300,
15000,
1);
</p>
114 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq = freq *
<span class=
"s4">SinOsc
</span>.ar(
<span class=
"s4">MouseY
</span>.kr(
3,
200,
1),
0,
0.5,
1);
</p>
115 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">SinOsc
</span>.ar(freq) *
0.1 *
<span class=
"s4">AmpComp
</span>.ar(freq,
300)
<span class=
"Apple-converted-space"> </span></p>
116 <p class=
"p6">}.play;
</p>
118 <p class=
"p3"><br></p>
119 <p class=
"p3"><br></p>
120 <p class=
"p5">// without amplitude compensation
</p>
122 <p class=
"p6">{
<span class=
"Apple-converted-space"> </span></p>
123 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">var
</span> freq;
</p>
124 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq =
<span class=
"s4">MouseX
</span>.kr(
300,
15000,
1);
</p>
125 <p class=
"p6"><span class=
"Apple-tab-span"> </span>freq = freq *
<span class=
"s4">SinOsc
</span>.ar(
<span class=
"s4">MouseY
</span>.kr(
3,
200,
1),
0,
0.5,
1);
</p>
126 <p class=
"p6"><span class=
"Apple-tab-span"> </span><span class=
"s4">SinOsc
</span>.ar(freq) *
0.1</p>
127 <p class=
"p6">}.play;
</p>
129 <p class=
"p3"><br></p>
130 <p class=
"p3"><br></p>
131 <p class=
"p3"><br></p>
132 <p class=
"p3"><br></p>
133 <p class=
"p2"><br></p>
134 <p class=
"p1">[
1] Function freq -
> dB,
<span class=
"Apple-converted-space"> </span></p>
135 <p class=
"p1"><span class=
"Apple-tab-span"> </span>derived from
<span class=
"s5">http://www.beis.de/Elektronik/AudioMeasure/WeightingFilters.html
</span></p>
136 <p class=
"p1"><span class=
"Apple-tab-span"> </span>and modified to map freq -
> amp
</p>
137 <p class=
"p3"><br></p>
139 <p class=
"p6"><span class=
"s4">var
</span> k =
<span class=
"Apple-converted-space"> </span>3.5041384e16;
</p>
140 <p class=
"p6">var c1 =
424.31867740601;
</p>
141 <p class=
"p6">var c2 =
11589.093052022;
</p>
142 <p class=
"p6">var c3 =
544440.67046057;
</p>
143 <p class=
"p6">var c4 =
148698928.24309;
</p>
144 <p class=
"p6">f = {
<span class=
"s4">|f|
</span></p>
145 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> r = squared(f);
</p>
146 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> m1 = pow(r,
4);
</p>
147 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> n1 = squared(c1 + r);
</p>
148 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> n2 = c2 + r;
</p>
149 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> n3 = c3 + r;
</p>
150 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> n4 = squared(c4 + r);
</p>
151 <p class=
"p6"><span class=
"Apple-converted-space"> </span><span class=
"s4">var
</span> level = k * m1 / (n1 * n2 * n3 * n4);
</p>
152 <p class=
"p6"><span class=
"Apple-converted-space"> </span>sqrt(level)
</p>
153 <p class=
"p6"><span class=
"Apple-converted-space"> </span>};
</p>
155 <p class=
"p3"><br></p>