From 56a442a8adf4d875d8077a818b4f8041018342b4 Mon Sep 17 00:00:00 2001 From: David Reid Date: Sat, 11 Aug 2018 20:59:16 +1000 Subject: [PATCH] PulseAudio: Small tweak to the default buffer size on PulseAudio. --- mini_al.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mini_al.h b/mini_al.h index 0b7e8fc6..010530e6 100644 --- a/mini_al.h +++ b/mini_al.h @@ -11993,6 +11993,16 @@ mal_result mal_device_init__pulse(mal_context* pContext, mal_device_type type, c bufferSizeInFrames = pDevice->bufferSizeInFrames; if (bufferSizeInFrames == 0) { bufferSizeInFrames = mal_calculate_buffer_size_in_frames_from_milliseconds(pDevice->bufferSizeInMilliseconds, ss.rate); + + // PulseAudio seems to need a bit of an bit of size to the buffer to be reliable. + if (pDevice->usingDefaultBufferSize) { + float bufferSizeScaleFactor = 1.0f; + if (type == mal_device_type_capture) { + bufferSizeScaleFactor = 2.0f; + } + + bufferSizeInFrames = mal_scale_buffer_size(bufferSizeInFrames, bufferSizeScaleFactor); + } } attr.maxlength = bufferSizeInFrames * mal_get_bytes_per_sample(mal_format_from_pulse(ss.format))*ss.channels;