Skip to content

audio: webrtc_aec: add stereo/MIMO AEC, 32 kHz resampling, and SSP loopback tests - #11545

Merged
lgirdwood merged 13 commits into
thesofproject:mainfrom
lgirdwood:topic/webrtc-aec-stereo
Nov 28, 2026
Merged

lgirdwood merged 13 commits into
thesofproject:mainfrom
lgirdwood:topic/webrtc-aec-stereo

Conversation

@lgirdwood

@lgirdwood lgirdwood commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Summary

Rebased cleanly onto main (28cd724d3), split into 13 small single-concern signed-off commits (88cac41ba..a3dac24e4), and pairs with thesofproject/sof-test#1369 (topic/webrtc-aec-ssp-loopback) and thesofproject/sof-test#1370 (topic/webrtc-tests).

Patch Series (88cac41ba..a3dac24e4)

  1. audio: webrtc_aec: fix LLEXT math linkage and CMake path — Omit __attribute__((weak)) under LL_EXTENSION_BUILD with a TODO to restore uniform __attribute__((weak)) linkage once Zephyr's Xtensa llext_link_plt() supports STB_WEAK relocations (fixing a runtime InstFetchPrivilegeCause / PC=0 panic found on WCL hardware), add double-precision wrappers for C++, add non-PIC Xtensa webrtc_aec.cmake flags, and replace the hardcoded toolchain path.
  2. audio: webrtc_aec: clean up IPC3/IPC4 config bounds and dead stub — Drop unused sof_ipc4_aec_config / <ipc4/aec.h>, add bounds-checked IPC3 switch handling, validate get_config size, and share webrtc_aec_apply_ctl().
  3. audio: webrtc_aec: preserve backend config on reset and slim stack — Extract apply_cfg + webrtc_aec_reset_resamplers() for reset() and move 16 kHz scratch arrays from stack to comp_data.
  4. audio: webrtc_aec: dynamically resolve ref source and drop surplus — Dynamic pin/pipeline source resolution, ref channel/format validation on mismatch, error-checked src_drop_frames(), and surplus-only draining in is_ready_to_process().
  5. audio: webrtc_aec: support multi-channel and asymmetric R x C — Decouple mic_channels / ref_channels, remove ch0-cloning so Float and AECm process all mic channels independently, and add CONFIG_WEBRTC_AEC_STEREO_DOWNMIX_REF.
  6. audio: webrtc_aec: add 32 kHz resampling support — 32 kHz ↔ 16 kHz resampling via WebRtcSpl_DownsampleBy2 / UpsampleBy2 (resample_by_2.c).
  7. audio: webrtc_aec: add delay, delay-agnostic, and metrics controls — WEBRTC_AEC_DELAY_MS, WEBRTC_AEC_DELAY_AGNOSTIC, and set_delay() / get_metrics().
  8. audio: webrtc_aec3: support asymmetric R x C MIMO and lock-free ctls — webrtc_aec3_cfg Kconfigs, atomic suppression/delay handoff into prepare() / reset(), 8 kHz support, and buffer rebuilds on init().
  9. docs: webrtc_aec: update README for 32 kHz, 4x4 MIMO, and Kconfigs — Sync src/audio/webrtc_aec/README.md.
  10. test: ztest: add webrtc_aec stereo, bypass, and 32/48 kHz unit tests — native_sim ztest suite (with per-source -Wno-double-promotion for Clang -Werror CI).
  11. topology2: development: parameterize nocodec SSP loopback AEC — Rate-matched hw_config (48 kHz / 16 kHz), nvl platform mapping, -16k and -2r1c targets.
  12. topology2: development: add DMIC + SSP2 loopback AEC topology — Hybrid DMIC0 capture + SSP2 lbm_mode loopback topology with nvl mapping for TGL/PTL.
  13. west.yml: bump webrtc-apm to 07232bb5e525 — Linear-only Classic Float AEC updates (07232bb).

Verification Results (against rebased tree 88cac41ba..a3dac24e4 / prior df5cfe350)

  • Zephyr ztest (host/llvm, Clang 20.1.8, CONFIG_COMPILER_WARNINGS_AS_ERRORS=y): Re-verified on a3dac24e4 — 3/3 passed (test_asymmetric_2r1c_and_2r4c_32k, test_bypass_48k_s32_and_controls, test_stereo_2x2_independence_and_erle with 53.51 dB ERLE).
  • Xtensa PTL Float LLEXT (intel_adsp/ace30/ptl, FLOAT=m, CONFIG_COMP_BT_CODEC=n locally): Re-verified on a3dac24e4 — webrtc_aec.llext (0 WEAK symbols) + zephyr.elf built cleanly.
  • WCL Hardware (Ladybird, WCL-U RVP, sof-wcl.ri + sof-wcl-openmodules.ri Float LLEXT): Verified live aplay + arecord on sof-wcl-rt722-aec.tplg across AEC switch=0, AEC switch=1 (S16_LE), and AEC high suppression switch=1 (S32_LE) with 0 DSP panics or kernel errors.
  • Xtensa (ptl AEC3=y, AECM=m; tgl FLOAT=y) & Topology2 (alsatplg 7 AEC targets + PLATFORM=nvl): Verified on identical pre-comment-only tree df5cfe350.

@lgirdwood lgirdwood changed the title audio: webrtc_aec: add stereo/MIMO AEC, 32 kHz resampling, Float/AEC3 controls, ztest, and SSP loopback topologies audio: webrtc_aec: add stereo/MIMO AEC, 32 kHz resampling, Float/AEC3 controls, west.yml bump, ztest, and SSP loopback topologies Nov 26, 2026

@lgirdwood lgirdwood left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed PR and unit test coverage for stereo/MIMO AEC, 32 kHz resampling, and the SSP loopback topologies.

I reviewed the full PR (noting the first 10 commits are stacked from #11426 and the final 4 commits are new to #11545). Below are the key findings — several blocking correctness/RT/concurrency bugs need addressing before merge:

Blocking / Bugs

  1. Out-of-bounds read in IPC3 set_config (src/audio/webrtc_aec/webrtc_aec.c:820-826): fragment_size is checked against sizeof(struct sof_ipc_ctrl_data) without including sizeof(struct sof_ipc_ctrl_value_chan) for chanv[0].
  2. AEC3 real-time allocation & DP/IPC thread UAF/data race (src/audio/webrtc_aec/webrtc_aec3_wrapper.cpp:121-123, 154-168): webrtc_aec3_buffer_farend() recreates EchoCanceller3 (std::make_unique) inside the audio processing path, racing with webrtc_aec3_set_delay() / webrtc_aec3_set_suppression() called from IPC context. Also hardcodes num_samples != 160, breaking 8 kHz streams.
  3. Dynamic reference bind channel/format mismatch (src/audio/webrtc_aec/webrtc_aec.c:623-667): If capture prepares with 1 source (cd->ref_channels = 1) and a stereo ref binds dynamically in process(), src_to_s16() reads using cd->ref_channels instead of source_get_channels(ref), corrupting the reference stream.
  4. reset() loses backend & resampler state (src/audio/webrtc_aec/webrtc_aec-aec.c:308-311, webrtc_aec-aecm.c:195, webrtc_aec.c:714): WebRtcAec_Init() / WebRtcAecm_Init() reset NLP/CNG/metrics/delay-agnostic settings to defaults and reset() does not re-apply them or clear resampler states.
  5. Infinite recursion in soft-float sqrtf() shims (webrtc_ns-shims.c:242-247, webrtc_ns2-shims.c:209-214, from stacked #11426): sqrtf() calls __builtin_sqrtf(x), which lowers back to sqrtf() on soft-float targets (unlike webrtc_aec-math.c which uses Newton-Raphson).
  6. Broken 16 kHz / 2R×1C topology clock & channel map (tplg-targets.cmake:344, cavs-dmic-ssp-lbm-webrtc-aec.conf:115, cavs-nocodec-webrtc-aec.conf:99,116): MIC_CH_MAP=0 should be 0xFFFFFFF0 (CHANNEL_MAP_MONO), and SSP bclk_freq 3072000 is hardcoded for 48 kHz stereo even in 16 kHz topologies.
  7. Hardcoded developer path in src/audio/webrtc_aec/CMakeLists.txt:55-57 (/home/lrg/zephyr-sdk-1.0.1/...).

Hygiene & Docs

  • CI & mergeability: intel-innersource/sof-pr-test is currently failing and the branch has conflicts against main (mergeable=False).
  • Commit subjects (> 75 chars per AGENTS.md): 12e4e8a81c (86 chars), 8ffbf5801e (83 chars), and 0fd471281c (79 chars).
  • Docs out of sync: src/audio/webrtc_aec/README.md does not document the 7 new Kconfig options, 32 kHz resampling, or 4-ch asymmetric R x C support; src/include/sof/userspace/README.md syscall table does not list the new notifier_event syscall (zephyr/syscall/notifier.c).

Comment thread src/audio/webrtc_aec/CMakeLists.txt Outdated
Comment on lines +55 to +57
if(NOT _sdk_cxx_dir AND EXISTS "/home/lrg/zephyr-sdk-1.0.1/gnu/xtensa-${_xtensa_target}_zephyr-elf/xtensa-${_xtensa_target}_zephyr-elf")
set(_sdk_cxx_dir "/home/lrg/zephyr-sdk-1.0.1/gnu/xtensa-${_xtensa_target}_zephyr-elf/xtensa-${_xtensa_target}_zephyr-elf")
endif()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking: Please remove this hardcoded personal host path (/home/lrg/zephyr-sdk-1.0.1/...). The CMAKE_CXX_COMPILER and ENV{ZEPHYR_SDK_INSTALL_DIR} discovery immediately above already handles SDK lookup portably.

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bd5377: removed the hardcoded /home/lrg toolchain fallback path in src/audio/webrtc_aec/CMakeLists.txt and kept only portable CMAKE_CXX_COMPILER and ENV{ZEPHYR_SDK_INSTALL_DIR} discovery.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
Comment on lines 820 to 826
if (fragment_size >= sizeof(struct sof_ipc_ctrl_data)) {
const struct sof_ipc_ctrl_data *cdata =
(const struct sof_ipc_ctrl_data *)fragment;

comp_err(dev, "webrtc_aec: unknown control id %d", ctl->id);
return -EINVAL;
if (cdata->cmd == SOF_CTRL_CMD_SWITCH && cdata->num_elems >= 1)
return webrtc_aec_apply_ctl(mod, cd, cdata->index, cdata->chanv[0].value);
}

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (Out-of-Bounds Read): struct sof_ipc_ctrl_data ends with a zero-length array chanv[], so sizeof(struct sof_ipc_ctrl_data) does not include chanv[0]. If fragment_size == sizeof(struct sof_ipc_ctrl_data) and num_elems >= 1, reading cdata->chanv[0].value reads past the end of fragment.

Match the IPC4 bounds check above:

Suggested change
if (fragment_size >= sizeof(struct sof_ipc_ctrl_data)) {
const struct sof_ipc_ctrl_data *cdata =
(const struct sof_ipc_ctrl_data *)fragment;
comp_err(dev, "webrtc_aec: unknown control id %d", ctl->id);
return -EINVAL;
if (cdata->cmd == SOF_CTRL_CMD_SWITCH && cdata->num_elems >= 1)
return webrtc_aec_apply_ctl(mod, cd, cdata->index, cdata->chanv[0].value);
}
if (fragment_size >= sizeof(struct sof_ipc_ctrl_data) +
sizeof(struct sof_ipc_ctrl_value_chan)) {
const struct sof_ipc_ctrl_data *cdata =
(const struct sof_ipc_ctrl_data *)fragment;
if (cdata->cmd == SOF_CTRL_CMD_SWITCH && cdata->num_elems >= 1)
return webrtc_aec_apply_ctl(mod, cd, cdata->index, cdata->chanv[0].value);
}

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bd5377: corrected the IPC3 set_config fragment_size bounds check in src/audio/webrtc_aec/webrtc_aec.c to sizeof(struct sof_ipc_ctrl_data) + sizeof(struct sof_ipc_ctrl_value_chan).

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
Comment on lines +651 to +660
ref_s32 = ref ? (source_get_frm_fmt(ref) == SOF_IPC_FRAME_S32_LE) : cd->is_s32;
if (fref > fmic) {
src_drop_frames(ref, fref - fmic);
fref = fmic;
}
if (fref >= n) {
src_to_s16(ref, n, cd->ref_buf, cd->buffered_in_frames, cd->channels, cd->is_s32);
src_to_s16(ref, n, cd->ref_buf, cd->buffered_in_frames, cd->ref_channels, ref_s32);
} else if (fref > 0) {
src_to_s16(ref, fref, cd->ref_buf, cd->buffered_in_frames, cd->channels, cd->is_s32);
for (c = 0; c < cd->channels; c++)
src_to_s16(ref, fref, cd->ref_buf, cd->buffered_in_frames, cd->ref_channels, ref_s32);
for (c = 0; c < cd->ref_channels; c++)

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug (Dynamic ref bind mismatch & unchecked drop):

  1. If webrtc_aec_prepare() ran with num_of_sources == 1, cd->ref_channels was initialized to 1. When a stereo reference source later binds dynamically in process(), src_to_s16() computes frame_bytes = cd->ref_channels * sample_sz instead of source_get_channels(ref) * sample_sz, consuming only half a frame per frame and corrupting ref_buf and alignment. Validate source_get_channels(ref) == cd->ref_channels (and that ref format is S16_LE or S32_LE) or fall back to silence / reconfigure before reading.
  2. src_drop_frames() silently ignores errors from source_get_data(), yet line 654 unconditionally assumes fref - fmic frames were dropped and sets fref = fmic.

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bd5377: src_drop_frames() now returns int and is checked before clamping fref = fmic. In addition, webrtc_aec_process() validates dynamic ref channels (ref_ch != cd->ref_channels) and sample format (S16_LE / S32_LE), dropping mismatched ref frames and zero-filling ref_buf with a one-shot comp_warn.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
Comment on lines +492 to +494
int16_t mic16[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K];
int16_t ref16[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K];
int16_t out16[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K];

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design / Stack Usage: These three arrays allocate 4 * 160 * 2 * 3 = 3840 bytes (~3.75 KB) directly on the DSP thread stack inside process() right before calling into WebRTC / C++ AEC frames. Consider moving mic16, ref16, and out16 into struct webrtc_aec_comp_data (or sizing to actual channel count) to keep stack usage bounded.

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bd5377: moved mic16, ref16, and out16 (3840 bytes) off the webrtc_aec_run_block() stack into struct webrtc_aec_comp_data.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
Comment on lines +808 to +818
if (param_id == IPC4_AEC_SET_EXT_FMT) {
if (pos != MODULE_CFG_FRAGMENT_SINGLE ||
fragment_size < sizeof(struct sof_ipc4_aec_config)) {
comp_err(dev, "webrtc_aec: invalid IPC4_AEC_SET_EXT_FMT size %zu",
fragment_size);
return -EINVAL;
}
memcpy(&cd->config, fragment, sizeof(struct sof_ipc4_aec_config));
comp_info(dev, "webrtc_aec: updated IPC4_AEC_SET_EXT_FMT");
return 0;
}

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design:

  1. IPC4_AEC_SET_EXT_FMT copies into cd->config, but cd->config is never read anywhere in webrtc_aec_prepare() or the backends — is this intentionally a stub for a follow-up?
  2. In webrtc_aec_apply_ctl() above, id == 2 (delay_ms, 0..500) is dispatched under SOF_IPC4_SWITCH_CONTROL_PARAM_ID / SOF_CTRL_CMD_SWITCH, which in ALSA/IPC4 represents a boolean (0/1) switch rather than an integer range control (and none of the topology webrtc-aec definitions expose control id == 2 yet).

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0bd5377: removed the dead IPC4_AEC_SET_EXT_FMT / cd->config stub and <ipc4/aec.h> include, and removed the id == 2 (delay_ms) integer overload from the boolean switch controls (SOF_IPC4_SWITCH_CONTROL_PARAM_ID / SOF_CTRL_CMD_SWITCH).

Comment thread src/audio/webrtc_ns2/webrtc_ns2-shims.c Outdated
Comment on lines 209 to 214
__attribute__((weak)) float sqrtf(float x)
{
if (x <= 0.0f)
return 0.0f;
return __builtin_sqrtf(x);
}

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocking (Infinite Recursion on Soft-Float Targets): Same issue as webrtc_ns-shims.c — __builtin_sqrtf(x) inside sqrtf() lowers to a self-recursive call on soft-float targets without hardware FP sqrt. Replace with the Newton-Raphson implementation from webrtc_aec-math.c.

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by rebasing directly onto main (032bf6eb6), where #11426 has already landed—dropping the stale stacked commits and removing webrtc_ns2-shims.c from this PR's diff.

"development/cavs-nocodec-webrtc-aec\;sof-ptl-nocodec-webrtc-aec-16k\;PLATFORM=ptl,\
AEC_RATE=16000,PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-ptl-nocodec-webrtc-aec-16k.bin"
"development/cavs-nocodec-webrtc-aec\;sof-ptl-nocodec-webrtc-aec-2r1c\;PLATFORM=ptl,\
AEC_RATE=16000,MIC_CH=1,REF_CH=2,MIC_CH_CFG=0,MIC_CH_MAP=0,\

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: CHANNEL_MAP_MONO in common_definitions.conf is 0xFFFFFFF0 (bits [3:0]=0, unused slots 0xF), not 0. Passing MIC_CH_MAP=0 maps all 8 channel slots to channel 0.

Suggested change
AEC_RATE=16000,MIC_CH=1,REF_CH=2,MIC_CH_CFG=0,MIC_CH_MAP=0,\
AEC_RATE=16000,MIC_CH=1,REF_CH=2,MIC_CH_CFG=0,MIC_CH_MAP=0xFFFFFFF0,\

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6cdef34: set MIC_CH_MAP=0xFFFFFFF0 on sof-ptl-nocodec-webrtc-aec-2r1c in tools/topology/topology2/development/tplg-targets.cmake.

Object.Base.hw_config.1 {
name "SSP2"
id 0
bclk_freq 3072000

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug (Clock Mismatch on Hardware): AEC_RATE defaults to 16000 in this file, but SSP2 hardcodes bclk_freq 3072000 (48000 * 2ch * 32-bit slot). At 16 kHz / 2ch / 32-bit slot width, bclk_freq should be 1024000 (or computed from $AEC_RATE), otherwise SSP2 runs 3x too fast on Spider/Aphid hardware. The same hardcoded bclk_freq 3072000 affects the new -16k and -2r1c targets in cavs-nocodec-webrtc-aec.conf (lines 99 and 116).

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 6cdef34: updated cavs-dmic-ssp-lbm-webrtc-aec.conf SSP2 to bclk_freq 1024000 / fsync_freq 16000, and updated cavs-nocodec-webrtc-aec.conf SSP0/SSP2 with hw_config.1 (3072000/48000) and hw_config.2 (1024000/16000) selected via default_hw_conf_id $AEC_HW_CONF_ID (AEC_HW_CONF_ID=1 on -16k and -2r1c). All 7 targets pass alsatplg.

target_compile_options(app PRIVATE
-Wno-error=deprecated-declarations
-Wno-double-promotion
-Wno-implicit-function-declaration

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit / Portability: Avoid suppressing -Wno-implicit-function-declaration in unit tests — it hides missing headers and can mask ABI/prototype mismatches (especially on 64-bit native_sim).

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 06efe37: removed -Wno-implicit-function-declaration and updated the includes/sources in test/ztest/unit/audio/webrtc_aec/CMakeLists.txt for main.

Comment on lines +83 to +96
if (ctx->mic_buf) {
free(ctx->mic_buf->source);
buffer_free(ctx->mic_buf);
}
if (ctx->ref_buf) {
free(ctx->ref_buf->source);
buffer_free(ctx->ref_buf);
}
if (ctx->out_buf) {
free(comp_buffer_get_sink_component(ctx->out_buf));
buffer_free(ctx->out_buf);
}
if (ctx->dev)
comp_free(ctx->dev);

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: create_buf() appends mic_buf, ref_buf, and out_buf to dev->bsource_list / dev->bsink_list, and destroy_ctx() frees the buffers with buffer_free() before comp_free(ctx->dev) without unlinking them from the lists. Call comp_free(ctx->dev) first (or unlink sink_list/source_list before buffer_free()) to avoid dangling list pointers.

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 06efe37: unlinked sink_list / source_list nodes via list_item_del(), called comp_free(ctx->dev) before buffer_free(), updated the delay test to use cd->backend->set_delay(), and added webrtc_aec_reset() coverage.

@lgirdwood
lgirdwood force-pushed the topic/webrtc-aec-stereo branch from 0fd4712 to 4f70354 Compare November 27, 2026 13:24
@lgirdwood lgirdwood changed the title audio: webrtc_aec: add stereo/MIMO AEC, 32 kHz resampling, Float/AEC3 controls, west.yml bump, ztest, and SSP loopback topologies audio: webrtc_aec: add stereo/MIMO AEC, 32 kHz resampling, and SSP loopback tests Nov 27, 2026
@lgirdwood

ghost commented Nov 27, 2026

Copy link
Copy Markdown
Member Author

All review comments have been addressed and the branch has been rebased cleanly onto main (032bf6eb6, resolving all merge conflicts and dropping the previously stacked #11426 commits):

  • Rebased commits: 0bd5377d6 (audio), 06efe3780 (ztest), 6cdef34c3 (topology2), 4f703547f (west.yml), plus synced src/audio/webrtc_aec/README.md.
  • Zephyr ztest (native_sim): 3/3 passed (53.51 dB stereo 2x2 ERLE, asymmetric 2x1/2x4 32 kHz, 48 kHz S32_LE bypass/controls/reset).
  • Topology2 (alsatplg): All 7 new/updated AEC targets built cleanly with 0 errors.
  • Xtensa builds (zephyr-sdk-1.0.1, CONFIG_COMP_BT_CODEC=n due to uninitialized local liblc3 module): ptl (AEC3=y, FLOAT=m, AECM=m) and tgl (FLOAT=y) all compiled and linked with 0 webrtc_aec warnings.

@lgirdwood
lgirdwood marked this pull request as ready for review November 27, 2026 16:59

ghost left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit hard to review with lots of different types of changes put into single commits. SOBs missing from all commits.

Comment thread src/audio/webrtc_aec/CMakeLists.txt Resolved
Comment thread src/audio/webrtc_aec/CMakeLists.txt Resolved
@@ -0,0 +1,140 @@
# SPDX-License-Identifier: BSD-3-Clause

ghost Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOB missing

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per AGENTS.md, AI agents do not add Signed-off-by tags; @lgirdwood will apply developer sign-off (git rebase --signoff) prior to merge.

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in rebase onto main (28cd724d3): added Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> across all 13 commits (88cac41ba..a3dac24e4).

@@ -0,0 +1,306 @@
#

ghost Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, SOB missing

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per AGENTS.md, AI agents do not add Signed-off-by tags; @lgirdwood will apply developer sign-off (git rebase --signoff) prior to merge.

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in rebase onto main (28cd724d3): added Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> across all 13 commits (88cac41ba..a3dac24e4).

"adl" "platform/intel/tgl.conf"
"mtl" "platform/intel/mtl.conf"
"lnl" "platform/intel/lnl.conf"
"ptl" "platform/intel/ptl.conf"

ghost Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is missing "nvl". On purpose?

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch — added "nvl" "platform/intel/ptl.conf" to IncludeByKey.PLATFORM in both cavs-dmic-ssp-lbm-webrtc-aec.conf (commit aaa4b0791) and cavs-nocodec-webrtc-aec.conf (commit dc5dd37e0), and verified both build cleanly with PLATFORM=nvl via alsatplg.

Comment thread west.yml
@@ -51,7 +51,7 @@ manifest:
- name: webrtc-apm

ghost Nov 27, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SOF missing

ghost Nov 27, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per AGENTS.md, AI agents do not add Signed-off-by tags; @lgirdwood will apply developer sign-off (git rebase --signoff) prior to merge.

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in rebase onto main (28cd724d3): added Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> across all 13 commits (88cac41ba..a3dac24e4).

ghost left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs split into smaller patches that just deal with 1 thing or a few things if they are tightly bound.

@lgirdwood
lgirdwood force-pushed the topic/webrtc-aec-stereo branch from 4f70354 to df5cfe3 Compare November 27, 2026 21:10
@lgirdwood

ghost commented Nov 27, 2026 •

Copy link
Copy Markdown
Member Author

Updated PR #11545 (HEAD df5cfe350) addressing the latest review feedback and CI failure:

  1. Split into 13 single-concern commits (991f7b95e..df5cfe350) per @kv2019i and @lgirdwood. (Note: Signed-off-by tags are omitted by the AI agent per AGENTS.md and await @lgirdwood running git rebase --signoff before merge.)
  2. Added missing nvl platform mapping ("nvl" "platform/intel/ptl.conf") to both cavs-dmic-ssp-lbm-webrtc-aec.conf and cavs-nocodec-webrtc-aec.conf (verified with PLATFORM=nvl via alsatplg).
  3. Fixed Zephyr Unit Tests (ZTest) CI failure (-Werror,-Wdouble-promotion on host/llvm) in test/ztest/unit/audio/webrtc_aec/CMakeLists.txt by moving -Wno-double-promotion into source-file COMPILE_OPTIONS so it overrides Zephyr's interface -Wdouble-promotion; verified locally with Clang 20.1.8 + CONFIG_COMPILER_WARNINGS_AS_ERRORS=y (3/3 pass, 53.51 dB ERLE).
  4. Tested on Ladybird (WCL-U RVP) with debug-key signed sof-wcl.ri + sof-wcl-openmodules.ri (WEBRTC_AEC_BACKEND_FLOAT=y LLEXT) and sof-wcl-rt722-aec.tplg:
    • Live hardware testing caught a DSP panic (InstFetchPrivilegeCause, PC=0) caused by STB_WEAK linkage in webrtc_aec-math.c (Zephyr's Xtensa LLEXT loader skips STB_WEAK relocations, leaving literal pool entries zeroed).
    • Fixed in 991f7b95e by omitting __attribute__((weak)) under LL_EXTENSION_BUILD; re-tested live aplay/arecord on WCL across AEC switch=0, AEC switch=1 (S16_LE), and AEC high suppression=1 (S32_LE) with 0 DSP panics or kernel errors.

@intel-sofci

ghost commented Nov 27, 2026 •

Copy link
Copy Markdown

PR 11545: test results

Run date: 2026-11-28 18:25 UTC

Tested commit: e4903a7937447dd66184477a641a8349422597c0

mtl pass rate lnl pass rate ptl pass rate wcl pass rate nvl pass rate

Avoid STB_WEAK linkage on math functions under LL_EXTENSION_BUILD so
Zephyr's Xtensa LLEXT loader relocates them properly instead of leaving
zeroed literal pool entries. Add double-precision wrappers (pow, log, log10,
floor, ceil, round, sin, cos) for C++/AEC3 targets, and replace the hardcoded
developer toolchain path in CMakeLists.txt with portable discovery.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/webrtc-aec-stereo branch from df5cfe3 to a3dac24 Compare November 28, 2026 11:55
@lgirdwood

ghost commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Rebased onto latest main (28cd724d3, incorporating #11554 AGENTS.md updates):

  • Added Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com> to all 13 commits (88cac41ba..a3dac24e4).
  • Added TODO comment in src/audio/webrtc_aec/webrtc_aec-math.c (88cac41ba) calling out the LL_EXTENSION_BUILD strong-linkage workaround so uniform __attribute__((weak)) can be restored once Zephyr's Xtensa llext_link_plt() supports STB_WEAK relocations.
  • Re-verified host/llvm ztest (-DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y, 3/3 pass, 53.51 dB ERLE) and intel_adsp/ace30/ptl (FLOAT=m LLEXT, 0 WEAK symbols) on a3dac24e4.

ghost left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs to be ipc4 only, large functions need inline comments.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
Comment on lines +589 to +594
if (id == 0) {
cd->enabled = (value != 0);
comp_info(dev, "webrtc_aec: switch enable = %d", cd->enabled);
return 0;
}
if (id == 1) {

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use macros for the control IDs. These need to align with topology IDs

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7ffd360: added WEBRTC_AEC_CTL_ID_ENABLE (0), WEBRTC_AEC_CTL_ID_HIGH_SUPPRESSION (1), and WEBRTC_AEC_CTL_NUM_ELEMS (1) in src/audio/webrtc_aec/webrtc_aec.h matching the 0-based Object.Control.mixer instances in webrtc-aec.conf, and used them across apply_ctl(), get_config(), and webrtc_aec_ztest.c.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
struct comp_dev *dev = mod->dev;

webrtc_aec_set_active_mod(mod);
#ifdef CONFIG_IPC_MAJOR_4

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be ipc4 code only.

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 7ffd360: added depends on IPC_MAJOR_4 in src/audio/webrtc_aec/Kconfig, removed IPC3 <ipc/control.h> and #ifdef CONFIG_IPC_MAJOR_4 fallbacks in set_config()/get_config(), and migrated test/ztest/unit/audio/webrtc_aec/ to CONFIG_IPC_MAJOR_4=y in da029e7.

Comment thread src/audio/webrtc_aec/webrtc_aec.c Outdated
if (num_of_sources <= 1)
return;

#ifdef CONFIG_IPC_MAJOR_4

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will be ipc4 only.

ghost Nov 28, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 2218d20: removed the pipeline-ID heuristic fallback and unused sink parameters in webrtc_aec_resolve_sources(), resolving mic (queue 0) vs. ref (queue 1) strictly via IPC4_SINK_QUEUE_ID().

Liam Girdwood added 5 commits November 28, 2026 17:07
Require IPC_MAJOR_4 in Kconfig, drop IPC3 switch fallback and pipeline-ID

fallback, use WEBRTC_AEC_CTL_ID_* macros aligned with topology mixer IDs,

remove unused ipc4/aec.h, and validate IPC4 get_config fragment bounds.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Extract apply_cfg helpers in the Float and AECm backends and
webrtc_aec_reset_resamplers() in core so reset() preserves suppression
and clean resampler state. Move 16 kHz resampler scratch buffers from
the real-time thread stack into struct webrtc_aec_comp_data.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Resolve mic and reference sources dynamically per call, validate dynamic
reference stream channel/format mismatches before reading, return errors
from src_drop_frames(), and drain only surplus reference frames when idle.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Decouple microphone and reference channel counts across the core module
and backends, add optional stereo reference downmixing (WEBRTC_AEC_STEREO_DOWNMIX_REF),
and remove ch0-cloning so Float and AECm process all mic channels independently.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Support 32 kHz pipelines via WebRtcSpl_DownsampleBy2 and
WebRtcSpl_UpsampleBy2, adding resample_by_2.c to built-in and LLEXT
builds and stubbing it for stub-backend builds.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Liam Girdwood added 7 commits November 28, 2026 17:09
Add WEBRTC_AEC_DELAY_MS and WEBRTC_AEC_DELAY_AGNOSTIC configuration,
backend set_delay()/get_metrics() hooks, Float metrics reporting, and
configurable msInSndCardBuf delay in Float and AECm backends.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add webrtc_aec3_cfg options and Kconfigs for asymmetric R x C MIMO,
filter blocks, coarse filter fallback, stereo content detection, and external
delay estimation; replace DP-thread reallocation with atomic handoffs; support
8 kHz frames; and add delay/metrics helpers.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Document 32 kHz resampling support, asymmetric up-to-4x4 R x C MIMO
operation, and all new AEC / AEC3 / Float Kconfig options.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add Zephyr native_sim IPC4 unit tests covering stereo 2x2 independence and

ERLE, asymmetric 2R x 1C (16 kHz) and 2R x 4C (32 kHz) multi-channel

processing, 48 kHz S32_LE bypass, IPC4 switch controls via WEBRTC_AEC_CTL_ID_*,

get_configuration readback, and reset(). Reuse unit/common/sof_context.c.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Parameterize sample rate, bits, format, channel counts/maps, and
rate-matched SSP hw_config (48k/16k) on cavs-nocodec-webrtc-aec.conf, add
nvl platform mapping, and add -16k and -2r1c targets.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Add hybrid DMIC0 capture + SSP2 digital loopback (lbm_mode) speaker
reference AEC topology and TGL/PTL build targets (with nvl mapping).

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
Update webrtc-apm module revision to 07232bb5e5252210da688796eac66538ca8d5939
with linear-only Classic Float AEC updates.

Signed-off-by: Liam Girdwood <liam.r.girdwood@linux.intel.com>
@lgirdwood
lgirdwood force-pushed the topic/webrtc-aec-stereo branch from a3dac24 to e4903a7 Compare November 28, 2026 17:09
@lgirdwood

ghost commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

Addressed latest review feedback and force-pushed e4903a7:

  • IPC4-only: Added depends on IPC_MAJOR_4 in src/audio/webrtc_aec/Kconfig, removed IPC3 #else switch and pipeline-ID heuristic fallbacks in webrtc_aec.c (webrtc_aec_resolve_sources(), webrtc_aec_set_config(), webrtc_aec_get_config()), and updated test/ztest/unit/audio/webrtc_aec/ to CONFIG_IPC_MAJOR_4=y using module_adapter_ipc4.c, ipc4_base_module_extended_cfg, SOF_IPC4_SWITCH_CONTROL_PARAM_ID, and IPC4 queue IDs.
  • Control ID macros: Added WEBRTC_AEC_CTL_ID_ENABLE, WEBRTC_AEC_CTL_ID_HIGH_SUPPRESSION, and WEBRTC_AEC_CTL_NUM_ELEMS in webrtc_aec.h aligned with webrtc-aec.conf mixer."1" / mixer."2".
  • Inline comments: Added concise rationale comments across the larger functions in webrtc_aec.c, webrtc_aec-aec.c, webrtc_aec-aecm.c, webrtc_aec-aec3.c, webrtc_aec3_wrapper.cpp, and webrtc_aec_ztest.c.

Verified locally after the rebase on e4903a793 with native_sim ztest (-DCONFIG_COMPILER_WARNINGS_AS_ERRORS=y -DCONFIG_ASAN=y, 3/3 passed).

@lgirdwood

ghost commented Nov 28, 2026

Copy link
Copy Markdown
Member Author

CI unrelated.

@lgirdwood
lgirdwood dismissed kv2019i’s stale review November 28, 2026 20:09

Changes made as requested and agents.md updated to reflect that.

@lgirdwood
lgirdwood merged commit 6cdeb87 into thesofproject:main Nov 28, 2026
@lgirdwood
lgirdwood deleted the topic/webrtc-aec-stereo branch November 28, 2026 20:09
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.

4 participants