]> git.nihav.org Git - nihav.git/blobdiff - src/frame.rs
channel map work
[nihav.git] / src / frame.rs
index 6431bc2e944cf5eb13eca58f5a9d5b2bead3f9a0..cfe6ab81488554df27d156881a3d55d603889c15 100644 (file)
@@ -17,6 +17,65 @@ 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,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
+}
+
+impl NAChannelType {
+    pub fn is_center(&self) -> bool {
+        match *self {
+            NAChannelType::C => true,   NAChannelType::Ch => true,
+            NAChannelType::Cl => true,  NAChannelType::Ov => true,
+            NAChannelType::LFE => true, NAChannelType::LFE2 => true,
+            _ => false,
+        }
+    }
+    pub fn is_left(&self) -> bool {
+        match *self {
+            NAChannelType::L   => true, NAChannelType::Ls => true,
+            NAChannelType::Lss => true, NAChannelType::Lc => true,
+            NAChannelType::Lh  => true, NAChannelType::Lw => true,
+            NAChannelType::Lhs => true, NAChannelType::Ll => true,
+            NAChannelType::Lt  => true, NAChannelType::Lo => true,
+            _ => false,
+        }
+    }
+    pub fn is_right(&self) -> bool {
+        match *self {
+            NAChannelType::R   => true, NAChannelType::Rs => true,
+            NAChannelType::Rss => true, NAChannelType::Rc => true,
+            NAChannelType::Rh  => true, NAChannelType::Rw => true,
+            NAChannelType::Rhs => true, NAChannelType::Rl => true,
+            NAChannelType::Rt  => true, NAChannelType::Ro => true,
+            _ => false,
+        }
+    }
+}
+
+pub struct NAChannelMap {
+    ids: Vec<NAChannelType>,
+}
+
+impl NAChannelMap {
+    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<u8> {
+        for i in 0..self.ids.len() {
+            if self.ids[i] as i32 == t as i32 { return Some(i as u8); }
+        }
+        None
+    }
+}
+
 #[allow(dead_code)]
 #[derive(Clone,Copy)]
 pub struct NAAudioInfo {