broadcast_loudness/error.rs
1use thiserror::Error;
2
3/// Loudness measurement error.
4#[derive(Debug, Error)]
5#[non_exhaustive]
6pub enum Error {
7 /// A channel index is out of range for the configured layout.
8 #[error("channel index {index} out of range (layout has {layout} channels)")]
9 ChannelOutOfRange {
10 /// The requested channel index.
11 index: usize,
12 /// The channel count of the configured layout.
13 layout: usize,
14 },
15
16 /// Push was called after `finish()`.
17 #[error("meter has been finished, no more samples accepted")]
18 Finished,
19
20 /// Too few samples provided for the channel count.
21 #[error("expected {expected} channels, got {got}")]
22 ChannelMismatch {
23 /// Number of channels expected.
24 expected: usize,
25 /// Number of channels provided.
26 got: usize,
27 },
28
29 /// A sample rate of zero was requested.
30 ///
31 /// A loudness meter needs a positive sample rate to derive K‑weighting
32 /// filter coefficients and to convert sample counts to seconds.
33 #[error("sample rate must be greater than 0, got {got} Hz")]
34 InvalidSampleRate {
35 /// The invalid sample rate requested.
36 got: u32,
37 },
38
39 /// A non-finite sample (NaN or ±Infinity) was passed to the meter.
40 ///
41 /// Non-finite values are rejected because they propagate through
42 /// the IIR filter state and permanently poison all subsequent
43 /// readings. The caller should either skip, replace, or clamp
44 /// such samples before feeding them.
45 #[error("non-finite sample at index {index} (channel {channel}): {value}")]
46 NonFiniteSample {
47 /// The index of the non-finite sample in the push call.
48 index: usize,
49 /// The channel index (zero-based) of the non-finite sample.
50 channel: usize,
51 /// The non-finite value received.
52 value: f64,
53 },
54}
55
56/// Result type for loudness operations.
57pub type Result<T> = core::result::Result<T, Error>;