Skip to content

audio: google_rtc_audio_processing: fix the S32 output conversion - #11575

Open
ursus161 wants to merge 1 commit into
thesofproject:mainfrom
ursus161:google-rtc-fix-float-to-s32
Open

ursus161 wants to merge 1 commit into
thesofproject:mainfrom
ursus161:google-rtc-fix-float-to-s32

Conversation

@ursus161

@ursus161 ursus161 commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

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 (undefined behavior), so an S32 sink does not get the processed audio.

The fix stores the value through sat_int32(). 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.

Found while looking at the Google RTC AEC component as a stand-in AEC for i.MX8MP (IPC3). The upstream topologies feed the component 16-bit audio, so they do not hit this path today.

Checked on the host with the two conversion functions copied out of the file (gcc, x86):

input before after
0.5 0 1073741824
-0.5 0 -1073741824
1.0 0 2147483647
-1.0 0 -2147483648
1.5 0 2147483647

Not tested on hardware: no in-tree topology uses S32 with this component.

@ursus161
ursus161 requested a review from a team as a code owner December 1, 2026 13:50
@ursus161
ursus161 marked this pull request as draft December 1, 2026 13:50
@ursus161
ursus161 marked this pull request as ready for review December 1, 2026 13:51
@sofci

sofci commented Dec 1, 2026

Copy link
Copy Markdown
Collaborator

Can one of the admins verify this patch?

reply test this please to run this test once

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: 28a5265 ("google_aec: Rework prepare/process() to support dynamic formats")
Signed-off-by: Ștefan Ghețu <stefan.ghetu@nxp.com>
@ursus161
ursus161 force-pushed the google-rtc-fix-float-to-s32 branch from e89033b to b16c5ab Compare December 1, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants