1
Fork 0

adapt to windows audio quirks (virtualbox ones at least)

This commit is contained in:
Andy Killorin 2025-03-06 17:09:37 -05:00
parent bb974c2015
commit 706ed9db03
Signed by: ank
GPG key ID: 23F9463ECB67FE8C
2 changed files with 11 additions and 1 deletions

View file

@ -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!("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!("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!("Gyro: {}", if telem.sensors.gyro.is_some() {""} else {""}));
ui.label(format!("Cam: {:?}", telem.cam_state));
} else { } else {
ui.label("disconnected"); ui.label("disconnected");
} }

View file

@ -1,4 +1,3 @@
#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
#![feature(iter_collect_into)] #![feature(iter_collect_into)]
use std::{ops::ControlFlow, result, sync::Arc, thread::{self, sleep}, time::Duration}; 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 // assumes pulseaudio system with f32 samples and 2204 sample packets
dbg!(cpal::available_hosts()); dbg!(cpal::available_hosts());
let host = cpal::default_host(); 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 device = host.devices().unwrap().find(|d|d.name().unwrap() == "pulse").context("no pulse")?;
let config = device.default_input_config()?; let config = device.default_input_config()?;
dbg!(config.sample_format()); dbg!(config.sample_format());
@ -28,7 +33,10 @@ fn main() -> Result<()> {
const POWER_THRESHOLD: f32 = 5.0; const POWER_THRESHOLD: f32 = 5.0;
const CLARITY_THRESHOLD: f32 = 0.85; const CLARITY_THRESHOLD: f32 = 0.85;
#[cfg(target_os = "linux")]
const PACKET_LEN: usize = 2204; const PACKET_LEN: usize = 2204;
#[cfg(target_os = "windows")]
const PACKET_LEN: usize = 512;
let stream = device.build_input_stream(&config.into(), let stream = device.build_input_stream(&config.into(),
move | data: &[f32], _: &_| { move | data: &[f32], _: &_| {