From: Kostya Shishkov Date: Thu, 11 May 2017 14:42:10 +0000 (+0200) Subject: channel map work X-Git-Url: https://git.nihav.org/?a=commitdiff_plain;h=3b501dcbaabd5922d829b217a541e697e8ed1a59;p=nihav.git channel map work --- diff --git a/src/frame.rs b/src/frame.rs index 1c57d7d..cfe6ab8 100644 --- a/src/frame.rs +++ b/src/frame.rs @@ -17,7 +17,7 @@ pub const SND_U8_FORMAT: NASoniton = NASoniton { bits: 8, is_be: false, packed: #[allow(dead_code)] pub const SND_S16_FORMAT: NASoniton = NASoniton { bits: 16, is_be: false, packed: false, planar: false, float: false, signed: true }; -#[derive(Debug)] +#[derive(Debug,Clone,Copy)] pub enum NAChannelType { C, L, R, Ls, Rs, Lss, Rss, LFE, Lc, Rc, Lh, Rh, Ch, LFE2, Lw, Rw, Ov, Lhs, Rhs, Chr, Ll, Rl, Cl, Lt, Rt, Lo, Ro } @@ -53,57 +53,25 @@ impl NAChannelType { } } -#[derive(Debug, Clone, Copy)] -pub enum NAChannel { - None, - C(T), - LR(T, T), - LsRs(T, T), - LssRss(T, T), - LFE(T), - LcRc(T, T), - LhRh(T, T), - Ch(T), - LFE2(T), - LwRw(T, T), - Ov(T), - LhsRhs(T, T), - LhrRhr(T, T), - Chr(T), - LlRl(T, T), - Cl(T), - LtRt(T, T), - LoRo(T, T), -} - -impl NAChannel { - pub fn num_ch(&self) -> u8 { - match *self { - NAChannel::None => 0, - NAChannel::C(_) => 1, - NAChannel::LFE(_) => 1, - NAChannel::Ch(_) => 1, - NAChannel::LFE2(_) => 1, - NAChannel::Ov(_) => 1, - NAChannel::Chr(_) => 1, - NAChannel::Cl(_) => 1, - _ => 2, - } - } -} - pub struct NAChannelMap { - ids: Vec>, - nch: u8, + ids: Vec, } impl NAChannelMap { - pub fn new() -> Self { NAChannelMap { ids: Vec::new(), nch: 0 } } - pub fn add_channels(&mut self, ct: NAChannel) { - self.nch += ct.num_ch(); - self.ids.push(ct); + pub fn new() -> Self { NAChannelMap { ids: Vec::new() } } + pub fn add_channel(&mut self, ch: NAChannelType) { + self.ids.push(ch); + } + pub fn num_channels(&self) -> usize { + self.ids.len() + } + pub fn get_channel(&self, idx: usize) -> NAChannelType { + self.ids[idx] } pub fn find_channel_id(&self, t: NAChannelType) -> Option { + for i in 0..self.ids.len() { + if self.ids[i] as i32 == t as i32 { return Some(i as u8); } + } None } }