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:
1 file changed
+22
@@ -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: {}",
|
||||
|
||||
Reference in new issue
Block a user