1use thiserror::Error;
2
3pub type DspResult<T> = Result<T, DspError>;
4
5#[derive(Error, Debug, Clone, PartialEq)]
6pub enum DspError {
7 #[error("Invalid channel index: requested {channel}, total channels {total}")]
8 InvalidChannel { channel: usize, total: usize },
9
10 #[error("Shape mismatch: expected {expected:?}, got {actual:?}")]
11 ShapeMismatch { expected: Vec<usize>, actual: Vec<usize> },
12
13 #[error("Invalid sample rate: {rate_hz} Hz (must be positive and non-zero)")]
14 InvalidSampleRate { rate_hz: f64 },
15
16 #[error("Buffer overrun: capacity {capacity}, attempted {requested}")]
17 BufferOverrun { capacity: usize, requested: usize },
18
19 #[error("Buffer underrun: available {available}, attempted {requested}")]
20 BufferUnderrun { available: usize, requested: usize },
21
22 #[error("Device compute error: {0}")]
23 ComputeError(String),
24
25 #[error("Invalid configuration: {0}")]
26 InvalidConfig(String),
27
28 #[error("Sample range {start}..{end} is outside 0..{total}")]
29 SampleRange { start: u64, end: u64, total: u64 },
30
31 #[error("I/O error: {0}")]
32 Io(String),
33
34 #[error("Unsupported format: {0}")]
35 UnsupportedFormat(String),
36}
37
38impl From<std::io::Error> for DspError {
39 fn from(e: std::io::Error) -> Self {
40 DspError::Io(e.to_string())
41 }
42}