# SDL: pulseaudio: wait until at least 1/8th (!) of the mixbuffer is available.

**URL:** <https://discourse.libsdl.org/t/sdl-pulseaudio-wait-until-at-least-1-8th-of-the-mixbuffer-is-available/33705>\
**Category:** SDL Commits\
**Created:** [November 26, 2021, 3:38am UTC](https://discourse.libsdl.org/t/sdl-pulseaudio-wait-until-at-least-1-8th-of-the-mixbuffer-is-available/33705 "2021-11-26T03:38:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![SDLPushPostBot](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/sdlpushpostbot/32/4370_2.png) [@SDLPushPostBot](https://discourse.libsdl.org/u/SDLPushPostBot)\
**Post date:** [November 26, 2021, 3:38am UTC](https://discourse.libsdl.org/t/sdl-pulseaudio-wait-until-at-least-1-8th-of-the-mixbuffer-is-available/33705/1 "2021-11-26T03:38:02Z")

</div>

> <https://github.com/libsdl-org/SDL/commit/d713a68071fe3ad8a60be3d92054a04325c5dfd8>
>
> This is to workaround systems where we hang in playback because the buffer
> does …not report the space for whatever reason. The system will instead block
> in PlayDevice, which always immediately follows WaitDevice in modern times
> so this works out, and it seems to keep the device moving forward.
> 
> For a future revision, we are either going to clean this up more properly,
> or attempt to move to PulseAudio's pa\_stream\_set\_write\_callback() API, but
> this will do for SDL 2.0.18.
> 
> Reference #4387 for discussion and further information.

```diff
From d713a68071fe3ad8a60be3d92054a04325c5dfd8 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 25 Nov 2021 22:32:40 -0500
Subject: [PATCH] pulseaudio: wait until at least 1/8th (!) of the mixbuffer is
 available.

This is to workaround systems where we hang in playback because the buffer
does not report the space for whatever reason. The system will instead block
in PlayDevice, which always immediately follows WaitDevice in modern times
so this works out, and it seems to keep the device moving forward.

For a future revision, we are either going to clean this up more properly,
or attempt to move to PulseAudio's pa_stream_set_write_callback() API, but
this will do for SDL 2.0.18.

Reference #4387 for discussion and further information.
---
 src/audio/pulseaudio/SDL_pulseaudio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/audio/pulseaudio/SDL_pulseaudio.c b/src/audio/pulseaudio/SDL_pulseaudio.c
index 4a1823df193..a7e181c93b6 100644
--- a/src/audio/pulseaudio/SDL_pulseaudio.c
+++ b/src/audio/pulseaudio/SDL_pulseaudio.c
@@ -368,7 +368,7 @@ PULSEAUDIO_WaitDevice(_THIS)
             SDL_OpenedAudioDeviceDisconnected(this);
             return;
         }
- if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= h->mixlen) {
+ if (PULSEAUDIO_pa_stream_writable_size(h->stream) >= (h->mixlen/8)) {
             return;
         }
     }

```
