use crate::Error;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
#[non_exhaustive]
pub enum Layout {
Mono,
#[default]
Stereo,
Discrete(u32),
}
impl Layout {
pub fn from_channels(channels: u32) -> Result<Self, Error> {
match channels {
0 => Err(Error::Unsupported(
"audio layout must contain at least one channel".into(),
)),
1 => Ok(Self::Mono),
2 => Ok(Self::Stereo),
channels => Ok(Self::Discrete(channels)),
}
}
pub fn channels(self) -> u32 {
match self {
Self::Mono => 1,
Self::Stereo => 2,
Self::Discrete(channels) => channels,
}
}
pub(crate) fn validate(self) -> Result<(), Error> {
if self.channels() == 0 {
return Err(Error::Unsupported(
"audio layout must contain at least one channel".into(),
));
}
Ok(())
}
}