diff --git a/interface/src/main.rs b/interface/src/main.rs index d3b3841..dcb0351 100644 --- a/interface/src/main.rs +++ b/interface/src/main.rs @@ -31,15 +31,34 @@ fn main() -> Result<()> { let (sender, notes) = mpsc::channel(2); + #[cfg(target_os = "linux")] const POWER_THRESHOLD: f32 = 5.0; + #[cfg(target_os = "windows")] + const POWER_THRESHOLD: f32 = 1.0; const CLARITY_THRESHOLD: f32 = 0.85; #[cfg(target_os = "linux")] const PACKET_LEN: usize = 2204; #[cfg(target_os = "windows")] - const PACKET_LEN: usize = 512; + const PACKET_LEN: usize = 2000; + + let mut packet = Vec::new(); let stream = device.build_input_stream(&config.into(), move | data: &[f32], _: &_| { + let mut data = data; + + if packet.len() > PACKET_LEN { + packet.clear(); + } + + if data.len() <= PACKET_LEN { + packet.extend_from_slice(data); + if packet.len() > PACKET_LEN { + data = &packet; + } else { + return; + } + } assert!(data.len() >= PACKET_LEN); let data = &data[..PACKET_LEN];