From b16c5ab4fc49fca4c3962013bc57306a3b62d3f9 Mon Sep 17 00:00:00 2001 From: Stefan Ghetu Date: Tue, 1 Dec 2026 16:02:39 +0200 Subject: [PATCH] audio: google_rtc_audio_processing: fix the S32 output conversion MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit float_to_s32() rescales the float sample to the 32-bit range and then casts it to int16_t before storing it as int32_t. Every value outside the int16_t range is out of range for the cast, which is undefined behavior; on a host build with gcc it yields 0 for every sample, so an S32 sink receives silence instead of the processed audio. Store the rescaled value through sat_int32() instead. The saturation is needed as well: in float, 1.0f - 1.0f / 2^31 rounds to 1.0f, so a full-scale sample rescales to 2^31, which does not fit in int32_t. The upstream topologies feed the component 16-bit audio, so they do not hit this path, but the component accepts S32 sources and sinks. Fixes: 28a5265568a8 ("google_aec: Rework prepare/process() to support dynamic formats") Signed-off-by: Ștefan Ghețu --- src/audio/google/google_rtc_audio_processing.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/audio/google/google_rtc_audio_processing.c b/src/audio/google/google_rtc_audio_processing.c index 28e36f3eb430..ddacf9a25b2a 100644 --- a/src/audio/google/google_rtc_audio_processing.c +++ b/src/audio/google/google_rtc_audio_processing.c @@ -141,7 +141,8 @@ static ALWAYS_INLINE float s32_to_float(const char *ptr) static ALWAYS_INLINE void float_to_s32(float x, char *dst) { - *(int32_t *)dst = (int16_t)clamp_rescale(-(float)INT_MIN, x); + /* in float, 1.0f - 1.0f / 2^31 rounds to 1.0f, so full scale reaches 2^31 */ + *(int32_t *)dst = sat_int32((int64_t)clamp_rescale(-(float)INT_MIN, x)); } static ALWAYS_INLINE void source_to_float(struct sof_source *src, float **dst_bufs,