From df4afab893cd16267dd398501c09266705b61572 Mon Sep 17 00:00:00 2001 From: borine <32966433+borine@users.noreply.github.com> Date: Mon, 3 Feb 2025 08:31:07 +0000 Subject: [PATCH] aplay: fix big-endian --- utils/aplay/aplay.c | 4 ++-- utils/aplay/resampler.c | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/utils/aplay/aplay.c b/utils/aplay/aplay.c index ae326411a..383c59112 100644 --- a/utils/aplay/aplay.c +++ b/utils/aplay/aplay.c @@ -511,8 +511,8 @@ static void *io_worker_routine(struct io_worker *w) { pcm_flags = SND_PCM_NO_AUTO_RESAMPLE | SND_PCM_NO_AUTO_FORMAT; /* The libsamplerate resampler uses FLOAT internally, so prefer that if * the ALSA device supports it, to avoid the need to convert; - * otherwise convert to the native endian integer format that is input - * to the resampler. */ + * otherwise use the native endian integer format that is output + * from the resampler. */ format_1 = resampler_preferred_format(); format_2 = resampler_native_format(pcm_format); } diff --git a/utils/aplay/resampler.c b/utils/aplay/resampler.c index 0fecc5e81..08c503b80 100644 --- a/utils/aplay/resampler.c +++ b/utils/aplay/resampler.c @@ -274,10 +274,10 @@ void resampler_format_le_to_native(void *buffer, size_t len, snd_pcm_format_t fo uint32_t *data = buffer; /* Convert to S32 */ for (n = 0; n < len; n++) { - if (data[n] & 0x00800000) - data[n] |= 0xff000000; + if (data[n] & 0x00000800) + data[n] |= 0x000000ff; else - data[n] &= 0x00ffffff; + data[n] &= 0xffffff00; bswap_32(data[n]); } break; @@ -299,7 +299,9 @@ snd_pcm_format_t resampler_native_format(snd_pcm_format_t source_format) { case SND_PCM_FORMAT_S16_LE: return SND_PCM_FORMAT_S16; case SND_PCM_FORMAT_S24_LE: - return SND_PCM_FORMAT_S24; + /* 24bit samples must be converted to 32 bit before passing to + * the resampler */ + return SND_PCM_FORMAT_S32; case SND_PCM_FORMAT_S32_LE: return SND_PCM_FORMAT_S32; default: