buffer received samples until they hit the analysis threshold
This commit is contained in:
parent
706ed9db03
commit
cf0a6b94d7
1 changed files with 20 additions and 1 deletions
|
@ -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];
|
||||
|
||||
|
|
Loading…
Reference in a new issue