From f15717ba3e973803cfc6a34fae382859cceda1a0 Mon Sep 17 00:00:00 2001 From: David Reid Date: Wed, 14 Jan 2026 16:39:52 +1000 Subject: [PATCH] OSS: Drain the playback device when stopping. --- miniaudio.h | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index 262f9a56..f76776b0 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -39774,7 +39774,8 @@ the moment that's just how it's going to have to be. When starting the device, OSS will automatically start it when write() or read() is called. UPDATE: 2026-01-14 -I'm no longer getting the stop delay when running from inside Virtual Box. +- I'm no longer getting the stop delay when running from inside Virtual Box. +- In playback mode, draining with SNDCTL_DSP_SYNC seems to work as expected. */ static ma_result ma_device_start__oss(ma_device* pDevice) { @@ -39794,10 +39795,13 @@ static ma_result ma_device_start__oss(ma_device* pDevice) static ma_result ma_device_stop__oss(ma_device* pDevice) { - MA_ASSERT(pDevice != NULL); + ma_device_state_oss* pDeviceStateOSS = ma_device_get_backend_state__oss(pDevice); + ma_device_type deviceType = ma_device_get_type(pDevice); - /* See note above on why this is empty. */ - (void)pDevice; + /* Try draining. */ + if (deviceType == ma_device_type_playback || deviceType == ma_device_type_duplex) { + ioctl(pDeviceStateOSS->fdPlayback, SNDCTL_DSP_SYNC, 0); + } return MA_SUCCESS; }