WIP: improve Linux audio support

This commit is contained in:
2026-02-03 14:42:03 +01:00
parent 243f76ce05
commit 266a625cf3
4 changed files with 64 additions and 20 deletions

View File

@@ -237,6 +237,12 @@ pub struct AudioStreamConfig {
pub max_voices: usize,
}
pub struct AudioStreamInfo {
pub sample_rate: f32,
pub host_name: String,
pub channels: u16,
}
pub fn build_stream(
config: &AudioStreamConfig,
audio_rx: Receiver<AudioCommand>,
@@ -245,7 +251,7 @@ pub fn build_stream(
metrics: Arc<EngineMetrics>,
initial_samples: Vec<doux::sampling::SampleEntry>,
audio_sample_pos: Arc<AtomicU64>,
) -> Result<(Stream, f32, AnalysisHandle), String> {
) -> Result<(Stream, AudioStreamInfo, AnalysisHandle), String> {
let device = match &config.output_device {
Some(name) => doux::audio::find_output_device(name)
.ok_or_else(|| format!("Device not found: {name}"))?,
@@ -258,11 +264,8 @@ pub fn build_stream(
let max_channels = doux::audio::max_output_channels(&device);
let channels = config.channels.min(max_channels);
let is_jack = doux::audio::preferred_host()
.id()
.name()
.to_lowercase()
.contains("jack");
let host_name = doux::audio::preferred_host().id().name().to_string();
let is_jack = host_name.to_lowercase().contains("jack");
let buffer_size = if config.buffer_size > 0 && !is_jack {
cpal::BufferSize::Fixed(config.buffer_size)
@@ -277,6 +280,7 @@ pub fn build_stream(
};
let sr = sample_rate;
let effective_channels = channels;
let channels = channels as usize;
let max_voices = config.max_voices;
@@ -347,5 +351,10 @@ pub fn build_stream(
stream
.play()
.map_err(|e| format!("Failed to play stream: {e}"))?;
Ok((stream, sample_rate, analysis_handle))
let info = AudioStreamInfo {
sample_rate,
host_name,
channels: effective_channels,
};
Ok((stream, info, analysis_handle))
}