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

Akihiko Odaki posted 3 patches 1 month, 1 week ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260423-audio-v1-0-e1d6b65c76f9@rsg.ci.i.u-tokyo.ac.jp
Maintainers: Gerd Hoffmann <kraxel@redhat.com>, "Marc-André Lureau" <marcandre.lureau@redhat.com>
audio/mixeng_template.h | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
[PATCH 0/3] audio: Fix unsigned PCM conversion edge cases
Posted by Akihiko Odaki 1 month, 1 week ago
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.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
---
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,
--  
Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Re: [PATCH 0/3] audio: Fix unsigned PCM conversion edge cases
Posted by Marc-André Lureau 1 month ago
Hi

On Thu, Apr 23, 2026 at 6:00 PM Akihiko Odaki
<odaki@rsg.ci.i.u-tokyo.ac.jp> wrote:
>
> 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.
>
> Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>

Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>

> ---
> 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,
> --
> Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
>
>