2022-12-24 06:21:58 +01:00
|
|
|
// 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 {
|
2022-12-27 19:01:48 +01:00
|
|
|
fn oscilloscope(&self, data: &mut [u8], channels: u32) -> Vec<Vec<f64>>;
|
2022-12-24 06:21:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Signed16PCM {}
|
|
|
|
|
2022-12-24 06:57:56 +01:00
|
|
|
/// TODO these are kinda inefficient, can they be faster?
|
2022-12-24 06:21:58 +01:00
|
|
|
impl SampleParser for Signed16PCM {
|
2022-12-27 19:01:48 +01:00
|
|
|
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;
|
2022-12-24 06:21:58 +01:00
|
|
|
}
|
|
|
|
out
|
|
|
|
}
|
|
|
|
}
|