Skip to content

audio: Fix unsigned PCM conversion edge cases

Akihiko Odaki qemu-devel 1 version In review

Get series with b4
b4 am [email protected] change-id 20260423-audio-464e1e90304e

Versions newest first

  1. v1 Latest3 patches 1 replyIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3audio: Avoid unsigned sample wraparoundaudio/mixeng_template.h+2 -20 replies
2/3audio: Clamp unsigned sample conversionaudio/mixeng_template.h+3 -10 replies
3/3audio: Use unsigned PCM biasaudio/mixeng_template.h+7 -90 replies

Reviews trailers per patch

None of the 3 patches has a Reviewed-by or Acked-by of their own; the series has one for all of them.

PatchMarc-André Lureau
SeriesA-b
1/3
2/3
3/3

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v1 thread

Cover letter [PATCH 0/3] audio: Fix unsigned PCM conversion edge cases

Building QEMU with recent Clang from Xcode reports warnings in the unsigned 32-bit PCM clipping helper. The warning points at a real conversion issue: the current code mixes unsigned arithmetic, floating-point rounding, and the wrong midpoint for unsigned PCM samples.

Unsigned PCM uses a bias at the upper middle value of the sample range, such as 0x80, 0x8000, or 0x80000000. The existing HALF value names the lower middle value instead. Around that boundary, the conversion code can also wrap before promotion, and the uint32_t clipping helper can compute a value one past the representable range.

Fix the unsigned conversion paths by:

- converting before subtracting the bias, so samples below the midpoint do not wrap;
- clamping the floating-point clipping result to the integer endpoint;
- replacing HALF with an explicit BIAS value matching unsigned PCM.

---
Akihiko Odaki (3):
audio: Avoid unsigned sample wraparound
audio: Clamp unsigned sample conversion
audio: Use unsigned PCM bias

 audio/mixeng_template.h | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

---
base-commit: 98b060da3a4f92b2a994ead5b16a87e783baf77c
change-id: 20260423-audio-464e1e90304e

Best regards,

Signature · 1 line
Akihiko Odaki <[email protected]>