fix: fall back to CPAL when ALSA Direct doesn't support sample rate

When hardware doesn't natively support a sample rate (e.g. 176.4kHz),
return None from try_create_direct_stream instead of a hard error.
This lets the player fall through to CPAL/rodio which can resample.

Applied to both hw and plughw paths — InvalidParams on rate now
triggers graceful fallback instead of killing playback.
This commit is contained in:
vicrodh committed 2026-02-28 07:48:03 -06:00
1 parent aff45f98f0
commit 29343e8149
1 file changed
+22
+22
View File
@@ -497,6 +497,17 @@ impl AlsaBackend {
)));
}
if matches!(error, super::backend::AlsaDirectError::InvalidParams(_)) {
// Hardware doesn't support this rate/format natively.
// Return None to let the player fall back to CPAL/rodio
// which can resample (e.g. 176.4kHz → 88.2kHz).
log::info!(
"[ALSA Backend] Hardware doesn't support {}Hz natively, falling back to CPAL (will resample)",
config.sample_rate
);
return None;
}
if !error.allows_plughw_fallback() {
// Non-recoverable error (permissions, etc.)
log::error!("[ALSA Backend] Cannot fallback - error type: {:?}", error);
@@ -550,6 +561,17 @@ impl AlsaBackend {
}
}
if matches!(error, super::backend::AlsaDirectError::InvalidParams(_)) {
// Hardware doesn't support this rate even via plughw.
// Return None to let the player fall back to CPAL/rodio
// which can resample (e.g. 176.4kHz → 88.2kHz).
log::info!(
"[ALSA Backend] Hardware doesn't support {}Hz even via plughw, falling back to CPAL (will resample)",
config.sample_rate
);
return None;
}
log::error!("[ALSA Backend] plughw fallback also failed: {}", e);
Some(Err(format!(
"Bit-perfect playback could not be established. hw failed, plughw failed: {}",