Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions src/audio/webrtc_aec/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.

set(_xtensa_target "intel_ace30_ptl")
endif()
set(_sdk_cxx_dir "/home/lrg/zephyr-sdk-1.0.1/gnu/xtensa-${_xtensa_target}_zephyr-elf/xtensa-${_xtensa_target}_zephyr-elf")

target_include_directories(zephyr_interface SYSTEM BEFORE INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_dir}/include/c++/14.3.0>
$<$<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.

if(CMAKE_CXX_COMPILER)
get_filename_component(_cxx_bin_dir "${CMAKE_CXX_COMPILER}" DIRECTORY)
get_filename_component(_cxx_tc_dir "${_cxx_bin_dir}" DIRECTORY)
if(EXISTS "${_cxx_tc_dir}/xtensa-${_xtensa_target}_zephyr-elf/include/c++")
set(_sdk_cxx_dir "${_cxx_tc_dir}/xtensa-${_xtensa_target}_zephyr-elf")
endif()
endif()
if(NOT _sdk_cxx_dir AND DEFINED ENV{ZEPHYR_SDK_INSTALL_DIR})
set(_sdk_cxx_dir "$ENV{ZEPHYR_SDK_INSTALL_DIR}/gnu/xtensa-${_xtensa_target}_zephyr-elf/xtensa-${_xtensa_target}_zephyr-elf")
endif()

if(_sdk_cxx_dir)
file(GLOB _sdk_cxx_ver_dirs LIST_DIRECTORIES true "${_sdk_cxx_dir}/include/c++/*")
if(_sdk_cxx_ver_dirs)
list(GET _sdk_cxx_ver_dirs 0 _sdk_cxx_ver_dir)
target_include_directories(zephyr_interface SYSTEM BEFORE INTERFACE
$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_ver_dir}>
$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_ver_dir}/xtensa-${_xtensa_target}_zephyr-elf>
$<$<COMPILE_LANGUAGE:CXX>:${_sdk_cxx_dir}/include>
)
endif()
endif()

# Do not link heavy libstdc++.a to prevent out-of-range relocations and unwinder bloat.
# Minimal C++ runtime, new/delete, and exception stubs are provided in webrtc_aec3_shims.cpp.
Expand Down Expand Up @@ -124,6 +141,7 @@ else()

add_local_sources(sof
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/division_operations.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_by_2.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_by_2_internal.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_fractional.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_48khz.c"
Expand All @@ -146,6 +164,7 @@ else()
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/spl_init.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/spl_sqrt.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_48khz.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_by_2.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_by_2_internal.c"
"${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/resample_fractional.c"
)
Expand Down
73 changes: 68 additions & 5 deletions src/audio/webrtc_aec/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,76 @@ config WEBRTC_AEC_SUPPRESSION_LEVEL
2 - medium suppression

config WEBRTC_AEC_SAMPLE_RATE_HZ
int "AECm processing sample rate in Hz"
int "AEC processing sample rate in Hz"
default 16000
help
AECm operates at 8000 or 16000 Hz. When the pipeline runs at a
higher rate (e.g. 48 kHz), the module downsamples before AEC
processing and upsamples afterward. 16 kHz is recommended for
best echo suppression quality.
Native AEC processing sample rate in Hz (8000 or 16000).
When the pipeline runs at 32 kHz or 48 kHz, the module downsamples
to 16 kHz before AEC processing and upsamples afterward. 16 kHz is
recommended for best echo suppression quality.
Valid values: 8000, 16000.

config WEBRTC_AEC_DELAY_MS
int "Nominal echo path / soundcard buffer delay in ms"
range 0 500
default 20
help
Nominal delay in milliseconds between echo reference playback and
microphone capture. Used by AECm/Float AEC (msInSndCardBuf) and by
AEC3 when WEBRTC_AEC_AEC3_EXTERNAL_DELAY_EST is enabled.

config WEBRTC_AEC_STEREO_DOWNMIX_REF
bool "Downmix stereo echo reference to mono before AEC"
default n
help
When enabled, multi-channel echo reference audio is averaged to a
single mono reference channel before feeding the AEC backend,
halving adaptive filter convolution load at the cost of stereo
spatial echo modeling.

config WEBRTC_AEC_STEREO_CONTENT_DETECT
bool "Enable AEC3 stereo content detector"
default y
depends on WEBRTC_AEC_BACKEND_AEC3
help
Allow AEC3 to dynamically detect stereo vs. dual-mono playback
content, using full 2-channel MIMO linear filtering only when
true stereo content is present.

config WEBRTC_AEC_AEC3_EXTERNAL_DELAY_EST
bool "Use fixed external delay estimate in AEC3"
default n
depends on WEBRTC_AEC_BACKEND_AEC3
help
When disabled (recommended), AEC3 uses its internal matched-filter
delay estimator to align render and capture automatically. Enable
to lock AEC3 to WEBRTC_AEC_DELAY_MS for reduced cycle usage when
the hardware echo path delay is fixed and known.

config WEBRTC_AEC_AEC3_FILTER_BLOCKS
int "AEC3 linear adaptive filter length in 4 ms blocks"
range 1 30
default 12
depends on WEBRTC_AEC_BACKEND_AEC3
help
Length of the AEC3 refined/coarse adaptive filter in 4 ms blocks
(e.g., 12 blocks = 48 ms echo tail, 1 block = 4 ms minimal CPU).

config WEBRTC_AEC_AEC3_COARSE_FILTER
bool "Enable AEC3 coarse filter output fallback"
default y
depends on WEBRTC_AEC_BACKEND_AEC3
help
Enable AEC3 coarse linear filter output selection when the refined
filter temporarily diverges.

config WEBRTC_AEC_DELAY_AGNOSTIC
bool "Enable delay-agnostic mode in Classic Float AEC"
default n
depends on WEBRTC_AEC_BACKEND_FLOAT
help
Enable signal-based delay estimation and extended filter mode in
Classic Float AEC so larger or varying echo delays converge without
an exact msInSndCardBuf hint.

endif # COMP_WEBRTC_AEC
18 changes: 13 additions & 5 deletions src/audio/webrtc_aec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ Wraps WebRTC's Acoustic Echo Cancellation algorithms behind the SOF `module_inte
- **Classic Float AEC (MDF)**: Single-precision floating-point Multidelay Block Frequency Domain adaptive filter (`echo_cancellation.c`) for FPU-enabled DSPs.
- **Classic Fixed-Point AECm**: Q15 integer echo canceller (`echo_control_mobile.c`) for low-power DSPs without hardware FPU.
- **Pass-Through Stub**: Zero-dependency pass-through for CI and staging pipeline validation.
- **Stereo 2x2 MIMO Echo Cancellation ($2\text{R} \times 2\text{C}$)**:
- Supports 2 render playback reference channels and 2 microphone capture channels.
- **Virtual Mono Reference Downmix**: Downmixes stereo render channels for the linear adaptive filter subtractor, reducing FFT and partition convolution load by 50%.
- **Stereo Power Tracking & Suppression**: Independent residual echo spectral power estimation per capture channel with a joint psychoacoustic suppression envelope.
- **Multi-Channel & Asymmetric Echo Cancellation ($R\text{R} \times C\text{C}$, up to $4 \times 4$)**:
- Decoupled reference (`ref_channels`) and microphone (`mic_channels`) counts (`WEBRTC_AEC_CHANNELS_MAX = 4`), eliminating ch0 output cloning.
- Supports $1\text{R} \times N\text{C}$, $2\text{R} \times 2\text{C}$, asymmetric $2\text{R} \times 1\text{C}$ / $2\text{R} \times 4\text{C}$, and optional multi-channel reference downmixing (`CONFIG_WEBRTC_AEC_STEREO_DOWNMIX_REF`).
- **Multi-Rate Pipeline Support**: Native 8 kHz / 16 kHz plus WebRTC SPL resampling for 32 kHz (`WebRtcSpl_DownsampleBy2` / `UpsampleBy2`) and 48 kHz (`WebRtcSpl_Resample48khzTo16khz` / `16khzTo48khz`).
- **AEC3 Stereo Power Tracking & Suppression**: Full $R \times C$ `EchoCanceller3::CreateDefaultMultichannelConfig()` support with configurable filter length, coarse filter fallback, stereo content detector, and external/internal delay estimation.
- **DSP Mathematical Accelerations**:
- **Fast Ooura RDFT**: 128-point split-radix real discrete Fourier transform replacing generic recursive FFTs.
- **Branchless Soft-Float**: Fast mantissa seed lookup + Newton-Raphson iterations (`FastFloatSqrt`, `FastFloatDiv`).
Expand Down Expand Up @@ -113,7 +114,14 @@ CONFIG_WEBRTC_AEC_SUPPRESSION_LEVEL=1
| `CONFIG_WEBRTC_AEC_PERF_TELEMETRY` | y | bool | Enable real-time cycle profiling via printk |
| `CONFIG_WEBRTC_AEC_FILTER_LEN_MS` | 64 | int (`32`, `64`, `128`) | AECm adaptive filter length in ms |
| `CONFIG_WEBRTC_AEC_SUPPRESSION_LEVEL` | 1 | int (`0` - `2`) | AECm comfort-noise suppression level |
| `CONFIG_WEBRTC_AEC_SAMPLE_RATE_HZ` | 16000 | int (`8000`, `16000`) | Native AEC processing rate |
| `CONFIG_WEBRTC_AEC_SAMPLE_RATE_HZ` | 16000 | int (`8000`, `16000`) | Native AEC processing rate (32/48 kHz resampled) |
| `CONFIG_WEBRTC_AEC_DELAY_MS` | 20 | int (`0` - `500`) | Nominal echo path / soundcard buffer delay in ms |
| `CONFIG_WEBRTC_AEC_STEREO_DOWNMIX_REF` | n | bool | Downmix multi-channel reference to mono before AEC |
| `CONFIG_WEBRTC_AEC_STEREO_CONTENT_DETECT` | y | bool (AEC3) | Dynamic stereo vs. dual-mono content detector |
| `CONFIG_WEBRTC_AEC_AEC3_EXTERNAL_DELAY_EST` | n | bool (AEC3) | Lock AEC3 to `WEBRTC_AEC_DELAY_MS` instead of matched filter |
| `CONFIG_WEBRTC_AEC_AEC3_FILTER_BLOCKS` | 12 | int (`1` - `30`, AEC3) | AEC3 refined/coarse adaptive filter length in 4 ms blocks |
| `CONFIG_WEBRTC_AEC_AEC3_COARSE_FILTER` | y | bool (AEC3) | Enable AEC3 coarse filter output fallback |
| `CONFIG_WEBRTC_AEC_DELAY_AGNOSTIC` | n | bool (Float) | Enable signal-based delay estimation and extended filter |

---

Expand Down
Loading
Loading