BlueGit

ict rusty-teams

Files

rusty-teams / crates / calling / examples / loopback_probe.rs

loopback_probe.rs

loopback_probe.rs 1.2 KiB Download Raw
1use std::time::{Duration, Instant};
2
3use calling::LoopbackKind;
4use calling::pcm::SampleQueue;
5use calling::sound_capture::start_loopback;
6
7const CAPTURE_TIME: Duration = Duration::from_secs(3);
8const FRAME_PERIOD: Duration = Duration::from_millis(10);
9
10fn main() {
11 let queue = SampleQueue::default();
12 let started = match start_loopback(queue.clone()) {
13 Ok(started) => started,
14 Err(error) => {
15 println!("loopback failed to start: {error}");
16 return;
17 }
18 };
19 let mut frames = 0u32;
20 let mut loud_frames = 0u32;
21 let begin = Instant::now();
22 while begin.elapsed() < CAPTURE_TIME {
23 std::thread::sleep(FRAME_PERIOD);
24 if let Some(frame) = queue.next_frame() {
25 frames += 1;
26 if frame.iter().any(|&sample| sample != 0) {
27 loud_frames += 1;
28 }
29 }
30 }
31 println!("process exclude mode available: {}", started.kind == LoopbackKind::ProcessExclude);
32 println!("mode: {:?}", started.kind);
33 if let Some(warning) = &started.warning {
34 println!("warning: {warning}");
35 }
36 println!("captured frames (10 ms): {frames}, with non-zero samples: {loud_frames}");
37}