Skip to content

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

Open
lgirdwood wants to merge 13 commits into
thesofproject:mainfrom
lgirdwood:topic/webrtc-aec-stereo
Open

lgirdwood wants to merge 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 (032bf6eb6), split into 13 small single-concern patches (991f7b95e..df5cfe350), and pairs with thesofproject/sof-test#1369 (topic/webrtc-aec-ssp-loopback) and thesofproject/sof-test#1370 (topic/webrtc-tests).

Note on Signed-off-by: Per AGENTS.md, AI-assisted commits omit Signed-off-by until developer sign-off (git rebase --signoff) is applied by @lgirdwood prior to merge.

Patch Series (991f7b95e..df5cfe350)

  1. audio: webrtc_aec: fix LLEXT math linkage and CMake path — Omit __attribute__((weak)) under LL_EXTENSION_BUILD so Zephyr's Xtensa LLEXT loader relocates webrtc_aec-math.c symbols properly (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 df5cfe350)

  • Zephyr ztest (host/llvm, Clang 20.1.8, CONFIG_COMPILER_WARNINGS_AS_ERRORS=y): 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).
  • WCL Hardware (Ladybird, WCL-U RVP, sof-wcl.ri + sof-wcl-openmodules.ri Float LLEXT):
    • Loaded sof-wcl-rt722-aec.tplg (SDW RT722 speaker ref + SmartMic via webrtc-aec, backend='aec_float', 16 kHz, S32_LE/S16_LE).
    • Verified live aplay + arecord across AEC switch=0 (bypass), AEC switch=1 (S16_LE), and AEC high suppression switch=1 (S32_LE) with 0 DSP panics and 0 kernel errors. (Note: Ladybird RVP hw:0,4 SmartMic has no active physical transducer, so acoustic cancellation magnitude was verified via native_sim ztest while live DSP scheduling/LLEXT execution/controls were verified on Ladybird silicon.)
  • Xtensa DSP builds (zephyr-sdk-1.0.1, CONFIG_COMP_BT_CODEC=n locally due to missing liblc3):
    • intel_adsp/ace30/ptl (AEC3=y): built & linked cleanly.
    • intel_adsp/ace30/ptl (FLOAT=m LLEXT): webrtc_aec.llext + zephyr.elf built cleanly.
    • intel_adsp/ace30/ptl (AECM=m LLEXT): webrtc_aec.llext + zephyr.elf built cleanly.
    • intel_adsp/cavs25/tgph (FLOAT=y): built & linked cleanly.
    • intel_adsp/ace30/wcl (FLOAT=m LLEXT, debug-key signed): sof-wcl.ri + sof-wcl-openmodules.ri built cleanly.
  • Topology2 (alsatplg): All 7 AEC targets + PLATFORM=nvl builds for both cavs-nocodec-webrtc-aec.conf and cavs-dmic-ssp-lbm-webrtc-aec.conf passed with 0 errors.

@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.

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);
}

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);
}

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++)

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.

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];

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.

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;
}

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).

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);
}

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.

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,\

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,\

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

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).

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

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).

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);

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.

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 pushed a commit to lgirdwood/sof that referenced this pull request Nov 27, 2026
Add multi-channel stereo/MIMO processing (up to 4 mic x 4 ref channels),
32 kHz internal sample rate with linear resampler support, and IPC/Kconfig
controls across the Float, AECM, and AEC3 backends.

Addresses PR thesofproject#11545 review feedback:
- Remove hardcoded /home/lrg toolchain fallback in CMakeLists.txt
- Fix IPC3 fragment_size bounds check for payload headers
- Validate dynamic reference stream channels/format on mismatch and check
  src_drop_frames() errors before clamping block frames
- Move per-block int16 scratch buffers (3840 bytes) into comp_data
- Remove dead IPC4_AEC_SET_EXT_FMT stub and integer delay switch overload
- Replace DP-thread AEC3 engine recreation with lock-free atomic state handoff
  applied in prepare()/reset(), support 8 kHz frame sizes, and rebuild
  buffers on init() sample rate change
- Guard against non-positive channel/sample counts in Float/AEC3 downmix
- Extract shared apply_cfg and resampler reset helpers for reset()
- Sync README.md with 32 kHz, up to 4x4 asymmetric R x C, and Kconfig options
lgirdwood pushed a commit to lgirdwood/sof that referenced this pull request Nov 27, 2026
Add Zephyr native_sim unit tests exercising mono 16 kHz, stereo 2x2
16 kHz / 48 kHz resampled echo cancellation (Float and AECM backends),
runtime bypass/suppression/delay controls, and component reset().

Addresses PR thesofproject#11545 review feedback:
- Remove -Wno-implicit-function-declaration and align includes with main
- Unlink buffer list nodes and call comp_free() before buffer_free()
- Replace legacy switch ctl id=2 with backend->set_delay()
lgirdwood pushed a commit to lgirdwood/sof that referenced this pull request Nov 27, 2026
Add 16 kHz and asymmetric 2-ref/1-mic (2r1c) nocodec SSP loopback AEC
topologies along with DMIC + SSP2 loopback AEC topologies for TGL and PTL.

Addresses PR thesofproject#11545 review feedback:
- Set MIC_CH_MAP=0xFFFFFFF0 on sof-ptl-nocodec-webrtc-aec-2r1c
- Match SSP BCLK/FSYNC to 16 kHz (1024000 Hz / 16000 Hz) via literal
  hw_config entries and default_hw_conf_id selection
@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

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

@kv2019i kv2019i 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.

@@ -40,13 +40,30 @@ else()
else()

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.

Signed-off-by missing

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.

$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_dir}/include/c++/14.3.0/xtensa-${_xtensa_target}_zephyr-elf>
$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_dir}/include>
)
set(_sdk_cxx_dir "")

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 doing all sorts of things in a single commit, please split into multiple commits with "one commit per logical change" approach.

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.

Split into 13 small single-concern commits (991f7b95e..df5cfe350): separating LLEXT/CMake linkage, IPC config cleanup, reset/stack safety, dynamic ref source guards, multi-ch asymmetric R x C, 32 kHz resampling, delay/metrics controls, AEC3 MIMO/atomics, docs, ztest, nocodec topology, DMIC+SSP2 topology, and west.yml.

@@ -0,0 +1,140 @@
# SPDX-License-Identifier: BSD-3-Clause

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

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.

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

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

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.

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

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?

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

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

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.

@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.

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

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.
Remove unused sof_ipc4_aec_config and <ipc4/aec.h>, add bounds-checked IPC3
switch control handling and IPC4 get_config fragment_size validation,
clear active module pointer safely in free(), and share webrtc_aec_apply_ctl().
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.
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.
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.
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.
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.
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.
Document 32 kHz resampling support, asymmetric up-to-4x4 R x C MIMO
operation, and all new AEC / AEC3 / Float Kconfig options.
Add Zephyr native_sim 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, runtime controls, and component reset(). Fix source-level
-Wno-double-promotion for Clang CI builds.
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.
Add hybrid DMIC0 capture + SSP2 digital loopback (lbm_mode) speaker
reference AEC topology and TGL/PTL build targets (with nvl mapping).
Update webrtc-apm module revision to 07232bb5e5252210da688796eac66538ca8d5939
with linear-only Classic Float AEC updates.
@lgirdwood
lgirdwood force-pushed the topic/webrtc-aec-stereo branch from 4f70354 to df5cfe3 Compare November 27, 2026 21:10
@lgirdwood

lgirdwood 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

Copy link
Copy Markdown

PR 11545: test results

Run date: 2026-11-27 21:44 UTC

Tested commit: df5cfe350b7a27a10d7cbc786416a9ead62a3e42

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

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