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.44">
9 <style type=
"text/css">
10 p
.p1
{margin: 0.0px 0.0px 0.0px 0.0px; font: 18.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: 9.0px Monaco
; min-height: 12.0px}
14 p
.p5
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #722c1d}
15 p
.p6
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #606060}
16 p
.p7
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
; color: #872718}
17 p
.p8
{margin: 0.0px 0.0px 0.0px 0.0px; font: 9.0px Monaco
}
18 span
.s1
{color: #000000}
19 span
.s2
{color: #1737a5}
20 span
.s3
{color: #102aae}
21 span
.s4
{color: #872718}
22 span
.Apple-tab-span
{white-space:pre
}
26 <p class=
"p1"><b>Loudness
<span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span><span class=
"Apple-tab-span"> </span>extraction of instantaneous loudness in sones
</b></p>
27 <p class=
"p2"><br></p>
28 <p class=
"p3"><b>sones = Loudness.kr(chain, smask=
0.25, tmask=
6)
</b></p>
29 <p class=
"p2"><br></p>
30 <p class=
"p3"><b>chain [fft] -
</b>Audio input to track, which has been pre-analysed by the FFT UGen; see examples below for the expected FFT size
</p>
31 <p class=
"p3"><b>smask [sk] -
</b>Spectral masking param: lower bins mask higher bin power within ERB bands, with a power falloff (leaky integration multiplier) of smask per bin
</p>
32 <p class=
"p3"><b>tmask [sk] -
</b>Temporal masking param: the phon level let through in an ERB band is the maximum of the new measurement, and the previous minus tmask phons
</p>
33 <p class=
"p2"><br></p>
34 <p class=
"p3">A perceptual loudness function which outputs loudness in sones; this is a variant of an MP3 perceptual model, summing excitation in ERB bands. It models simple spectral and temporal masking, with equal loudness contour correction in ERB bands to obtain phons (relative dB), then a phon to sone transform. The final output is typically in the range of
0 to
64 sones, though higher values can occur with specific synthesised stimuli
</p>
35 <p class=
"p2"><br></p>
36 <p class=
"p4"><br></p>
37 <p class=
"p4"><br></p>
38 <p class=
"p5">//assumes hop of half fftsize, fine
</p>
39 <p class=
"p5"><span class=
"s1">b =
</span><span class=
"s2">Buffer
</span><span class=
"s1">.alloc(s,
1024,
1);
</span>//for sampling rates
44100 and
48000</p>
40 <p class=
"p5">//b = Buffer.alloc(s,
2048,
1); //for sampling rates
88200 and
96000</p>
41 <p class=
"p4"><br></p>
42 <p class=
"p6"><span class=
"s1">d=
</span><span class=
"s2">Buffer
</span><span class=
"s1">.read(s,
</span>"sounds/a11wlk01.wav"<span class=
"s1">);
</span></p>
43 <p class=
"p4"><br></p>
44 <p class=
"p4"><br></p>
45 <p class=
"p7">//analyse loudness and poll result
</p>
48 <p class=
"p4"><br></p>
49 <p class=
"p8"><span class=
"s3">var
</span> in, fft, loudness;
</p>
50 <p class=
"p4"><br></p>
51 <p class=
"p8">in=
<span class=
"s3">PlayBuf
</span>.ar(
1,d,
<span class=
"s3">BufRateScale
</span>.kr(d),
1,
0,
1);
</p>
52 <p class=
"p4"><br></p>
53 <p class=
"p8">fft =
<span class=
"s3">FFT
</span>(b, in);
</p>
54 <p class=
"p4"><br></p>
55 <p class=
"p8">loudness=
<span class=
"s3">Loudness
</span>.kr(fft).poll(
50);
<span class=
"Apple-converted-space"> </span></p>
56 <p class=
"p4"><br></p>
57 <p class=
"p8"><span class=
"s3">Out
</span>.ar(
0,
<span class=
"s3">Pan2
</span>.ar(in));
<span class=
"Apple-converted-space"> </span></p>
58 <p class=
"p8">}.play
</p>
60 <p class=
"p4"><br></p>
61 <p class=
"p4"><br></p>
62 <p class=
"p4"><br></p>
63 <p class=
"p5">//TESTS
</p>
64 <p class=
"p5">//sones =
2**((phon-
40)/
10)
</p>
65 <p class=
"p5">//sine of
40 dB=
40phon at
1000 kHz =
1 sone
</p>
66 <p class=
"p5">//full amp =
100 dB
</p>
67 <p class=
"p5">//-
60.dbamp =
0.001 =
1 sone
</p>
68 <p class=
"p5">//-
40.dbamp =
0.01 =
4 sone
</p>
69 <p class=
"p5">//-
20.dbamp=
0.1 =
16 sone
</p>
70 <p class=
"p5">//
0.dbamp=
1 =
64 sone
</p>
73 <p class=
"p4"><br></p>
74 <p class=
"p8"><span class=
"s3">var
</span> in, fft, loudness;
</p>
75 <p class=
"p4"><br></p>
76 <p class=
"p8">in=
<span class=
"s3">SinOsc
</span>.ar(
1000,
0,
0.001);
<span class=
"s4">//should be
1 sone
</span></p>
77 <p class=
"p7">//in= SinOsc.ar(
1000,
0,
0.01); //should be
4 sone
</p>
78 <p class=
"p7">//in= SinOsc.ar(
1000,
0,
0.1); //should be
16 sone
<span class=
"Apple-converted-space"> </span></p>
79 <p class=
"p7">//in= SinOsc.ar(
1000,
0,
1); //should be
64 sone
<span class=
"Apple-converted-space"> </span></p>
80 <p class=
"p7">//in= Saw.ar * SinOsc.ar(
4);
<span class=
"Apple-converted-space"> </span></p>
81 <p class=
"p7">//in=WhiteNoise.ar;
</p>
82 <p class=
"p7">//in= Silent.ar; //should be small, around
2 **((
0-
40)/
10) =
2 ** (-
4) =
0.0625</p>
83 <p class=
"p7">//in=DC.ar(
1);
</p>
84 <p class=
"p7">//in=SinOsc.ar(
22050,pi*
0.5,
1);
</p>
85 <p class=
"p7">//fade ins
</p>
86 <p class=
"p7">//in= SinOsc.ar(
1000,
0,Line.kr(
0,
1,
2));
</p>
87 <p class=
"p7">//in= SinOsc.ar(
1000,
0,Line.kr(
0,
1,
2)**
2);
</p>
88 <p class=
"p7">//in= WhiteNoise.ar(Line.kr(
0,
1,
2));
</p>
89 <p class=
"p7">//in= PlayBuf.ar(
1,d,BufRateScale.kr(d),
1,
0,
1);
</p>
90 <p class=
"p4"><br></p>
91 <p class=
"p8">fft =
<span class=
"s3">FFT
</span>(b, in);
</p>
92 <p class=
"p4"><br></p>
93 <p class=
"p8">loudness=
<span class=
"s3">Loudness
</span>.kr(fft,
0.25,
6).poll(
50);
<span class=
"Apple-converted-space"> </span></p>
94 <p class=
"p4"><br></p>
95 <p class=
"p8"><span class=
"s3">Out
</span>.ar(
0,
<span class=
"s3">Pan2
</span>.ar(in));
<span class=
"Apple-converted-space"> </span></p>
96 <p class=
"p8"><span class=
"s3">K2A
</span>.ar(loudness*
0.016)
</p>
97 <p class=
"p8">}.plot(
2.0)
</p>
99 <p class=
"p4"><br></p>
100 <p class=
"p4"><br></p>
101 <p class=
"p4"><br></p>
102 <p class=
"p4"><br></p>
103 <p class=
"p4"><br></p>
104 <p class=
"p4"><br></p>
105 <p class=
"p8">Research note: This UGen is an informal juxtaposition of perceptual coding, and a Zwicker and Glasberg/Moore/Stone loudness model.
<span class=
"Apple-converted-space"> </span></p>