From e5743d666c1dd90091e5b3a1d038ab48454ae64a Mon Sep 17 00:00:00 2001 From: David Reid Date: Tue, 13 Jan 2026 13:03:15 +1000 Subject: [PATCH] SDL2: Improve Emscripten support by limiting the period size. Setting the period size to something too small results in glitching so this commit will clamp it to a minimum size on the Emscripten build. --- extras/backends/sdl2/miniaudio_sdl2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/extras/backends/sdl2/miniaudio_sdl2.c b/extras/backends/sdl2/miniaudio_sdl2.c index a07e06d3..67df7a42 100644 --- a/extras/backends/sdl2/miniaudio_sdl2.c +++ b/extras/backends/sdl2/miniaudio_sdl2.c @@ -506,6 +506,18 @@ static ma_result ma_device_init_internal__sdl2(ma_device* pDevice, ma_context_st pDescriptor->periodSizeInFrames = ma_next_power_of_2(pDescriptor->periodSizeInFrames); } + /* + In my experience there is glitching with a period size of anything <= 512. To make this "Just Work" on + the Emscripten build we'll set this to 1024. + */ + #if defined(__EMSCRIPTEN__) + { + if (pDescriptor->periodSizeInFrames < 1024) { + pDescriptor->periodSizeInFrames = 1024; + } + } + #endif + /* We now have enough information to set up the device. */ memset(&desiredSpec, 0, sizeof(desiredSpec));