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 =
44 "hop must be greater than zero, no longer than the window, and fit in u32 samples";
45const HOP_TOO_SHORT: &str = "hop rounds to zero samples at this sample rate";
46const INVALID_THRESHOLD: &str = "threshold must be finite, and a relative threshold non-negative";
47const INVALID_LENGTHS: &str = "lengths must satisfy min <= target <= max with a non-zero target";
48const INVALID_RATIO: &str = "placement ratio must be within 0.0..=1.0";
49const INVALID_WEIGHTS: &str =
50 "weights must be finite and non-negative, the per-cut cost and pause reference above zero";
51const INVALID_SCORE_FRAMES: &str =
52 "score rate and hop must be greater than zero, with each frame at least one sample long";
53const INVALID_VALUE: &str =
54 "scores must be within 0.0..=1.0 without zero marks, and levels must be finite";
55const FRAME_COUNT_MISMATCH: &str = "frame count does not cover the audio length";
56
57pub(crate) const PLANAR_CHANNELS: &str = "planar input must have one slice per channel";
59pub(crate) const PLANAR_LENGTHS: &str = "planar channel slices must have equal lengths";
61pub(crate) const PLANAR_PENDING: &str = "planar input cannot follow a partial interleaved frame";
63
64impl fmt::Display for ConfigError {
65 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
66 f.write_str(match self {
67 Self::ZeroSampleRate => ZERO_SAMPLE_RATE,
68 Self::ZeroChannels => ZERO_CHANNELS,
69 Self::SampleRateTooLow => SAMPLE_RATE_TOO_LOW,
70 Self::InvalidFrames => INVALID_FRAMES,
71 Self::HopTooShort => HOP_TOO_SHORT,
72 Self::InvalidThreshold => INVALID_THRESHOLD,
73 Self::InvalidLengths => INVALID_LENGTHS,
74 Self::InvalidRatio => INVALID_RATIO,
75 Self::InvalidWeights => INVALID_WEIGHTS,
76 Self::InvalidScoreFrames => INVALID_SCORE_FRAMES,
77 Self::InvalidValue => INVALID_VALUE,
78 Self::FrameCountMismatch => FRAME_COUNT_MISMATCH,
79 })
80 }
81}
82
83impl core::error::Error for ConfigError {}