1
0
Fork 0
mirror of https://github.com/alemidev/scope-tui.git synced 2024-11-15 03:09:20 +01:00
scope-tui/src/parser.rs

29 lines
775 B
Rust
Raw Normal View History

// use libpulse_binding::sample::Format;
// pub fn parser(fmt: Format) -> impl SampleParser {
// match fmt {
// Format::S16NE => Signed16PCM {},
// _ => panic!("parser not implemented for this format")
// }
// }
pub trait SampleParser {
fn oscilloscope(&self, data: &mut [u8], channels: u32) -> Vec<Vec<f64>>;
}
pub struct Signed16PCM {}
2022-12-24 06:57:56 +01:00
/// TODO these are kinda inefficient, can they be faster?
impl SampleParser for Signed16PCM {
fn oscilloscope(&self, data: &mut [u8], channels: u32) -> Vec<Vec<f64>> {
let mut out = vec![vec![]; channels as usize];
let mut channel = 0;
for chunk in data.chunks(2) {
let buf = chunk[0] as i16 | (chunk[1] as i16) << 8;
out[channel].push(buf as f64);
channel = (channel + 1 ) % channels as usize;
}
out
}
}