scope-tui 0.3.0

A simple oscilloscope/vectorscope/spectroscope for your terminal
// 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: &[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: &[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 { 2 }  // 16 bit, thus 2 bytes
}