Skip to content

Commit 635697b

Browse files
feat(loudness): LUFS-I and LRA
Signed-off-by: Maika Namuo <httpworldview@gmail.com>
1 parent 5482057 commit 635697b

8 files changed

Lines changed: 582 additions & 164 deletions

File tree

‎CONTRIBUTING.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ the existing visuals, but in short:
3232
linear or power-law radial scaling. Multiband correlation uses the
3333
same crossover outputs.
3434
6. The loudness meter implements K-weighting relative to full
35-
scale/LUFS momentary/short-term, True Peak, and RMS
36-
fast/slow. Standards used include ITU-R BS.1770.
35+
scale/LUFS momentary/short-term/integrated, loudness range, True
36+
Peak, and RMS fast/slow. Standards used include ITU-R BS.1770 and
37+
EBU Tech 3341/3342.
3738

3839
The point of this section is not to discourage engagement with the
3940
project, but rather to emphasize the expected level at which

‎README.md‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ open an issue or pull request.
5454

5555
- **Loudness**
5656
- BS.1770-5 K-weighted short-term and momentary LUFS meter modes.
57+
- BS.1770-5 integrated LUFS meter mode with EBU Tech 3342 loudness
58+
range (LRA), dimmed for its first 60 s per EBU Tech 3341.
5759
- True Peak meter modes.
5860
- Fast and slow K-weighted RMS dB meter modes.
5961
- **Oscilloscope**
@@ -212,6 +214,12 @@ Fedora, and tarball artifacts.
212214
| `ctrl+scroll up/down` | Zoom the frequency axis. |
213215
| `middle click+drag` or `ctrl+left click+drag` | Pan the frequency axis while zoomed in. |
214216

217+
### Loudness
218+
219+
| Binding | Action |
220+
| --- | --- |
221+
| double click | Reset LUFS Integrated and its loudness range. |
222+
215223
## Configuration
216224

217225
On first launch, all six visuals are enabled. Application settings are
@@ -343,6 +351,8 @@ out.
343351
### Papers and Standards
344352

345353
- ITU-R BS.1770-5, loudness and true peak measurement.
354+
- EBU Tech 3341, 'EBU Mode' loudness metering.
355+
- EBU Tech 3342, loudness range measurement.
346356
- IEC 61672-1, A-weighting reference curve.
347357
- Brecht De Man, "[Evaluation of Implementations of the EBU R128
348358
Loudness

‎src/meter.rs‎

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,10 @@ mod tests {
154154
use super::*;
155155
use crate::dsp::AudioBlock;
156156
use crate::util::audio::sine_wave;
157-
use crate::visuals::loudness::processor::{LoudnessProcessor, LoudnessSnapshot};
157+
use crate::visuals::loudness::processor::{LoudnessProcessor, LoudnessSnapshot, Programme};
158158
use crate::visuals::registry::{VisualContent, VisualKind};
159159

160-
fn loudness() -> (VisualManager, impl Fn() -> LoudnessSnapshot) {
160+
fn loudness() -> (VisualManager, impl Fn() -> (LoudnessSnapshot, Programme)) {
161161
let mut manager = VisualManager::default();
162162
manager.set_enabled(VisualKind::Loudness, true);
163163
let state = manager
@@ -224,7 +224,7 @@ mod tests {
224224
for bulk in [false, true] {
225225
manager.ingest_samples(&signal, format);
226226
let before = snapshot();
227-
assert!(before.momentary_loudness > reset.momentary_loudness);
227+
assert!(before.0.momentary_loudness > reset.0.momentary_loudness);
228228
manager.set_enabled(VisualKind::Loudness, true);
229229
assert_eq!(snapshot(), before);
230230
manager.set_enabled(VisualKind::Loudness, false);
@@ -248,28 +248,36 @@ mod tests {
248248
let (mut manager, snapshot) = loudness();
249249
let mut batcher = DspBatcher::new();
250250
let format = AudioFormat::fallback(1, SampleRate::DEFAULT);
251-
let signal = sine_wave(1_000.0, 48_000.0, 256, 0.5);
252-
let reset_level = snapshot().short_term_loudness;
251+
let signal = sine_wave(1_000.0, 48_000.0, 256 * 80, 0.5);
252+
let reset_level = snapshot().0.short_term_loudness;
253253
for frames in [48_000, 144_001, 192_000, 192_001] {
254254
batcher.reset(&mut manager);
255255
batcher.push(&mut manager, &signal, format);
256-
assert!(snapshot().short_term_loudness > reset_level);
256+
assert!(snapshot().0.short_term_loudness > reset_level);
257+
let programme = snapshot().1;
258+
assert!(programme.integrated.is_some());
257259
let mut reference = LoudnessProcessor::new(Default::default());
258260
reference.process_block(&AudioBlock::new(&signal, format));
259261
batcher.push(&mut manager, &[0.0], format);
260262
batcher.push_silence(&mut manager, frames, format);
261263
let expected = if frames > 192_000 {
262264
assert!(batcher.samples.is_empty());
265+
assert_eq!(snapshot().1, programme);
263266
reset_level
264267
} else {
265268
reference
266269
.process_block(&AudioBlock::new(
267270
&vec![0.0; (frames as usize + 1) / 256 * 256],
268271
format,
269272
))
273+
.0
270274
.short_term_loudness
271275
};
272-
assert_eq!(snapshot().short_term_loudness, expected, "frames={frames}");
276+
assert_eq!(
277+
snapshot().0.short_term_loudness,
278+
expected,
279+
"frames={frames}"
280+
);
273281
assert_eq!(batcher.format.is_none(), frames > 192_000);
274282
}
275283
}

‎src/visuals.rs‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22
// Copyright (C) 2026 Maika Namuo
33

44
macro_rules! visualization_widget {
5-
($widget:ident, $state:ty, |$this:ident, $renderer:ident, $theme:ident, $bounds:ident| $draw:block) => {
5+
(
6+
$widget:ident, $state:ty, $($update:ident,)?
7+
|$this:ident, $renderer:ident, $theme:ident, $bounds:ident| $draw:block
8+
) => {
69
struct $widget<'a> {
710
state: &'a std::cell::RefCell<$state>,
811
}
@@ -13,6 +16,13 @@ macro_rules! visualization_widget {
1316
|limits| limits.resolve(iced::Length::Fill, iced::Length::Fill, iced::Size::ZERO)
1417
);
1518

19+
$($crate::macros::widget_method!(update M; this; _, event, layout, cursor, _, _, shell, _ => {
20+
if this.state.borrow_mut().$update(event, cursor, layout.bounds()) {
21+
shell.request_redraw();
22+
shell.capture_event();
23+
}
24+
});)?
25+
1626
$crate::macros::widget_method!(draw $this; _, $renderer, $theme, _, layout, _, _ => {
1727
use iced_wgpu::primitive::Renderer as _;
1828
let $bounds = layout.bounds();
@@ -98,6 +108,7 @@ pub mod options {
98108
crate::macros::choice_enum!(pub enum MeterMode {
99109
LufsShortTerm => "LUFS Short-term",
100110
LufsMomentary => "LUFS Momentary",
111+
LufsIntegrated => "LUFS Integrated",
101112
RmsFast => "RMS Fast",
102113
RmsSlow => "RMS Slow",
103114
TruePeak => "True Peak",

0 commit comments

Comments
 (0)