use crate::Error;
pub type Result<T> = std::result::Result<T, Error>;
pub type Sample = i32;
pub type Time = i64;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SignalFormat {
Format0,
Format8,
Format16,
Format24,
Format32,
Format61,
Format80,
Format160,
Format212,
Format310,
Format311,
Flac8,
Flac16,
Flac24,
}
impl TryFrom<u16> for SignalFormat {
type Error = Error;
fn try_from(format_code: u16) -> Result<Self> {
match format_code {
0 => Ok(Self::Format0),
8 => Ok(Self::Format8),
16 => Ok(Self::Format16),
24 => Ok(Self::Format24),
32 => Ok(Self::Format32),
61 => Ok(Self::Format61),
80 => Ok(Self::Format80),
160 => Ok(Self::Format160),
212 => Ok(Self::Format212),
310 => Ok(Self::Format310),
311 => Ok(Self::Format311),
508 => Ok(Self::Flac8),
516 => Ok(Self::Flac16),
524 => Ok(Self::Flac24),
_ => Err(Error::UnsupportedSignalFormat(format_code)),
}
}
}
impl From<SignalFormat> for u16 {
fn from(format: SignalFormat) -> Self {
match format {
SignalFormat::Format0 => 0,
SignalFormat::Format8 => 8,
SignalFormat::Format16 => 16,
SignalFormat::Format24 => 24,
SignalFormat::Format32 => 32,
SignalFormat::Format61 => 61,
SignalFormat::Format80 => 80,
SignalFormat::Format160 => 160,
SignalFormat::Format212 => 212,
SignalFormat::Format310 => 310,
SignalFormat::Format311 => 311,
SignalFormat::Flac8 => 508,
SignalFormat::Flac16 => 516,
SignalFormat::Flac24 => 524,
}
}
}