From cf0a6b94d7693fd42fa7c339b155a82bf6eea8cb Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Thu, 6 Mar 2025 20:24:14 -0500 Subject: [PATCH] buffer received samples until they hit the analysis threshold --- interface/src/main.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) 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];