Skip to content

Add Source::loudness via ebur128#895

Open
4wn51dq wants to merge 3 commits into
RustAudio:masterfrom
4wn51dq:feature/loudness
Open

Add Source::loudness via ebur128#895
4wn51dq wants to merge 3 commits into
RustAudio:masterfrom
4wn51dq:feature/loudness

Conversation

@4wn51dq

@4wn51dq 4wn51dq commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Wraps the ebur128 crate (a pure-Rust port of libebur128) behind a new loudness feature flag, exposing EBU R128 / ITU-R BS.1770 loudness measurement as a passthrough Source adapter.

  • Source::loudness() — chains onto any source, passes audio through unchanged
  • momentary_lufs() (400 ms), short_term_lufs() (3 s), integrated_lufs() (gated, whole-program)
  • Handles mono, stereo, and multi-channel; conditional compilation for 64bit feature
  • Analyzer resets on seek (loudness history is position-dependent)

What's included

  • src/source/loudness.rs — the adapter
  • tests/loudness.rs — 4 integration tests (plausible LUFS, silence, louder-is-higher, stereo passthrough)
  • Cargo.tomlloudness = ["dep:ebur128"] feature + optional dependency
  • CHANGELOG.md entry

What's not included (yet)

  • Examples — waiting for API feedback before writing these
  • SpanTracker integration for mid-stream sample rate / channel changes

Test plan

  • cargo test --lib --features loudness (75 pass)
  • cargo test --test loudness --features loudness (4 pass)
  • cargo test --doc --features loudness (68 pass)
  • cargo clippy --all-features -- -D warnings
  • cargo fmt --check
  • Builds with loudness + 64bit combined

Refs #757

4wn51dq added 2 commits June 25, 2026 03:12
Adds a `loudness` feature that wraps the ebur128 crate in a passthrough
Source exposing momentary, short-term, and integrated LUFS. Includes
integration tests and a changelog entry.

Refs RustAudio#757
@4wn51dq 4wn51dq marked this pull request as ready for review June 25, 2026 06:14
@4wn51dq 4wn51dq marked this pull request as draft June 25, 2026 06:14
@4wn51dq 4wn51dq marked this pull request as ready for review June 26, 2026 11:29
Comment thread src/source/loudness.rs
//! # Limitation right now:
//! The analyzer is configured for the stream's channel count and sample rate at the construction time.
//! Sources whose parameters change mid-stream (e.g. a queue of files with differing sample rates)
//! are not yet reconfigured; that would need the analyzer to be rebuilt at span boundaries.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should soon (I've got time again) merge sources that cannot change parameters mid-stream. How do you feel about postponing this addition until we have those? Most users will probably move over to those (their API is nicer).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes total sense. the loudness source would be built cleaner on top of them!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants