On Wed, Oct 22, 2025 at 11:55 AM Philippe Mathieu-Daudé
<[email protected]> wrote:
>
> @endianness is used as a boolean, rename for clarity.
>
> Signed-off-by: Philippe Mathieu-Daudé <[email protected]>

Reviewed-by: Marc-André Lureau <[email protected]>

> ---
>  audio/alsaaudio.c | 32 ++++++--------------------------
>  audio/ossaudio.c  | 14 +++-----------
>  audio/paaudio.c   |  8 ++++----
>  audio/pwaudio.c   | 12 ++++++------
>  4 files changed, 19 insertions(+), 47 deletions(-)
>
> diff --git a/audio/alsaaudio.c b/audio/alsaaudio.c
> index 89f6dad1a97..7d7da576dc9 100644
> --- a/audio/alsaaudio.c
> +++ b/audio/alsaaudio.c
> @@ -264,7 +264,7 @@ static int alsa_poll_in (HWVoiceIn *hw)
>      return alsa_poll_helper (alsa->handle, &alsa->pollhlp, POLLIN);
>  }
>
> -static snd_pcm_format_t aud_to_alsafmt (AudioFormat fmt, int endianness)
> +static snd_pcm_format_t aud_to_alsafmt(AudioFormat fmt, bool big_endian)
>  {
>      switch (fmt) {
>      case AUDIO_FORMAT_S8:
> @@ -274,39 +274,19 @@ static snd_pcm_format_t aud_to_alsafmt (AudioFormat 
> fmt, int endianness)
>          return SND_PCM_FORMAT_U8;
>
>      case AUDIO_FORMAT_S16:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_S16_BE;
> -        } else {
> -            return SND_PCM_FORMAT_S16_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_S16_BE : SND_PCM_FORMAT_S16_LE;
>
>      case AUDIO_FORMAT_U16:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_U16_BE;
> -        } else {
> -            return SND_PCM_FORMAT_U16_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_U16_BE : SND_PCM_FORMAT_U16_LE;
>
>      case AUDIO_FORMAT_S32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_S32_BE;
> -        } else {
> -            return SND_PCM_FORMAT_S32_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_S32_BE : SND_PCM_FORMAT_S32_LE;
>
>      case AUDIO_FORMAT_U32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_U32_BE;
> -        } else {
> -            return SND_PCM_FORMAT_U32_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_U32_BE : SND_PCM_FORMAT_U32_LE;
>
>      case AUDIO_FORMAT_F32:
> -        if (endianness) {
> -            return SND_PCM_FORMAT_FLOAT_BE;
> -        } else {
> -            return SND_PCM_FORMAT_FLOAT_LE;
> -        }
> +        return big_endian ? SND_PCM_FORMAT_FLOAT_BE : 
> SND_PCM_FORMAT_FLOAT_LE;
>
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", fmt);
> diff --git a/audio/ossaudio.c b/audio/ossaudio.c
> index 86c4805675e..c6cad47a015 100644
> --- a/audio/ossaudio.c
> +++ b/audio/ossaudio.c
> @@ -131,7 +131,7 @@ static void oss_poll_in (HWVoiceIn *hw)
>      qemu_set_fd_handler(oss->fd, oss_helper_poll_in, NULL, hw->s);
>  }
>
> -static int aud_to_ossfmt (AudioFormat fmt, int endianness)
> +static int aud_to_ossfmt(AudioFormat fmt, bool big_endian)
>  {
>      switch (fmt) {
>      case AUDIO_FORMAT_S8:
> @@ -141,18 +141,10 @@ static int aud_to_ossfmt (AudioFormat fmt, int 
> endianness)
>          return AFMT_U8;
>
>      case AUDIO_FORMAT_S16:
> -        if (endianness) {
> -            return AFMT_S16_BE;
> -        } else {
> -            return AFMT_S16_LE;
> -        }
> +        return big_endian ? AFMT_S16_BE : AFMT_S16_LE;
>
>      case AUDIO_FORMAT_U16:
> -        if (endianness) {
> -            return AFMT_U16_BE;
> -        } else {
> -            return AFMT_U16_LE;
> -        }
> +        return big_endian ? AFMT_U16_BE : AFMT_U16_LE;
>
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", fmt);
> diff --git a/audio/paaudio.c b/audio/paaudio.c
> index 6b9b6d219ab..0c06a397195 100644
> --- a/audio/paaudio.c
> +++ b/audio/paaudio.c
> @@ -316,7 +316,7 @@ unlock_and_fail:
>      return 0;
>  }
>
> -static pa_sample_format_t audfmt_to_pa (AudioFormat afmt, int endianness)
> +static pa_sample_format_t audfmt_to_pa(AudioFormat afmt, bool big_endian)
>  {
>      int format;
>
> @@ -327,14 +327,14 @@ static pa_sample_format_t audfmt_to_pa (AudioFormat 
> afmt, int endianness)
>          break;
>      case AUDIO_FORMAT_S16:
>      case AUDIO_FORMAT_U16:
> -        format = endianness ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
> +        format = big_endian ? PA_SAMPLE_S16BE : PA_SAMPLE_S16LE;
>          break;
>      case AUDIO_FORMAT_S32:
>      case AUDIO_FORMAT_U32:
> -        format = endianness ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
> +        format = big_endian ? PA_SAMPLE_S32BE : PA_SAMPLE_S32LE;
>          break;
>      case AUDIO_FORMAT_F32:
> -        format = endianness ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
> +        format = big_endian ? PA_SAMPLE_FLOAT32BE : PA_SAMPLE_FLOAT32LE;
>          break;
>      default:
>          dolog ("Internal logic error: Bad audio format %d\n", afmt);
> diff --git a/audio/pwaudio.c b/audio/pwaudio.c
> index 0fd59d9fe60..30f717ccacf 100644
> --- a/audio/pwaudio.c
> +++ b/audio/pwaudio.c
> @@ -324,7 +324,7 @@ done_unlock:
>  }
>
>  static int
> -audfmt_to_pw(AudioFormat fmt, int endianness)
> +audfmt_to_pw(AudioFormat fmt, bool big_endian)
>  {
>      int format;
>
> @@ -336,19 +336,19 @@ audfmt_to_pw(AudioFormat fmt, int endianness)
>          format = SPA_AUDIO_FORMAT_U8;
>          break;
>      case AUDIO_FORMAT_S16:
> -        format = endianness ? SPA_AUDIO_FORMAT_S16_BE : 
> SPA_AUDIO_FORMAT_S16_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_S16_BE : 
> SPA_AUDIO_FORMAT_S16_LE;
>          break;
>      case AUDIO_FORMAT_U16:
> -        format = endianness ? SPA_AUDIO_FORMAT_U16_BE : 
> SPA_AUDIO_FORMAT_U16_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_U16_BE : 
> SPA_AUDIO_FORMAT_U16_LE;
>          break;
>      case AUDIO_FORMAT_S32:
> -        format = endianness ? SPA_AUDIO_FORMAT_S32_BE : 
> SPA_AUDIO_FORMAT_S32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_S32_BE : 
> SPA_AUDIO_FORMAT_S32_LE;
>          break;
>      case AUDIO_FORMAT_U32:
> -        format = endianness ? SPA_AUDIO_FORMAT_U32_BE : 
> SPA_AUDIO_FORMAT_U32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_U32_BE : 
> SPA_AUDIO_FORMAT_U32_LE;
>          break;
>      case AUDIO_FORMAT_F32:
> -        format = endianness ? SPA_AUDIO_FORMAT_F32_BE : 
> SPA_AUDIO_FORMAT_F32_LE;
> +        format = big_endian ? SPA_AUDIO_FORMAT_F32_BE : 
> SPA_AUDIO_FORMAT_F32_LE;
>          break;
>      default:
>          dolog("Internal logic error: Bad audio format %d\n", fmt);
> --
> 2.51.0
>
>


-- 
Marc-André Lureau

Reply via email to