Updated cpal dependency

This commit is contained in:
2026-01-21 10:21:31 -05:00
parent ab8abd635b
commit 03d076cb94
3 changed files with 237 additions and 262 deletions

View File

@@ -9,16 +9,20 @@ use std::sync::mpsc::{SyncSender, TrySendError};
use crate::app::debug_plot::DebugPlotSender;
pub struct Audio {
pub stream: cpal::Stream,
pub _stream: cpal::Stream,
}
impl Audio {
pub fn new(
device: &cpal::Device,
device_id: cpal::DeviceId,
config: cpal::StreamConfig,
fft_input: SyncSender<Vec<f32>>,
_plot_tx: DebugPlotSender,
) -> Result<Self> {
let stream = device.build_input_stream(
let host = cpal::default_host();
let device = host
.device_by_id(&device_id)
.ok_or(anyhow::anyhow!("Can't open device."))?;
let _stream = device.build_input_stream(
&config,
move |data: &[f32], _: &cpal::InputCallbackInfo| {
match fft_input.try_send(data.to_vec()) {
@@ -33,7 +37,7 @@ impl Audio {
None,
)?;
Ok(Self { stream })
Ok(Self { _stream })
}
}
impl crate::backend::Device for Audio {
@@ -85,11 +89,15 @@ impl super::Backend for AudioBackend {
egui::ComboBox::from_label("Device")
.selected_text(
self.devices[self.current_device]
.name()
.id()
.map(|id| id.1)
.unwrap_or("UNKNOWN DEVICE".into()),
)
.show_index(ui, &mut self.current_device, self.devices.len(), |i| {
self.devices[i].name().unwrap_or("UNKNOWN DEVICE".into())
self.devices[i]
.id()
.map(|id| id.1)
.unwrap_or("UNKNOWN DEVICE".into())
});
if ui.add(egui::Button::new("Refresh")).clicked() {
self.update_devices();
@@ -103,11 +111,11 @@ impl super::Backend for AudioBackend {
) -> anyhow::Result<Box<dyn super::Device>> {
let config = cpal::StreamConfig {
channels: 1,
sample_rate: cpal::SampleRate(44100),
sample_rate: 44100,
buffer_size: BufferSize::Default,
};
Ok(Box::new(Audio::new(
&self.devices[self.current_device],
self.devices[self.current_device].id()?,
config,
fft_input,
_plot_tx,