use crate::{_impl_init, impl_trait};
#[doc = crate::_tags!(audio)]
#[doc = crate::_doc_location!("media/audio")]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum AudioChannel {
#[default]
L,
R,
C,
LFE,
Ls,
Rs,
Lb,
Rb,
}
_impl_init![ConstInit: Self::L => AudioChannel];
impl_trait![fmt::Display for AudioChannel |self, f| f.write_str(self.as_code())];
impl AudioChannel {
pub const fn as_code(self) -> &'static str {
match self {
Self::L => "L",
Self::R => "R",
Self::C => "C",
Self::LFE => "LFE",
Self::Ls => "Ls",
Self::Rs => "Rs",
Self::Lb => "Lb",
Self::Rb => "Rb",
}
}
pub const fn as_name(self) -> &'static str {
match self {
Self::L => "Left",
Self::R => "Right",
Self::C => "Center",
Self::LFE => "Low Frequency Effects",
Self::Ls => "Left Surround",
Self::Rs => "Right Surround",
Self::Lb => "Left Back",
Self::Rb => "Right Back",
}
}
}
#[doc = crate::_tags!(audio)]
#[doc = crate::_doc_location!("media/audio")]
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum AudioChannels {
Mono = 0,
#[default]
Stereo,
Stereo2_1,
Surround3_0,
Surround4_0,
Surround5_0,
Surround5_1,
Surround7_0,
Surround7_1,
}
_impl_init![ConstInit: Self::Stereo => AudioChannels];
impl_trait![fmt::Display for AudioChannels |self, f| f.write_str(self.as_x_y())];
impl AudioChannels {
pub const fn from_total_lfe(total: u8, lfe: bool) -> Option<Self> {
match (total, lfe) {
(1, false) => Some(Self::Mono),
(2, false) => Some(Self::Stereo),
(3, true) => Some(Self::Stereo2_1),
(3, false) => Some(Self::Surround3_0),
(4, false) => Some(Self::Surround4_0),
(5, false) => Some(Self::Surround5_0),
(6, true) => Some(Self::Surround5_1),
(7, false) => Some(Self::Surround7_0),
(8, true) => Some(Self::Surround7_1),
_ => None,
}
}
pub const fn from_main_lfe(main: u8, lfe: bool) -> Option<Self> {
match (main, lfe) {
(1, false) => Some(Self::Mono), (2, false) => Some(Self::Stereo), (2, true) => Some(Self::Stereo2_1), (3, false) => Some(Self::Surround3_0), (4, false) => Some(Self::Surround4_0), (5, false) => Some(Self::Surround5_0), (5, true) => Some(Self::Surround5_1), (7, false) => Some(Self::Surround7_0), (7, true) => Some(Self::Surround7_1), _ => None,
}
}
pub const fn channels(self) -> u8 {
match self {
Self::Mono => 1,
Self::Stereo => 2,
Self::Stereo2_1 => 3,
Self::Surround3_0 => 3,
Self::Surround4_0 => 4,
Self::Surround5_0 => 5,
Self::Surround5_1 => 6,
Self::Surround7_0 => 7,
Self::Surround7_1 => 8,
}
}
pub const fn main_channels(self) -> u8 {
match self {
Self::Mono => 1,
Self::Stereo => 2,
Self::Stereo2_1 => 2,
Self::Surround3_0 => 3,
Self::Surround4_0 => 4,
Self::Surround5_0 => 5,
Self::Surround5_1 => 5,
Self::Surround7_0 => 7,
Self::Surround7_1 => 7,
}
}
pub const fn main_lfe(self) -> (u8, bool) {
(self.main_channels(), self.has_lfe())
}
pub const fn has_lfe(self) -> bool {
matches![self, Self::Stereo2_1 | Self::Surround5_1 | Self::Surround7_1]
}
pub const fn is_surround(self) -> bool {
!matches![self, Self::Mono | Self::Stereo | Self::Stereo2_1]
}
pub const fn is_stereo_like(self) -> bool {
matches![self, Self::Stereo | Self::Stereo2_1]
}
pub const fn as_x_y(self) -> &'static str {
match self {
Self::Mono => "1.0",
Self::Stereo => "2.0",
Self::Stereo2_1 => "2.1",
Self::Surround3_0 => "3.0",
Self::Surround4_0 => "4.0",
Self::Surround5_0 => "5.0",
Self::Surround5_1 => "5.1",
Self::Surround7_0 => "7.0",
Self::Surround7_1 => "7.1",
}
}
pub const fn as_name(self) -> &'static str {
match self {
Self::Mono => "Mono",
Self::Stereo => "Stereo",
Self::Stereo2_1 => "Stereo 2.1",
Self::Surround3_0 => "3.0 surround",
Self::Surround4_0 => "4.0 surround",
Self::Surround5_0 => "5.0 surround",
Self::Surround5_1 => "5.1 surround",
Self::Surround7_0 => "7.0 surround",
Self::Surround7_1 => "7.1 surround",
}
}
pub const fn channels_expanded(self) -> &'static [AudioChannel] {
use AudioChannel::{C, L, LFE, Lb, Ls, R, Rb, Rs};
match self {
Self::Mono => &[L],
Self::Stereo => &[L, R],
Self::Stereo2_1 => &[L, R, LFE],
Self::Surround3_0 => &[L, C, R],
Self::Surround4_0 => &[L, R, Ls, Rs],
Self::Surround5_0 => &[L, C, R, Ls, Rs],
Self::Surround5_1 => &[L, C, R, Ls, Rs, LFE],
Self::Surround7_0 => &[L, C, R, Ls, Rs, Lb, Rb],
Self::Surround7_1 => &[L, C, R, Ls, Rs, Lb, Rb, LFE],
}
}
}