From 7700880b56b12ed6aaf405ca725874c52ddf9b1c Mon Sep 17 00:00:00 2001 From: David Reid Date: Fri, 20 Feb 2026 17:23:42 +1000 Subject: [PATCH] Don't unnecessarily apply clipping. --- miniaudio.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miniaudio.h b/miniaudio.h index 3cd96df5..07633745 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -20626,7 +20626,11 @@ static void ma_device__handle_data_callback(ma_device* pDevice, void* pFramesOut } } - if (!pDevice->noClip && pDevice->playback.format == ma_format_f32) { + /* + Clipping is only necessary when both the external and internal format is f32. For anything else samples + will be clipped naturally as part of format conversion. + */ + if (!pDevice->noClip && pDevice->playback.format == ma_format_f32 && pDevice->playback.internalFormat == ma_format_f32) { ma_clip_samples_f32((float*)pFramesOut, (const float*)pFramesOut, frameCount * pDevice->playback.channels); /* Intentionally specifying the same pointer for both input and output for in-place processing. */ } }