qemu/audio
Akihiko Odaki 64abf45516 audio: Use unsigned PCM bias
Clang warns for the uint32_t clip_ instantiations because HALF cannot be
represented with mixeng_real:

[1115/2559] Compiling C object libqemuaudio.a.p/audio_mixeng.c.o
In file included from ../../qemu/audio/mixeng.c:147:
../../qemu/audio/mixeng_template.h:68:70: warning: implicit conversion from 'unsigned int' to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
   68 |     return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF));
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
../../qemu/audio/mixeng_template.h:31:22: note: expanded from macro 'HALF'
   31 | #define HALF (IN_MAX >> 1)
      |                      ^
../../qemu/audio/mixeng.c:146:28: note: expanded from macro 'ENDIAN_CONVERT'
  146 | #define ENDIAN_CONVERT(v) (v)
      |                            ^
In file included from ../../qemu/audio/mixeng.c:152:
../../qemu/audio/mixeng_template.h:68:70: warning: implicit conversion from 'unsigned int' to 'float' changes value from 2147483647 to 2147483648 [-Wimplicit-const-int-float-conversion]
   68 |     return ENDIAN_CONVERT((IN_T)((v * ((mixeng_real)IN_MAX / 2.f)) + HALF));
      |            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~
../../qemu/audio/mixeng_template.h:31:22: note: expanded from macro 'HALF'
   31 | #define HALF (IN_MAX >> 1)
      |                      ^
../../qemu/audio/mixeng.c:151:36: note: expanded from macro 'ENDIAN_CONVERT'
  151 | #define ENDIAN_CONVERT(v) bswap32 (v)
      |                           ~~~~~~~~~^~
/Users/person/v/qemu/include/qemu/bswap.h:10:39: note: expanded from macro 'bswap32'
   10 | #define bswap32(_x) __builtin_bswap32(_x)
      |                                       ^~
2 warnings generated.

HALF is not the right value here anyway. IN_MAX is odd, so the integer
sample range has two middle codes. Unsigned PCM normally uses the upper
middle code as the "bias": 0x80, 0x8000, or 0x80000000. HALF is instead
defined as the lower middle code: 0x7f, 0x7fff, or 0x7fffffff.

Replace HALF with BIAS, defined as the upper middle code. This fixes the
warnings, since the value can be exactly represented with mixeng_real.

Signed-off-by: Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>
Acked-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Message-Id: <20260423-audio-v1-3-e1d6b65c76f9@rsg.ci.i.u-tokyo.ac.jp>
2026-04-28 18:53:58 +04:00
..
alsaaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
audio-be.c audio: constify some add_capture() arguments 2026-02-23 14:38:22 +01:00
audio-hmp-cmds.c audio: deprecate HMP audio commands 2025-10-30 22:59:30 +04:00
audio-mixeng-be.c audio: Add functions to initialize buffers 2026-03-17 21:15:10 +04:00
audio.c audio: split AudioMixengBackend code in audio-mixeng-be.c 2026-02-23 14:38:22 +01:00
audio_int.h audio: Add functions to initialize buffers 2026-03-17 21:15:10 +04:00
audio_template.h audio/mixeng: fix sw/hw mixup in audio_pcm_sw_init_ 2026-03-30 14:02:32 +04:00
audio_win_int.c audio/dsound: replace custom logging with error_report & trace 2026-02-23 14:38:22 +01:00
audio_win_int.h Windows Waveform Audio driver (no ADC support yet) 2009-10-10 01:18:24 +04:00
coreaudio.m coreaudio: Initialize the buffer for device change 2026-03-17 21:15:10 +04:00
dbusaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
dsound_template.h audio: replace int endianness with bool big_endian in audsettings 2026-02-23 14:38:22 +01:00
dsoundaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
jackaudio.c audio/jack: Fix use of qemu_thread_set_name() on macOS 2026-03-08 23:11:14 +01:00
meson.build audio: split AudioMixengBackend code in audio-mixeng-be.c 2026-02-23 14:38:22 +01:00
mixeng.c audio: remove AUD_log/ldebug 2026-02-23 14:38:22 +01:00
mixeng.h audio/replay: fix type punning 2025-10-30 22:56:28 +04:00
mixeng_template.h audio: Use unsigned PCM bias 2026-04-28 18:53:58 +04:00
noaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
ossaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
paaudio.c audio: require pulse >= 0.9.13 2026-02-27 14:48:04 +01:00
pwaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
rate_template.h audio: make the resampling code greedy 2023-03-06 10:30:23 +04:00
sdlaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
sndioaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
spiceaudio.c audio: require spice >= 0.15 2026-02-27 14:48:04 +01:00
trace-events audio: replace remaining dolog() and AUD_log 2026-02-23 14:38:22 +01:00
trace.h trace: switch position of headers to what Meson requires 2020-08-21 06:18:24 -04:00
wavaudio.c audio: remove AudioMixengBackendClass.name 2026-02-23 14:38:22 +01:00
wavcapture.c audio: replace int endianness with bool big_endian in audsettings 2026-02-23 14:38:22 +01:00