1
Fork 0

buffer received samples until they hit the analysis threshold

This commit is contained in:
Andy Killorin 2025-03-06 20:24:14 -05:00
parent 706ed9db03
commit cf0a6b94d7
Signed by: ank
GPG key ID: 23F9463ECB67FE8C

View file

@ -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];