#[derive(Debug, Clone, PartialEq)]
pub enum WaveformError {
ZeroSampleRate,
ZeroChannels,
UnalignedSamples {
samples: usize,
channels: u16,
},
NotFinite(&'static str),
OutOfRange {
what: &'static str,
min: f64,
max: f64,
got: f64,
},
UnsupportedChannels {
operation: &'static str,
channels: u16,
},
FormatMismatch,
TooLong {
max_frames: usize,
},
Wav(String),
}
impl std::fmt::Display for WaveformError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
WaveformError::ZeroSampleRate => write!(f, "the sample rate must be above zero"),
WaveformError::ZeroChannels => write!(f, "the channel count must be above zero"),
WaveformError::UnalignedSamples { samples, channels } => {
write!(f, "{samples} samples is not a whole number of {channels}-channel frames")
}
WaveformError::NotFinite(what) => write!(f, "{what} is not a finite number"),
WaveformError::OutOfRange { what, min, max, got } => write!(f, "{what} must be between {min} and {max}, got {got}"),
WaveformError::UnsupportedChannels { operation, channels } => {
write!(f, "{operation} does not work on a {channels}-channel waveform")
}
WaveformError::FormatMismatch => write!(f, "the waveforms differ in sample rate or channel count"),
WaveformError::TooLong { max_frames } => write!(f, "the result would be longer than {max_frames} frames"),
WaveformError::Wav(why) => write!(f, "not a readable WAV: {why}"),
}
}
}
impl std::error::Error for WaveformError {}