From 98a23f9551844c495238c1fd7f65c8aa61fd0876 Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 13 Jan 2026 10:36:30 +1000 Subject: [PATCH] ALSA: Fix an error with underrun recovery. When an underrun occurs the buffer needs to be filled with data before restarting or else snd_pcm_start() will return EPIPE. --- miniaudio.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/miniaudio.h b/miniaudio.h index ebe6cb7f..cc0d93f0 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -29833,6 +29833,12 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block return ma_result_from_errno((int)-resultALSA); } + /* + Before restarting the PCM we need to make sure there's actually some data in the buffer. We're going to + fill it with silence which is consistent with what we do when we start the PCM normally. + */ + ma_device_prime_playback_buffer__alsa(pDevice); + resultALSA = pContextStateALSA->snd_pcm_start(pDeviceStateALSA->pPCMPlayback); if (resultALSA < 0) { ma_log_postf(ma_device_get_log(pDevice), MA_LOG_LEVEL_ERROR, "[ALSA] Failed to start playback device after underrun. %s.", pContextStateALSA->snd_strerror(resultALSA));