From 7c3f845658075b4c309d84e7064f24d55b5dd7bf Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 14 Jan 2026 15:00:54 +1000 Subject: [PATCH] ALSA: Fix a playback data throughput error. This has the data callback handling and the ALSA writing operation in the wrong order. I have no idea how I missed this... --- miniaudio.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 1cb94c32..73e965ac 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -29845,10 +29845,13 @@ static ma_result ma_device_step__alsa(ma_device* pDevice, ma_blocking_mode block } if ((revents & POLLOUT) != 0) { + /* Read data from the client first. */ + ma_device_handle_backend_data_callback(pDevice, pDeviceStateALSA->pIntermediaryBuffer, NULL, pDevice->playback.internalPeriodSizeInFrames); + + /* Now send the data to ALSA for playback. */ resultALSA = pContextStateALSA->snd_pcm_writei(pDeviceStateALSA->pPCMPlayback, pDeviceStateALSA->pIntermediaryBuffer, pDevice->playback.internalPeriodSizeInFrames); if (resultALSA >= 0) { - /* Success. Process the data. */ - ma_device_handle_backend_data_callback(pDevice, pDeviceStateALSA->pIntermediaryBuffer, NULL, (ma_uint32)resultALSA); + /* Success. */ } else { /* Failed. No data processing will be done this iteration. What we do here depends on the type of error. */ if (resultALSA == -EAGAIN) {