1use core::fmt;
4
5#[derive(Clone, Copy, Debug, PartialEq, Eq)]
10#[non_exhaustive]
11pub enum ConfigError {
12 ZeroSampleRate,
14 ZeroChannels,
16 SampleRateTooLow,
18 InvalidFrames,
20 HopTooShort,
22 InvalidThreshold,
24 InvalidLengths,
26 InvalidRatio,
28 InvalidWeights,
31 InvalidScoreFrames,
33 InvalidValue,
36 FrameCountMismatch,
38}
39
40const ZERO_SAMPLE_RATE: &str = "sample rate must be greater than zero";
41const ZERO_CHANNELS: &str = "channel count must be greater than zero";
42const SAMPLE_RATE_TOO_LOW: &str = "sample rate must be above 160 Hz for the 80 Hz high-pass filter";
43const INVALID_FRAMES: &str = "hop must be greater than zero, no longer than the window, and fit in u32 samples; window must fit in u64 samples";
44const HOP_TOO_SHORT: &str = "hop rounds to zero samples at this sample rate";
45const INVALID_THRESHOLD: &str = "threshold must be finite, and a relative threshold non-negative";
46const INVALID_LENGTHS: &str = "lengths must satisfy min <= target <= max with a non-zero target";
47const INVALID_RATIO: &str = "placement ratio must be within 0.0..=1.0";
48const INVALID_WEIGHTS: &str =
49 "weights must be finite and non-negative, the per-cut cost and pause reference above zero";
50const INVALID_SCORE_FRAMES: &str =
51 "score rate and hop must be greater than zero, with each frame at least one sample long";
52const INVALID_VALUE: &str =
53 "scores must be within 0.0..=1.0 without signal-free marks, and levels must be finite";
54const FRAME_COUNT_MISMATCH: &str = "frame count does not cover the audio length";
55
56pub(crate) const PLANAR_CHANNELS: &str = "planar input must have one slice per channel";
58pub(crate) const PLANAR_LENGTHS: &str = "planar channel slices must have equal lengths";
60pub(crate) const PLANAR_PENDING: &str = "planar input cannot follow a partial interleaved frame";
62
63impl fmt::Display for ConfigError {
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 f.write_str(match self {
66 Self::ZeroSampleRate => ZERO_SAMPLE_RATE,
67 Self::ZeroChannels => ZERO_CHANNELS,
68 Self::SampleRateTooLow => SAMPLE_RATE_TOO_LOW,
69 Self::InvalidFrames => INVALID_FRAMES,
70 Self::HopTooShort => HOP_TOO_SHORT,
71 Self::InvalidThreshold => INVALID_THRESHOLD,
72 Self::InvalidLengths => INVALID_LENGTHS,
73 Self::InvalidRatio => INVALID_RATIO,
74 Self::InvalidWeights => INVALID_WEIGHTS,
75 Self::InvalidScoreFrames => INVALID_SCORE_FRAMES,
76 Self::InvalidValue => INVALID_VALUE,
77 Self::FrameCountMismatch => FRAME_COUNT_MISMATCH,
78 })
79 }
80}
81
82impl core::error::Error for ConfigError {}