From 706ed9db0302dfdb114064c777ce960b5eb74d14 Mon Sep 17 00:00:00 2001 From: Andy Killorin <37423245+Speedy6451@users.noreply.github.com> Date: Thu, 6 Mar 2025 17:09:37 -0500 Subject: [PATCH] adapt to windows audio quirks (virtualbox ones at least) --- interface/src/gui.rs | 2 ++ interface/src/main.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/interface/src/gui.rs b/interface/src/gui.rs index 2d5596f..a9ace36 100644 --- a/interface/src/gui.rs +++ b/interface/src/gui.rs @@ -59,6 +59,8 @@ impl eframe::App for GUI { ui.label(format!("Right tof: {}", if let Some(tof) = telem.sensors.tof_r {format!("✅ {tof}mm")} else {"❌".into()})); ui.label(format!("Side tof: {}", if let Some(tof) = telem.sensors.tof_s {format!("✅ {tof}mm")} else {"❌".into()})); ui.label(format!("Gyro: {}", if telem.sensors.gyro.is_some() {"✅"} else {"❌"})); + + ui.label(format!("Cam: {:?}", telem.cam_state)); } else { ui.label("disconnected"); } diff --git a/interface/src/main.rs b/interface/src/main.rs index dca7b64..d3b3841 100644 --- a/interface/src/main.rs +++ b/interface/src/main.rs @@ -1,4 +1,3 @@ -#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] #![feature(iter_collect_into)] use std::{ops::ControlFlow, result, sync::Arc, thread::{self, sleep}, time::Duration}; @@ -17,8 +16,14 @@ fn main() -> Result<()> { // assumes pulseaudio system with f32 samples and 2204 sample packets dbg!(cpal::available_hosts()); let host = cpal::default_host(); + #[cfg(target_os = "windows")] + let Some(device) = host.devices().unwrap().filter(|device| device.supported_input_configs().unwrap().count() != 0).next() else { + panic!("no input devices") + }; + #[cfg(target_os = "linux")] let device = host.devices().unwrap().find(|d|d.name().unwrap() == "pulse").context("no pulse")?; + let config = device.default_input_config()?; dbg!(config.sample_format()); @@ -28,7 +33,10 @@ fn main() -> Result<()> { const POWER_THRESHOLD: f32 = 5.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; let stream = device.build_input_stream(&config.into(), move | data: &[f32], _: &_| {