From ff56c5ad24c581fe9e5285a9a53ff923d2f7efd7 Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 10 Oct 2026 18:50:32 +0000 Subject: [PATCH] Audio: the short preview buffer is Linux-only and within the device's range (#614 follow-up) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01QiAJeFttZp83Fh7YuzAR5f --- apps/effectcraft/src/audio_out.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/apps/effectcraft/src/audio_out.rs b/apps/effectcraft/src/audio_out.rs index 7c26db51..7d0ec4b2 100644 --- a/apps/effectcraft/src/audio_out.rs +++ b/apps/effectcraft/src/audio_out.rs @@ -152,7 +152,15 @@ impl AudioDevice for CpalOut { }; let mut cfg: cpal::StreamConfig = sup.config(); cfg.sample_rate = cpal::SampleRate(rate); - cfg.buffer_size = cpal::BufferSize::Fixed(preferred_buffer_frames(rate)); + // A short period only where the default one is long (ALSA/PulseAudio on Linux, #554), + // and only within what the device reports it takes. + if cfg!(target_os = "linux") { + let want = preferred_buffer_frames(rate); + cfg.buffer_size = match sup.buffer_size() { + cpal::SupportedBufferSize::Range { min, max } if *min <= *max => cpal::BufferSize::Fixed(want.clamp(*min, *max)), + _ => cpal::BufferSize::Default, + }; + } let build = |cfg: &cpal::StreamConfig| match sup.sample_format() { cpal::SampleFormat::F32 => run::(&dev, cfg, feed.clone(), latency.clone(), map), cpal::SampleFormat::I16 => run::(&dev, cfg, feed.clone(), latency.clone(), map),