ebur128_stream/snapshot.rs
1//! Per-call view of the analyzer's current measurements.
2//!
3//! [`Snapshot`] is cheap to read (`O(1)` for momentary / short-term —
4//! values are cached on each new block; `O(programme blocks)` for
5//! integrated — see [`Snapshot::integrated_lufs`]).
6
7/// A point-in-time view of the analyzer's measurements.
8///
9/// Returned from [`Analyzer::snapshot`].
10///
11/// All accessors return `Option<f64>`:
12/// - `Some(value)` when the requested mode was selected at build time
13/// *and* enough audio has been ingested for that measurement.
14/// - `None` when the mode wasn't selected, or there isn't enough data
15/// yet (for example, less than 400 ms of audio has been pushed for
16/// momentary loudness).
17///
18/// [`Analyzer::snapshot`]: crate::Analyzer::snapshot
19#[derive(Debug, Clone, Copy, Default, PartialEq)]
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21pub struct Snapshot {
22 pub(crate) momentary_lufs: Option<f64>,
23 pub(crate) short_term_lufs: Option<f64>,
24 pub(crate) integrated_lufs: Option<f64>,
25 pub(crate) true_peak_dbtp: Option<f64>,
26 pub(crate) loudness_range_lu: Option<f64>,
27 pub(crate) programme_duration_seconds: f64,
28}
29
30impl Snapshot {
31 /// Momentary loudness (sliding 400 ms window) in LUFS.
32 #[inline]
33 #[must_use]
34 pub fn momentary_lufs(&self) -> Option<f64> {
35 self.momentary_lufs
36 }
37
38 /// Short-term loudness (sliding 3 s window) in LUFS.
39 #[inline]
40 #[must_use]
41 pub fn short_term_lufs(&self) -> Option<f64> {
42 self.short_term_lufs
43 }
44
45 /// Integrated (gated) loudness over the audio pushed so far, in LUFS.
46 ///
47 /// Computing this involves a pass over the programme buffer; the
48 /// analyzer caches the result and invalidates the cache when new
49 /// audio is pushed, so polling at \~10 Hz from a real-time monitor
50 /// is safe.
51 #[inline]
52 #[must_use]
53 pub fn integrated_lufs(&self) -> Option<f64> {
54 self.integrated_lufs
55 }
56
57 /// Maximum true-peak observed so far, in dBTP.
58 #[inline]
59 #[must_use]
60 pub fn true_peak_dbtp(&self) -> Option<f64> {
61 self.true_peak_dbtp
62 }
63
64 /// Loudness range (95 % − 10 % of doubly-gated short-term values), in LU.
65 #[inline]
66 #[must_use]
67 pub fn loudness_range_lu(&self) -> Option<f64> {
68 self.loudness_range_lu
69 }
70
71 /// Total duration of audio ingested, in seconds.
72 #[inline]
73 #[must_use]
74 pub fn programme_duration_seconds(&self) -> f64 {
75 self.programme_duration_seconds
76 }
77}