use broadcast_common::impl_spec_display;
#[derive(Debug, Clone, Copy, PartialEq)]
#[non_exhaustive]
pub enum ChannelLayout {
Mono,
Stereo,
Surround51,
Custom {
weights: &'static [f64],
},
}
impl ChannelLayout {
#[must_use]
pub fn channel_count(&self) -> usize {
match self {
Self::Mono => 1,
Self::Stereo => 2,
Self::Surround51 => 6,
Self::Custom { weights } => weights.len(),
}
}
#[must_use]
pub fn weight(&self, index: usize) -> f64 {
match self {
Self::Mono => 1.0,
Self::Stereo => {
match index {
0 => 1.0, 1 => 1.0, _ => 0.0,
}
}
Self::Surround51 => {
match index {
0 => 1.0, 1 => 1.0, 2 => 1.0, 3 => 0.0, 4 => 1.41, 5 => 1.41, _ => 0.0,
}
}
Self::Custom { weights } => weights.get(index).copied().unwrap_or(0.0),
}
}
#[must_use]
pub fn name(&self) -> &'static str {
match self {
Self::Mono => "Mono",
Self::Stereo => "Stereo",
Self::Surround51 => "5.1 Surround",
Self::Custom { .. } => "Custom",
}
}
}
impl_spec_display!(ChannelLayout);