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 let (frame, had_data) = queue.next_frame();
25 if had_data {
26 frames += 1;
27 if frame.iter().any(|&sample| sample != 0) {
28 loud_frames += 1;
29 }
30 }
31 }
32 println!("process exclude mode available: {}", started.kind == LoopbackKind::ProcessExclude);
33 println!("mode: {:?}", started.kind);
34 if let Some(warning) = &started.warning {
35 println!("warning: {warning}");
36 }
37 println!("captured frames (10 ms): {frames}, with non-zero samples: {loud_frames}");
38}