00 /**********************************************************************
01 Copyright (c) 2014-2016 Mark C. Erickson
02
03 Permission is hereby granted, free of charge, to any person obtaining
04 a copy of this software and associated documentation files (the
05 "Software"), to deal in the Software without restriction, including
06 without limitation the rights to use, copy, modify, merge, publish,
07 distribute, sublicense, and/or sell copies of the Software, and to
08 permit persons to whom the Software is furnished to do so, subject to
09 the following conditions:
10
11 The above copyright notice and this permission notice shall be included
12 in all copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
22 Reference: Rec. ITU-R BS.1770
23
24 **********************************************************************/
25
Disclaimer...
26 desc:LUFS Meter, Mono [-18dB], v1.0.1
27
28 @init
29 a1a = -1.69065929318241; // 48k prefilter, boost highs, model effects of head as a sphere
30 a2a = 0.73248077421585;
31 b0a = 1.53512485958697;
32 b1a = -2.69169618940638;
33 b2a = 1.19839281085285;
34
35 srate == 44100 ? (
36 a1a = -1.66365511325602; // 44k prefilter, boost highs, model effects of head as a sphere
37 a2a = 0.71259542807323;
38 b0a = 1.53084123005035;
39 b1a = -2.65097999515473;
40 b2a = 1.16907907992159;
41 );
42
43 axn=0;
44 axn1=0;
45 axn2=0;
46 ayn=0;
47 ayn1=0;
48 ayn2=0;
49
50 a1b = -1.99004745483398; // 48k High Pass
51 a2b = 0.99007225036621;
52 b0b = 1.0;
53 b1b = -2.0;
54 b2b = 1.0;
55
56 srate == 44100 ? (
57 a1b = -1.98916967362980; // 44k High Pass
58 a2b = 0.98919903578704;
59 b0b = 0.99956006454251;
60 b1b = -1.99912012908503;
61 b2b = 0.99956006454251;
62 );
63
64 bxn=0;
65 bxn1=0;
66 bxn2=0;
67 byn=0;
68 byn1=0;
69 byn2=0;
70
71 buf = 0; // buffer exists at offset 0
72 bufpos = 0;
73 buflength = srate * 3;//1.2; // 1200 ms
74
75 rmsSum = 0;
76 rmsTarget = 0.01;
77 LUFS_REF = pow(10, 20/-18);
78
79
80 @sample
81 axn2=axn1;
82 axn1=axn;
83 axn=spl0;
84 ayn2=ayn1;
85 ayn1=ayn;
86
87 ayn=b0a*axn + b1a*axn1 + b2a*axn2 - a1a*ayn1 - a2a*ayn2;
88
89 bxn2=bxn1;
90 bxn1=bxn;
91 bxn=ayn * sqrt(1.3);
92 byn2=byn1;
93 byn1=byn;
94
95 byn=b0b*bxn + b1b*bxn1 + b2b*bxn2 - a1b*byn1 - a2b*byn2;
96
97 rmsValue = byn * byn;
98 rmsSum -= buf[bufpos];
99 buf[bufpos] = rmsValue;
100 rmsSum += rmsValue;
101
102 bufpos = bufpos + 1 ;
103 bufpos > buflength ? bufpos = 0;
104
105 gain = 1.0;
106 rmsDelta = rmsSum / buflength;
107 rmsDB = 20 * log10(sqrt(rmsDelta) / LUFS_REF) - 24; // -21 for stereo simulation
108
109 spl0 = axn;
110 spl1 = spl1;
111
Graphics...
113 @gfx 100 18
114 gfx_x=gfx_y=5;
115 gfx_r=0.7;
116 gfx_g=1;
117 gfx_b=0.1;
118 gfx_a=1;
119 gfx_drawchar($'L');
120 gfx_drawchar($'U');
121 gfx_drawchar($'F');
122 gfx_drawchar($'S');
123 gfx_drawchar($' ');
124 gfx_drawchar($'1');
125 gfx_drawchar($'8');
126 gfx_drawchar($':');
127 gfx_drawchar($' ');
128 gfx_drawnumber(rmsDB,1);
129
130