Skip to main content

ebur128_stream/
mode.rs

1//! The [`Mode`] bitflags — which measurements the analyzer should compute.
2//!
3//! Modes are composable: `Mode::Integrated | Mode::TruePeak` builds an
4//! analyzer that maintains both gating state and an oversampling FIR.
5//! Each mode adds work on the hot path; only request what the caller will
6//! read.
7
8use bitflags::bitflags;
9
10bitflags! {
11    /// The set of measurements an analyzer should compute.
12    ///
13    /// Combine with `|`:
14    ///
15    /// ```
16    /// use ebur128_stream::Mode;
17    /// let modes = Mode::Integrated | Mode::TruePeak;
18    /// assert!(modes.contains(Mode::Integrated));
19    /// ```
20    #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
21    #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
22    pub struct Mode: u8 {
23        /// Integrated loudness over the full programme, gated per
24        /// BS.1770-4 §5.6. Reported via [`Report::integrated_lufs`].
25        ///
26        /// [`Report::integrated_lufs`]: crate::Report::integrated_lufs
27        const Integrated = 0b0000_0001;
28        /// Momentary loudness over a sliding 400 ms window. Reported via
29        /// [`Snapshot::momentary_lufs`] and
30        /// [`Report::momentary_max_lufs`].
31        ///
32        /// [`Snapshot::momentary_lufs`]: crate::Snapshot::momentary_lufs
33        /// [`Report::momentary_max_lufs`]: crate::Report::momentary_max_lufs
34        const Momentary = 0b0000_0010;
35        /// Short-term loudness over a sliding 3 s window. Reported via
36        /// [`Snapshot::short_term_lufs`] and
37        /// [`Report::short_term_max_lufs`].
38        ///
39        /// [`Snapshot::short_term_lufs`]: crate::Snapshot::short_term_lufs
40        /// [`Report::short_term_max_lufs`]: crate::Report::short_term_max_lufs
41        const ShortTerm = 0b0000_0100;
42        /// True-peak via 4× oversampling FIR per BS.1770 Annex 2.
43        /// Reported via [`Report::true_peak_dbtp`].
44        ///
45        /// [`Report::true_peak_dbtp`]: crate::Report::true_peak_dbtp
46        const TruePeak = 0b0000_1000;
47        /// Loudness range per EBU Tech 3342. Reported via
48        /// [`Report::loudness_range_lu`].
49        ///
50        /// [`Report::loudness_range_lu`]: crate::Report::loudness_range_lu
51        const Lra = 0b0001_0000;
52        /// Convenience: all measurement modes.
53        const All = 0b0001_1111;
54    }
55}
56
57impl Default for Mode {
58    fn default() -> Self {
59        Mode::All
60    }
61}