1
0
Fork 0
mirror of https://github.com/alemidev/scope-tui.git synced 2024-11-14 18:59:19 +01:00
scope-tui/src/parser.rs
alemidev d72e471dbd
feat: better UI and keybinds, more CLI opts
Added CLI option to specify channel number, but I'm not sure it's really
working. Refactored AppConfig a little. Added threshold indication on
status bar. References and UI are separate settings and can be toggled
individually. At least 1 sample is always shown when discarding due to
triggering. Range and threshold are configured with arrow keys. Added
more colors to palette. Added ability to toggle braille mode. Fix: fully
write "fps" instead of cutting "s" out.
2023-01-05 00:51:05 +01:00

33 lines
880 B
Rust

// 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: u8) -> Vec<Vec<f64>>;
fn sample_size(&self) -> usize;
}
pub struct Signed16PCM {}
/// TODO these are kinda inefficient, can they be faster?
impl SampleParser for Signed16PCM {
fn oscilloscope(&self, data: &mut [u8], channels: u8) -> 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
}
fn sample_size(&self) -> usize {
return 2; // 16 bit, thus 2 bytes
}
}