diff --git a/src/audio/webrtc_aec/CMakeLists.txt b/src/audio/webrtc_aec/CMakeLists.txt index 196a8a1afc46..d1104b89aef3 100644 --- a/src/audio/webrtc_aec/CMakeLists.txt +++ b/src/audio/webrtc_aec/CMakeLists.txt @@ -40,13 +40,30 @@ else() else() 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 - $<$:${_sdk_cxx_dir}/include/c++/14.3.0> - $<$:${_sdk_cxx_dir}/include/c++/14.3.0/xtensa-${_xtensa_target}_zephyr-elf> - $<$:${_sdk_cxx_dir}/include> - ) + set(_sdk_cxx_dir "") + 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 + $<$:${_sdk_cxx_ver_dir}> + $<$:${_sdk_cxx_ver_dir}/xtensa-${_xtensa_target}_zephyr-elf> + $<$:${_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. @@ -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" @@ -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" ) diff --git a/src/audio/webrtc_aec/Kconfig b/src/audio/webrtc_aec/Kconfig index a91df12ee506..b6eb4e622158 100644 --- a/src/audio/webrtc_aec/Kconfig +++ b/src/audio/webrtc_aec/Kconfig @@ -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 diff --git a/src/audio/webrtc_aec/README.md b/src/audio/webrtc_aec/README.md index a5c34f6c8310..76d1b1da7df2 100644 --- a/src/audio/webrtc_aec/README.md +++ b/src/audio/webrtc_aec/README.md @@ -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`). @@ -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 | --- diff --git a/src/audio/webrtc_aec/webrtc_aec-aec.c b/src/audio/webrtc_aec/webrtc_aec-aec.c index 470f42f69cf6..bd174378e7ea 100644 --- a/src/audio/webrtc_aec/webrtc_aec-aec.c +++ b/src/audio/webrtc_aec/webrtc_aec-aec.c @@ -23,14 +23,17 @@ #include "webrtc_aec.h" #include +#include LOG_MODULE_DECLARE(webrtc_aec, CONFIG_SOF_LOG_LEVEL); struct webrtc_aec_float_data { void *aec[WEBRTC_AEC_CHANNELS_MAX]; - int num_channels; + int num_mic_channels; + int num_ref_channels; int suppression; - float ref_f[WEBRTC_AEC_FRAME_SAMPLES_16K]; + int delay_ms; + float ref_f[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K]; float mic_f[WEBRTC_AEC_FRAME_SAMPLES_16K]; float out_f[WEBRTC_AEC_FRAME_SAMPLES_16K]; }; @@ -44,32 +47,62 @@ static int webrtc_aec_float_init(struct processing_module *mod) if (!rd) return -ENOMEM; + rd->delay_ms = cd->delay_ms; cd->backend_data = rd; comp_info(mod->dev, "webrtc_aec: Classic Float AEC backend initialised"); return 0; } +static int webrtc_aec_float_apply_cfg(struct processing_module *mod, + struct webrtc_aec_float_data *rd, + void *inst, int ch) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct AecCore *core = WebRtcAec_aec_core(inst); + AecConfig config; + int ret; + + if (core && IS_ENABLED(CONFIG_WEBRTC_AEC_DELAY_AGNOSTIC)) { + WebRtcAec_enable_delay_agnostic(core, 1); + WebRtcAec_enable_extended_filter(core, 1); + } + + config.nlpMode = (cd->high_suppression || rd->suppression > 1) ? kAecNlpAggressive : + (rd->suppression == 0) ? kAecNlpConservative : kAecNlpModerate; + config.skewMode = kAecFalse; + config.metricsMode = kAecTrue; + config.delay_logging = kAecFalse; + + ret = WebRtcAec_set_config(inst, config); + if (ret) { + comp_err(mod->dev, "webrtc_aec: set_config ch%d failed %d", ch, ret); + return ret; + } + + return 0; +} + static int webrtc_aec_float_configure(struct processing_module *mod, int sample_rate_hz, - int filter_len_ms, int suppression, int num_channels) + int filter_len_ms, int suppression, + int num_mic_channels, int num_ref_channels) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec_float_data *rd = cd->backend_data; - AecConfig config; int c, ret; /* Free previously allocated handles. */ - for (c = 0; c < rd->num_channels; c++) { + for (c = 0; c < rd->num_mic_channels; c++) { if (rd->aec[c]) { WebRtcAec_Free(rd->aec[c]); rd->aec[c] = NULL; } } - rd->num_channels = 0; - rd->suppression = suppression; + rd->num_mic_channels = 0; + rd->num_ref_channels = num_ref_channels; + rd->suppression = suppression; + rd->delay_ms = cd->delay_ms; - int aec_channels = (num_channels > 1) ? 1 : num_channels; - - for (c = 0; c < aec_channels; c++) { + for (c = 0; c < num_mic_channels; c++) { rd->aec[c] = WebRtcAec_Create(); if (!rd->aec[c]) { comp_err(mod->dev, "webrtc_aec: WebRtcAec_Create() failed ch%d", c); @@ -84,26 +117,18 @@ static int webrtc_aec_float_configure(struct processing_module *mod, int sample_ goto err; } - config.nlpMode = (cd->high_suppression || suppression > 1) ? kAecNlpAggressive : - (suppression == 0) ? kAecNlpConservative : kAecNlpModerate; - config.skewMode = kAecFalse; - config.metricsMode = kAecFalse; - config.delay_logging = kAecFalse; - - ret = WebRtcAec_set_config(rd->aec[c], config); - if (ret) { - comp_err(mod->dev, "webrtc_aec: set_config ch%d failed %d", c, ret); + if (webrtc_aec_float_apply_cfg(mod, rd, rd->aec[c], c)) goto err; - } } - rd->num_channels = aec_channels; - comp_info(mod->dev, "webrtc_aec: Float AEC rate=%d nlpMode=%d ch=%d (stream_ch=%d)", - sample_rate_hz, config.nlpMode, aec_channels, num_channels); + rd->num_mic_channels = num_mic_channels; + comp_info(mod->dev, "webrtc_aec: Float AEC rate=%d high_supp=%d mic_ch=%d ref_ch=%d delay=%dms", + sample_rate_hz, cd->high_suppression, num_mic_channels, num_ref_channels, + rd->delay_ms); return 0; err: - for (c = 0; c < num_channels; c++) { + for (c = 0; c < num_mic_channels; c++) { if (rd->aec[c]) { WebRtcAec_Free(rd->aec[c]); rd->aec[c] = NULL; @@ -124,10 +149,10 @@ static int webrtc_aec_float_set_suppression(struct processing_module *mod, bool config.nlpMode = high_suppression ? kAecNlpAggressive : kAecNlpModerate; config.skewMode = kAecFalse; - config.metricsMode = kAecFalse; + config.metricsMode = kAecTrue; config.delay_logging = kAecFalse; - for (c = 0; c < rd->num_channels; c++) { + for (c = 0; c < rd->num_mic_channels; c++) { if (!rd->aec[c]) continue; ret = WebRtcAec_set_config(rd->aec[c], config); @@ -142,49 +167,70 @@ static int webrtc_aec_float_set_suppression(struct processing_module *mod, bool return 0; } -static int webrtc_aec_float_process_ch(struct processing_module *mod, - const int16_t *mic, const int16_t *ref, int16_t *out, - int frame_samples, int ch) +static int webrtc_aec_float_set_delay(struct processing_module *mod, int delay_ms) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec_float_data *rd = cd->backend_data; + + if (!rd) + return 0; + + rd->delay_ms = delay_ms; + return 0; +} + +static int webrtc_aec_float_get_metrics(struct processing_module *mod, + int *erl_db, int *erle_db, int *delay_ms) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec_float_data *rd = cd->backend_data; + AecMetrics m; + + if (!rd || !rd->aec[0]) + return -EINVAL; + + if (WebRtcAec_GetMetrics(rd->aec[0], &m) != 0) + return -EINVAL; + + if (erl_db) + *erl_db = m.erl.instant; + if (erle_db) + *erle_db = m.erle.instant; + if (delay_ms) + *delay_ms = rd->delay_ms; + return 0; +} + +static int webrtc_aec_float_run_ch(struct processing_module *mod, + struct webrtc_aec_float_data *rd, + const int16_t *mic, const float *ref_f, + int16_t *out, int frame_samples, int ch) +{ const float *const nearend[1] = { rd->mic_f }; float *const out_ptrs[1] = { rd->out_f }; int i, ret; - if (frame_samples > WEBRTC_AEC_FRAME_SAMPLES_16K) - return -EINVAL; - - if (ch >= rd->num_channels || !rd->aec[ch]) { + if (ch >= rd->num_mic_channels || !rd->aec[ch]) { memcpy(out, mic, (size_t)frame_samples * sizeof(int16_t)); return 0; } - /* Convert ref to float and buffer far-end */ - for (i = 0; i < frame_samples; i++) - rd->ref_f[i] = (float)ref[i]; - - ret = WebRtcAec_BufferFarend(rd->aec[ch], rd->ref_f, (size_t)frame_samples); + ret = WebRtcAec_BufferFarend(rd->aec[ch], ref_f, (size_t)frame_samples); if (ret) { comp_err(mod->dev, "webrtc_aec: BufferFarend ch%d failed %d", ch, ret); return ret; } - /* Convert mic to float */ for (i = 0; i < frame_samples; i++) rd->mic_f[i] = (float)mic[i]; - - /* Process near-end (mic) and produce echo-cancelled output. - * Pass 20 ms nominal sound card buffer delay. */ ret = WebRtcAec_Process(rd->aec[ch], nearend, 1, out_ptrs, - (size_t)frame_samples, 20, 0); + (size_t)frame_samples, (int16_t)rd->delay_ms, 0); if (ret) { comp_err(mod->dev, "webrtc_aec: Process ch%d failed %d", ch, ret); return ret; } - /* Convert float output back to int16_t with saturation and rounding */ for (i = 0; i < frame_samples; i++) { float val = rd->out_f[i]; if (val > 32767.0f) @@ -198,18 +244,86 @@ static int webrtc_aec_float_process_ch(struct processing_module *mod, return 0; } +static int webrtc_aec_float_process_frame(struct processing_module *mod, + const int16_t *const *mic, + const int16_t *const *ref, + int16_t *const *out, + int frame_samples, + int num_mic_channels, int num_ref_channels) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec_float_data *rd = cd->backend_data; + int i, c, ret; + + if (frame_samples <= 0 || frame_samples > WEBRTC_AEC_FRAME_SAMPLES_16K || + num_mic_channels <= 0 || num_mic_channels > WEBRTC_AEC_CHANNELS_MAX || + num_ref_channels <= 0 || num_ref_channels > WEBRTC_AEC_CHANNELS_MAX) + return -EINVAL; + + if (num_ref_channels == num_mic_channels) { + for (c = 0; c < num_ref_channels; c++) { + for (i = 0; i < frame_samples; i++) + rd->ref_f[c][i] = (float)ref[c][i]; + } + } else if (num_ref_channels == 1) { + for (i = 0; i < frame_samples; i++) + rd->ref_f[0][i] = (float)ref[0][i]; + } else { + float inv = 1.0f / (float)num_ref_channels; + + for (i = 0; i < frame_samples; i++) { + float acc = 0.0f; + + for (c = 0; c < num_ref_channels; c++) + acc += (float)ref[c][i]; + rd->ref_f[0][i] = acc * inv; + } + } + + for (c = 0; c < num_mic_channels; c++) { + const float *ref_f = (num_ref_channels == num_mic_channels) ? + rd->ref_f[c] : rd->ref_f[0]; + + ret = webrtc_aec_float_run_ch(mod, rd, mic[c], ref_f, out[c], frame_samples, c); + if (ret) + return ret; + } + + return 0; +} + +static int webrtc_aec_float_process_ch(struct processing_module *mod, + const int16_t *mic, const int16_t *ref, int16_t *out, + int frame_samples, int ch) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec_float_data *rd = cd->backend_data; + int i; + + if (frame_samples > WEBRTC_AEC_FRAME_SAMPLES_16K) + return -EINVAL; + + for (i = 0; i < frame_samples; i++) + rd->ref_f[0][i] = (float)ref[i]; + + return webrtc_aec_float_run_ch(mod, rd, mic, rd->ref_f[0], out, frame_samples, ch); +} + static int webrtc_aec_float_reset(struct processing_module *mod) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec_float_data *rd = cd->backend_data; int c, ret; - for (c = 0; c < rd->num_channels; c++) { + for (c = 0; c < rd->num_mic_channels; c++) { if (!rd->aec[c]) continue; ret = WebRtcAec_Init(rd->aec[c], cd->proc_rate, cd->proc_rate); - if (ret) + if (ret) { comp_warn(mod->dev, "webrtc_aec: reset ch%d failed %d", c, ret); + continue; + } + webrtc_aec_float_apply_cfg(mod, rd, rd->aec[c], c); } return 0; } @@ -223,7 +337,7 @@ static int webrtc_aec_float_free(struct processing_module *mod) if (!rd) return 0; - for (c = 0; c < rd->num_channels; c++) { + for (c = 0; c < rd->num_mic_channels; c++) { if (rd->aec[c]) { WebRtcAec_Free(rd->aec[c]); rd->aec[c] = NULL; @@ -239,7 +353,10 @@ const struct webrtc_aec_backend webrtc_aec_backend = { .init = webrtc_aec_float_init, .configure = webrtc_aec_float_configure, .set_suppression = webrtc_aec_float_set_suppression, + .set_delay = webrtc_aec_float_set_delay, + .get_metrics = webrtc_aec_float_get_metrics, .process_ch = webrtc_aec_float_process_ch, + .process_frame = webrtc_aec_float_process_frame, .reset = webrtc_aec_float_reset, .free = webrtc_aec_float_free, }; diff --git a/src/audio/webrtc_aec/webrtc_aec-aec3.c b/src/audio/webrtc_aec/webrtc_aec-aec3.c index bb197e6db260..64ebe554c490 100644 --- a/src/audio/webrtc_aec/webrtc_aec-aec3.c +++ b/src/audio/webrtc_aec/webrtc_aec-aec3.c @@ -22,8 +22,12 @@ LOG_MODULE_DECLARE(webrtc_aec, CONFIG_SOF_LOG_LEVEL); struct webrtc_aec3_data { webrtc_aec3_inst_t *aec3; - int num_channels; + int num_mic_channels; + int num_ref_channels; int suppression; + uint32_t aec3_frames; + uint64_t aec3_ref_cyc; + uint64_t aec3_mic_cyc; float ref_f[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K]; float mic_f[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K]; float out_f[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FRAME_SAMPLES_16K]; @@ -44,31 +48,54 @@ static int webrtc_aec3_backend_init(struct processing_module *mod) } static int webrtc_aec3_backend_configure(struct processing_module *mod, int sample_rate_hz, - int filter_len_ms, int suppression, int num_channels) + int filter_len_ms, int suppression, + int num_mic_channels, int num_ref_channels) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec3_data *rd = cd->backend_data; + struct webrtc_aec3_cfg cfg = { + .sample_rate_hz = sample_rate_hz, + .num_render_channels = (num_ref_channels > WEBRTC_AEC_CHANNELS_MAX) ? + WEBRTC_AEC_CHANNELS_MAX : num_ref_channels, + .num_capture_channels = (num_mic_channels > WEBRTC_AEC_CHANNELS_MAX) ? + WEBRTC_AEC_CHANNELS_MAX : num_mic_channels, + .delay_ms = cd->delay_ms, +#ifdef CONFIG_WEBRTC_AEC_AEC3_FILTER_BLOCKS + .filter_length_blocks = CONFIG_WEBRTC_AEC_AEC3_FILTER_BLOCKS, +#else + .filter_length_blocks = 12, +#endif + .use_external_delay_estimator = IS_ENABLED(CONFIG_WEBRTC_AEC_AEC3_EXTERNAL_DELAY_EST), + .enable_coarse_filter = IS_ENABLED(CONFIG_WEBRTC_AEC_AEC3_COARSE_FILTER), + .detect_stereo_content = IS_ENABLED(CONFIG_WEBRTC_AEC_STEREO_CONTENT_DETECT), + .high_suppression = (cd->high_suppression || suppression > 1), + }; if (rd->aec3) { webrtc_aec3_free(rd->aec3); rd->aec3 = NULL; } - rd->num_channels = 0; - rd->suppression = suppression; + rd->num_mic_channels = 0; + rd->num_ref_channels = 0; + rd->suppression = suppression; + rd->aec3_frames = 0; + rd->aec3_ref_cyc = 0; + rd->aec3_mic_cyc = 0; - int aec_channels = (num_channels > WEBRTC_AEC_CHANNELS_MAX) ? WEBRTC_AEC_CHANNELS_MAX : num_channels; - - rd->aec3 = webrtc_aec3_create(sample_rate_hz, aec_channels, aec_channels); + rd->aec3 = webrtc_aec3_create_cfg(&cfg); if (!rd->aec3) { - comp_err(mod->dev, "webrtc_aec: webrtc_aec3_create() failed rate=%d ch=%d", - sample_rate_hz, aec_channels); + comp_err(mod->dev, "webrtc_aec: webrtc_aec3_create_cfg() failed rate=%d mic=%d ref=%d", + sample_rate_hz, cfg.num_capture_channels, cfg.num_render_channels); return -ENOMEM; } - rd->num_channels = aec_channels; - comp_info(mod->dev, "webrtc_aec: AEC3 configured rate=%d ch=%d (stream_ch=%d)", - sample_rate_hz, aec_channels, num_channels); + rd->num_mic_channels = cfg.num_capture_channels; + rd->num_ref_channels = cfg.num_render_channels; + comp_info(mod->dev, "webrtc_aec: AEC3 configured rate=%d mic=%d ref=%d blocks=%d ext_delay=%d stereo_det=%d", + sample_rate_hz, rd->num_mic_channels, rd->num_ref_channels, + cfg.filter_length_blocks, cfg.use_external_delay_estimator, + cfg.detect_stereo_content); return 0; } @@ -85,11 +112,35 @@ static int webrtc_aec3_backend_set_suppression(struct processing_module *mod, bo return 0; } +static int webrtc_aec3_backend_set_delay(struct processing_module *mod, int delay_ms) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec3_data *rd = cd->backend_data; + + if (!rd || !rd->aec3) + return 0; + + return webrtc_aec3_set_delay(rd->aec3, delay_ms); +} + +static int webrtc_aec3_backend_get_metrics(struct processing_module *mod, + int *erl_db, int *erle_db, int *delay_ms) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec3_data *rd = cd->backend_data; + + if (!rd || !rd->aec3) + return -EINVAL; + + return webrtc_aec3_get_metrics(rd->aec3, erl_db, erle_db, delay_ms); +} + static int webrtc_aec3_backend_process_frame(struct processing_module *mod, const int16_t *const *mic, const int16_t *const *ref, int16_t *const *out, - int frame_samples, int num_channels) + int frame_samples, + int num_mic_channels, int num_ref_channels) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec3_data *rd = cd->backend_data; @@ -97,58 +148,72 @@ static int webrtc_aec3_backend_process_frame(struct processing_module *mod, const float *farend[WEBRTC_AEC_CHANNELS_MAX]; float *out_ptrs[WEBRTC_AEC_CHANNELS_MAX]; int i, ch, ret; - - static uint32_t aec3_frames = 0; - static uint64_t aec3_ref_cyc = 0; - static uint64_t aec3_mic_cyc = 0; +#if IS_ENABLED(CONFIG_WEBRTC_AEC_PERF_TELEMETRY) uint32_t t0, t1, t2; +#endif - if (frame_samples > WEBRTC_AEC_FRAME_SAMPLES_16K || num_channels > WEBRTC_AEC_CHANNELS_MAX) + if (frame_samples <= 0 || frame_samples > WEBRTC_AEC_FRAME_SAMPLES_16K || + num_mic_channels <= 0 || num_mic_channels > WEBRTC_AEC_CHANNELS_MAX || + num_ref_channels <= 0 || num_ref_channels > WEBRTC_AEC_CHANNELS_MAX) return -EINVAL; - if (num_channels != rd->num_channels || !rd->aec3) { - for (ch = 0; ch < num_channels; ch++) + if (num_mic_channels != rd->num_mic_channels || + num_ref_channels != rd->num_ref_channels || !rd->aec3) { + for (ch = 0; ch < num_mic_channels; ch++) memcpy(out[ch], mic[ch], (size_t)frame_samples * sizeof(int16_t)); return 0; } - for (ch = 0; ch < num_channels; ch++) { - for (i = 0; i < frame_samples; i++) { + for (ch = 0; ch < num_ref_channels; ch++) { + for (i = 0; i < frame_samples; i++) rd->ref_f[ch][i] = (float)ref[ch][i]; - rd->mic_f[ch][i] = (float)mic[ch][i]; - } farend[ch] = rd->ref_f[ch]; + } + + for (ch = 0; ch < num_mic_channels; ch++) { + for (i = 0; i < frame_samples; i++) + rd->mic_f[ch][i] = (float)mic[ch][i]; nearend[ch] = rd->mic_f[ch]; out_ptrs[ch] = rd->out_f[ch]; } +#if IS_ENABLED(CONFIG_WEBRTC_AEC_PERF_TELEMETRY) t0 = k_cycle_get_32(); - ret = webrtc_aec3_buffer_farend(rd->aec3, farend, (size_t)num_channels, (size_t)frame_samples); +#endif + ret = webrtc_aec3_buffer_farend(rd->aec3, farend, (size_t)num_ref_channels, + (size_t)frame_samples); +#if IS_ENABLED(CONFIG_WEBRTC_AEC_PERF_TELEMETRY) t1 = k_cycle_get_32(); +#endif if (ret) { comp_err(mod->dev, "webrtc_aec: AEC3 BufferFarend failed %d", ret); return ret; } - ret = webrtc_aec3_process(rd->aec3, nearend, (size_t)num_channels, out_ptrs, (size_t)frame_samples); + ret = webrtc_aec3_process(rd->aec3, nearend, (size_t)num_mic_channels, + out_ptrs, (size_t)frame_samples); +#if IS_ENABLED(CONFIG_WEBRTC_AEC_PERF_TELEMETRY) t2 = k_cycle_get_32(); +#endif if (ret) { comp_err(mod->dev, "webrtc_aec: AEC3 Process failed %d", ret); return ret; } - aec3_ref_cyc += (uint64_t)(t1 - t0); - aec3_mic_cyc += (uint64_t)(t2 - t1); - aec3_frames++; - if (aec3_frames % 20 == 0) { - comp_info(mod->dev, "webrtc_aec3 stereo perf: f=%u ref=%u kcyc mic=%u kcyc tot=%u kcyc", - aec3_frames, - (uint32_t)(aec3_ref_cyc / (aec3_frames * 1000)), - (uint32_t)(aec3_mic_cyc / (aec3_frames * 1000)), - (uint32_t)((aec3_ref_cyc + aec3_mic_cyc) / (aec3_frames * 1000))); +#if IS_ENABLED(CONFIG_WEBRTC_AEC_PERF_TELEMETRY) + rd->aec3_ref_cyc += (uint64_t)(t1 - t0); + rd->aec3_mic_cyc += (uint64_t)(t2 - t1); + rd->aec3_frames++; + if (rd->aec3_frames % 20 == 0) { + comp_info(mod->dev, "webrtc_aec3 (%dx%d) perf: f=%u ref=%u kcyc mic=%u kcyc tot=%u kcyc", + num_ref_channels, num_mic_channels, rd->aec3_frames, + (uint32_t)(rd->aec3_ref_cyc / (rd->aec3_frames * 1000)), + (uint32_t)(rd->aec3_mic_cyc / (rd->aec3_frames * 1000)), + (uint32_t)((rd->aec3_ref_cyc + rd->aec3_mic_cyc) / (rd->aec3_frames * 1000))); } +#endif - for (ch = 0; ch < num_channels; ch++) { + for (ch = 0; ch < num_mic_channels; ch++) { for (i = 0; i < frame_samples; i++) { float val = rd->out_f[ch][i]; if (val > 32767.0f) @@ -172,7 +237,8 @@ static int webrtc_aec3_backend_process_ch(struct processing_module *mod, int16_t *out_arr[1] = { out }; (void)ch; - return webrtc_aec3_backend_process_frame(mod, mic_arr, ref_arr, out_arr, frame_samples, 1); + return webrtc_aec3_backend_process_frame(mod, mic_arr, ref_arr, out_arr, + frame_samples, 1, 1); } static int webrtc_aec3_backend_reset(struct processing_module *mod) @@ -180,9 +246,8 @@ static int webrtc_aec3_backend_reset(struct processing_module *mod) struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec3_data *rd = cd->backend_data; - if (rd && rd->aec3) { + if (rd && rd->aec3) webrtc_aec3_init(rd->aec3, cd->proc_rate); - } return 0; } @@ -208,6 +273,8 @@ const struct webrtc_aec_backend webrtc_aec_backend = { .init = webrtc_aec3_backend_init, .configure = webrtc_aec3_backend_configure, .set_suppression = webrtc_aec3_backend_set_suppression, + .set_delay = webrtc_aec3_backend_set_delay, + .get_metrics = webrtc_aec3_backend_get_metrics, .process_ch = webrtc_aec3_backend_process_ch, .process_frame = webrtc_aec3_backend_process_frame, .reset = webrtc_aec3_backend_reset, diff --git a/src/audio/webrtc_aec/webrtc_aec-aecm.c b/src/audio/webrtc_aec/webrtc_aec-aecm.c index 9b9a674a9745..988acaacf349 100644 --- a/src/audio/webrtc_aec/webrtc_aec-aecm.c +++ b/src/audio/webrtc_aec/webrtc_aec-aecm.c @@ -30,6 +30,7 @@ struct webrtc_aec_real_data { int num_channels; int filter_len_ms; int suppression; + int delay_ms; }; static int webrtc_aec_real_init(struct processing_module *mod) @@ -41,17 +42,40 @@ static int webrtc_aec_real_init(struct processing_module *mod) if (!rd) return -ENOMEM; + rd->delay_ms = cd->delay_ms; cd->backend_data = rd; comp_info(mod->dev, "webrtc_aec: AECm real backend initialised"); return 0; } +static int webrtc_aec_real_apply_cfg(struct processing_module *mod, + struct webrtc_aec_real_data *rd, + void *inst, int ch) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + AecmConfig config; + int ret; + + config.cngMode = (cd->high_suppression || rd->suppression > 0) ? AecmTrue : AecmFalse; + config.echoMode = cd->high_suppression ? 4 : + (rd->filter_len_ms == 128) ? 4 : + (rd->filter_len_ms == 64) ? 3 : + (rd->filter_len_ms == 32) ? 2 : 3; + ret = WebRtcAecm_set_config(inst, config); + if (ret) { + comp_err(mod->dev, "webrtc_aec: set_config ch%d failed %d", ch, ret); + return ret; + } + + return 0; +} + static int webrtc_aec_real_configure(struct processing_module *mod, int sample_rate_hz, - int filter_len_ms, int suppression, int num_channels) + int filter_len_ms, int suppression, + int num_mic_channels, int num_ref_channels) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); struct webrtc_aec_real_data *rd = cd->backend_data; - AecmConfig config; int c, ret; /* Free previously allocated handles. */ @@ -64,8 +88,9 @@ static int webrtc_aec_real_configure(struct processing_module *mod, int sample_r rd->num_channels = 0; rd->filter_len_ms = filter_len_ms; rd->suppression = suppression; + rd->delay_ms = cd->delay_ms; - for (c = 0; c < num_channels; c++) { + for (c = 0; c < num_mic_channels; c++) { rd->aecm[c] = WebRtcAecm_Create(); if (!rd->aecm[c]) { comp_err(mod->dev, "webrtc_aec: WebRtcAecm_Create() failed ch%d", c); @@ -80,25 +105,18 @@ static int webrtc_aec_real_configure(struct processing_module *mod, int sample_r goto err; } - config.cngMode = (cd->high_suppression || suppression > 0) ? AecmTrue : AecmFalse; - config.echoMode = cd->high_suppression ? 4 : - (filter_len_ms == 128) ? 4 : - (filter_len_ms == 64) ? 3 : - (filter_len_ms == 32) ? 2 : 3; - ret = WebRtcAecm_set_config(rd->aecm[c], config); - if (ret) { - comp_err(mod->dev, "webrtc_aec: set_config ch%d failed %d", c, ret); + if (webrtc_aec_real_apply_cfg(mod, rd, rd->aecm[c], c)) goto err; - } } - rd->num_channels = num_channels; - comp_info(mod->dev, "webrtc_aec: AECm rate=%d filter=%dms cng=%d echoMode=%d ch=%d", - sample_rate_hz, filter_len_ms, config.cngMode, config.echoMode, num_channels); + rd->num_channels = num_mic_channels; + comp_info(mod->dev, "webrtc_aec: AECm rate=%d filter=%dms high_supp=%d mic_ch=%d ref_ch=%d delay=%dms", + sample_rate_hz, filter_len_ms, cd->high_suppression, + num_mic_channels, num_ref_channels, rd->delay_ms); return 0; err: - for (c = 0; c < num_channels; c++) { + for (c = 0; c < num_mic_channels; c++) { if (rd->aecm[c]) { WebRtcAecm_Free(rd->aecm[c]); rd->aecm[c] = NULL; @@ -135,6 +153,18 @@ static int webrtc_aec_real_set_suppression(struct processing_module *mod, bool h return 0; } +static int webrtc_aec_real_set_delay(struct processing_module *mod, int delay_ms) +{ + struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + struct webrtc_aec_real_data *rd = cd->backend_data; + + if (!rd) + return 0; + + rd->delay_ms = delay_ms; + return 0; +} + static int webrtc_aec_real_process_ch(struct processing_module *mod, const int16_t *mic, const int16_t *ref, int16_t *out, int frame_samples, int ch) @@ -143,6 +173,11 @@ static int webrtc_aec_real_process_ch(struct processing_module *mod, struct webrtc_aec_real_data *rd = cd->backend_data; int ret; + if (ch >= rd->num_channels || !rd->aecm[ch]) { + memcpy(out, mic, (size_t)frame_samples * sizeof(int16_t)); + return 0; + } + /* Queue the far-end (reference/playback) frame first. */ ret = WebRtcAecm_BufferFarend(rd->aecm[ch], ref, frame_samples); if (ret) { @@ -150,9 +185,9 @@ static int webrtc_aec_real_process_ch(struct processing_module *mod, return ret; } - /* Process near-end (mic) and produce echo-cancelled output. - * Pass 20 ms nominal sound card buffer delay. */ - ret = WebRtcAecm_Process(rd->aecm[ch], mic, NULL, out, frame_samples, 20); + /* Process near-end (mic) and produce echo-cancelled output. */ + ret = WebRtcAecm_Process(rd->aecm[ch], mic, NULL, out, frame_samples, + (int16_t)rd->delay_ms); if (ret) { comp_err(mod->dev, "webrtc_aec: Process ch%d failed %d", ch, ret); return ret; @@ -171,8 +206,11 @@ static int webrtc_aec_real_reset(struct processing_module *mod) if (!rd->aecm[c]) continue; ret = WebRtcAecm_Init(rd->aecm[c], cd->proc_rate); - if (ret) + if (ret) { comp_warn(mod->dev, "webrtc_aec: reset ch%d failed %d", c, ret); + continue; + } + webrtc_aec_real_apply_cfg(mod, rd, rd->aecm[c], c); } return 0; } @@ -202,6 +240,7 @@ const struct webrtc_aec_backend webrtc_aec_backend = { .init = webrtc_aec_real_init, .configure = webrtc_aec_real_configure, .set_suppression = webrtc_aec_real_set_suppression, + .set_delay = webrtc_aec_real_set_delay, .process_ch = webrtc_aec_real_process_ch, .reset = webrtc_aec_real_reset, .free = webrtc_aec_real_free, diff --git a/src/audio/webrtc_aec/webrtc_aec-math.c b/src/audio/webrtc_aec/webrtc_aec-math.c index 0d7e61f8d1ae..f45af30f0725 100644 --- a/src/audio/webrtc_aec/webrtc_aec-math.c +++ b/src/audio/webrtc_aec/webrtc_aec-math.c @@ -9,6 +9,17 @@ #include #include +/* + * Zephyr's Xtensa LLEXT loader only relocates STB_GLOBAL and STB_LOCAL symbols, + * silently skipping STB_WEAK relocations and leaving literal entries zeroed. + * Keep strong linkage when building inside an LLEXT module. + */ +#ifdef LL_EXTENSION_BUILD +#define WEBRTC_MATH_WEAK +#else +#define WEBRTC_MATH_WEAK __attribute__((weak)) +#endif + /* --- helpers --- */ static inline float aec_ldexp2(int n) @@ -42,7 +53,7 @@ static float aec_log2f(float x) } /* --- fast exp2f: split x = n + f, degree-3 polynomial --- */ -float exp2f(float x) +WEBRTC_MATH_WEAK float exp2f(float x) { int n; float f, p; @@ -61,9 +72,7 @@ float exp2f(float x) return p * aec_ldexp2(n); } -#ifdef LL_EXTENSION_BUILD -/* --- sqrtf: not exported by the base firmware, bit estimate + 3 Newton steps --- */ -float sqrtf(float x) +WEBRTC_MATH_WEAK float sqrtf(float x) { union { float f; uint32_t i; } u = { .f = x }; float y; @@ -78,11 +87,10 @@ float sqrtf(float x) y = 0.5f * (y + x / y); return y; } -#endif /* --- powf: x^y = 2^(y * log2(x)) --- */ -float powf(float x, float y) +WEBRTC_MATH_WEAK float powf(float x, float y) { if (x <= 0.0f) return (x == 0.0f && y > 0.0f) ? 0.0f : 1.0f; @@ -95,38 +103,38 @@ float powf(float x, float y) if (y == 2.0f) return x * x; if (y == 0.5f) - return __builtin_sqrtf(x); + return sqrtf(x); return exp2f((float)(y * aec_log2f(x))); } -double pow(double x, double y) +WEBRTC_MATH_WEAK double pow(double x, double y) { return (double)powf((float)x, (float)y); } /* --- logf and log10f --- */ -float logf(float x) +WEBRTC_MATH_WEAK float logf(float x) { return aec_log2f(x) * 0.6931471805599453f; } -double log(double x) +WEBRTC_MATH_WEAK double log(double x) { return (double)logf((float)x); } -float log10f(float x) +WEBRTC_MATH_WEAK float log10f(float x) { return aec_log2f(x) * 0.3010299956639812f; } -double log10(double x) +WEBRTC_MATH_WEAK double log10(double x) { return (double)log10f((float)x); } /* --- floor / ceil / round --- */ -float floorf(float x) +WEBRTC_MATH_WEAK float floorf(float x) { int i = (int)x; if (x < 0.0f && (float)i != x) @@ -134,12 +142,12 @@ float floorf(float x) return (float)i; } -double floor(double x) +WEBRTC_MATH_WEAK double floor(double x) { return (double)floorf((float)x); } -float ceilf(float x) +WEBRTC_MATH_WEAK float ceilf(float x) { int i = (int)x; if (x > 0.0f && (float)i != x) @@ -147,17 +155,17 @@ float ceilf(float x) return (float)i; } -double ceil(double x) +WEBRTC_MATH_WEAK double ceil(double x) { return (double)ceilf((float)x); } -float roundf(float x) +WEBRTC_MATH_WEAK float roundf(float x) { return (x >= 0.0f) ? floorf(x + 0.5f) : ceilf(x - 0.5f); } -double round(double x) +WEBRTC_MATH_WEAK double round(double x) { return (double)roundf((float)x); } @@ -173,7 +181,7 @@ static inline void aec_sincosf_poly(float z, float *s_out, float *c_out) *c_out = 1.0f + z2 * (-0.5f + z2 * (0.041666667f + z2 * (-0.0013888889f + z2 * 0.0000248016f))); } -float sinf(float x) +WEBRTC_MATH_WEAK float sinf(float x) { const float inv_half_pi = 0.636619772367581343f; /* 2 / pi */ const float half_pi_hi = 1.5707963267948966f; @@ -191,12 +199,12 @@ float sinf(float x) } } -double sin(double x) +WEBRTC_MATH_WEAK double sin(double x) { return (double)sinf((float)x); } -float cosf(float x) +WEBRTC_MATH_WEAK float cosf(float x) { const float inv_half_pi = 0.636619772367581343f; const float half_pi_hi = 1.5707963267948966f; @@ -214,7 +222,7 @@ float cosf(float x) } } -double cos(double x) +WEBRTC_MATH_WEAK double cos(double x) { return (double)cosf((float)x); } diff --git a/src/audio/webrtc_aec/webrtc_aec-stub.c b/src/audio/webrtc_aec/webrtc_aec-stub.c index 0ab530b7d404..26a765137af1 100644 --- a/src/audio/webrtc_aec/webrtc_aec-stub.c +++ b/src/audio/webrtc_aec/webrtc_aec-stub.c @@ -19,10 +19,11 @@ static int webrtc_aec_stub_init(struct processing_module *mod) } static int webrtc_aec_stub_configure(struct processing_module *mod, int sample_rate_hz, - int filter_len_ms, int suppression, int num_channels) + int filter_len_ms, int suppression, + int num_mic_channels, int num_ref_channels) { - comp_info(mod->dev, "webrtc_aec stub: rate=%d filter=%dms sup=%d ch=%d (ignored)", - sample_rate_hz, filter_len_ms, suppression, num_channels); + comp_info(mod->dev, "webrtc_aec stub: rate=%d filter=%dms sup=%d mic_ch=%d ref_ch=%d (ignored)", + sample_rate_hz, filter_len_ms, suppression, num_mic_channels, num_ref_channels); return 0; } @@ -44,6 +45,13 @@ static int webrtc_aec_stub_set_suppression(struct processing_module *mod, bool h return 0; } +static int webrtc_aec_stub_set_delay(struct processing_module *mod, int delay_ms) +{ + (void)mod; + (void)delay_ms; + return 0; +} + static int webrtc_aec_stub_reset(struct processing_module *mod) { (void)mod; @@ -61,6 +69,7 @@ const struct webrtc_aec_backend webrtc_aec_backend = { .init = webrtc_aec_stub_init, .configure = webrtc_aec_stub_configure, .set_suppression = webrtc_aec_stub_set_suppression, + .set_delay = webrtc_aec_stub_set_delay, .process_ch = webrtc_aec_stub_process_ch, .reset = webrtc_aec_stub_reset, .free = webrtc_aec_stub_free, diff --git a/src/audio/webrtc_aec/webrtc_aec.c b/src/audio/webrtc_aec/webrtc_aec.c index 7b27f44f1746..b03ee2b07f0a 100644 --- a/src/audio/webrtc_aec/webrtc_aec.c +++ b/src/audio/webrtc_aec/webrtc_aec.c @@ -19,9 +19,11 @@ #include #include #include -#include +#ifdef CONFIG_IPC_MAJOR_4 #include -#include +#else +#include +#endif #include #include #include @@ -49,6 +51,14 @@ static inline void WebRtcSpl_ResetResample16khzTo48khz(void *state) { (void)state; } +static inline void WebRtcSpl_DownsampleBy2(const int16_t *in, size_t len, int16_t *out, int32_t *state) +{ + (void)in; (void)len; (void)out; (void)state; +} +static inline void WebRtcSpl_UpsampleBy2(const int16_t *in, size_t len, int16_t *out, int32_t *state) +{ + (void)in; (void)len; (void)out; (void)state; +} #endif SOF_DEFINE_REG_UUID(webrtc_aec); @@ -169,6 +179,72 @@ static void s16_to_sink(struct sof_sink *dst, int16_t src[][WEBRTC_AEC_FIFO_FRAM sink_commit_buffer(dst, nbytes); } +static int src_drop_frames(struct sof_source *src, int frames) +{ + size_t frame_bytes = source_get_frame_bytes(src); + const void *data_ptr, *buf_start; + size_t buf_size, nbytes; + int err; + + if (frames <= 0 || !frame_bytes) + return 0; + + nbytes = (size_t)frames * frame_bytes; + err = source_get_data(src, nbytes, &data_ptr, &buf_start, &buf_size); + if (err) + return err; + + source_release_data(src, nbytes); + return 0; +} + +static void webrtc_aec_resolve_sources(struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks, + int *mic_idx, int *ref_idx) +{ + *mic_idx = 0; + *ref_idx = -1; + + if (num_of_sources <= 1) + return; + +#ifdef CONFIG_IPC_MAJOR_4 + { + uint32_t q0 = IPC4_SINK_QUEUE_ID(source_get_id(sources[0])); + uint32_t q1 = IPC4_SINK_QUEUE_ID(source_get_id(sources[1])); + + if (q0 != q1) { + if (q0 == 0) { + *mic_idx = 0; + *ref_idx = 1; + } else { + *mic_idx = 1; + *ref_idx = 0; + } + return; + } + } +#endif + + if (num_of_sinks > 0) { + if (source_get_pipeline_id(sources[0]) == sink_get_pipeline_id(sinks[0]) && + source_get_pipeline_id(sources[1]) != sink_get_pipeline_id(sinks[0])) { + *mic_idx = 0; + *ref_idx = 1; + return; + } + if (source_get_pipeline_id(sources[1]) == sink_get_pipeline_id(sinks[0]) && + source_get_pipeline_id(sources[0]) != sink_get_pipeline_id(sinks[0])) { + *mic_idx = 1; + *ref_idx = 0; + return; + } + } + + *mic_idx = 0; + *ref_idx = 1; +} + /* ---------------------------------------------------------------- * module_interface operations * ---------------------------------------------------------------- */ @@ -192,6 +268,12 @@ __cold static int webrtc_aec_init(struct processing_module *mod) cd->backend = &webrtc_aec_backend; cd->enabled = false; cd->high_suppression = false; +#ifdef CONFIG_WEBRTC_AEC_DELAY_MS + cd->delay_ms = CONFIG_WEBRTC_AEC_DELAY_MS; +#else + cd->delay_ms = 20; +#endif + cd->downmix_ref = IS_ENABLED(CONFIG_WEBRTC_AEC_STEREO_DOWNMIX_REF); /* Two input pins: mic + echo reference. */ mod->max_sources = 2; @@ -210,6 +292,27 @@ __cold static int webrtc_aec_init(struct processing_module *mod) return 0; } +static void webrtc_aec_reset_resamplers(struct webrtc_aec_comp_data *cd) +{ + int c; + + if (cd->resamp_mode == WEBRTC_AEC_RESAMP_48_TO_16) { + for (c = 0; c < cd->mic_channels; c++) { + WebRtcSpl_ResetResample48khzTo16khz((void *)&cd->mic_resamp[c]); + WebRtcSpl_ResetResample16khzTo48khz((void *)&cd->out_resamp[c]); + } + for (c = 0; c < cd->ref_channels; c++) + WebRtcSpl_ResetResample48khzTo16khz((void *)&cd->ref_resamp[c]); + } else if (cd->resamp_mode == WEBRTC_AEC_RESAMP_32_TO_16) { + for (c = 0; c < cd->mic_channels; c++) { + memset(cd->mic_resamp32[c], 0, sizeof(cd->mic_resamp32[c])); + memset(cd->out_resamp32[c], 0, sizeof(cd->out_resamp32[c])); + } + for (c = 0; c < cd->ref_channels; c++) + memset(cd->ref_resamp32[c], 0, sizeof(cd->ref_resamp32[c])); + } +} + __cold static int webrtc_aec_prepare(struct processing_module *mod, struct sof_source **sources, int num_of_sources, struct sof_sink **sinks, int num_of_sinks) @@ -227,29 +330,23 @@ __cold static int webrtc_aec_prepare(struct processing_module *mod, return -EINVAL; } - if (num_of_sources == 1) { - cd->mic_src = 0; - cd->ref_src = -1; - } else { -#ifdef CONFIG_IPC_MAJOR_4 - /* Bind order is arbitrary, input pin 0 is mic and pin 1 is reference */ - cd->mic_src = IPC4_SINK_QUEUE_ID(source_get_id(sources[0])) == 0 ? 0 : 1; -#else - /* The mic is the source in the same pipeline as the output */ - cd->mic_src = source_get_pipeline_id(sources[1]) == sink_get_pipeline_id(sinks[0]) && - source_get_pipeline_id(sources[0]) != sink_get_pipeline_id(sinks[0]) ? - 1 : 0; -#endif - cd->ref_src = 1 - cd->mic_src; - } + webrtc_aec_resolve_sources(sources, num_of_sources, sinks, num_of_sinks, + &cd->mic_src, &cd->ref_src); mic_fmt = source_get_frm_fmt(sources[cd->mic_src]); mic_rate = source_get_rate(sources[cd->mic_src]); - cd->channels = source_get_channels(sources[cd->mic_src]); + cd->mic_channels = source_get_channels(sources[cd->mic_src]); if (cd->ref_src >= 0) { +#ifdef CONFIG_IPC_MAJOR_4 + /* Apply reference format override from topology pin descriptor. */ + if (mod->priv.cfg.nb_input_pins > 1 && mod->priv.cfg.input_pins) + ipc4_update_source_format(sources[cd->ref_src], + &mod->priv.cfg.input_pins[1].audio_fmt); +#endif ref_fmt = source_get_frm_fmt(sources[cd->ref_src]); ref_rate = source_get_rate(sources[cd->ref_src]); + cd->ref_channels = source_get_channels(sources[cd->ref_src]); if (mic_rate != ref_rate) { comp_err(dev, "webrtc_aec: mic_rate %d != ref_rate %d", mic_rate, ref_rate); return -EINVAL; @@ -257,37 +354,44 @@ __cold static int webrtc_aec_prepare(struct processing_module *mod, } else { ref_fmt = mic_fmt; ref_rate = mic_rate; + cd->ref_channels = 1; } - if (cd->channels > WEBRTC_AEC_CHANNELS_MAX) { - comp_err(dev, "webrtc_aec: too many channels %d (max %d)", - cd->channels, WEBRTC_AEC_CHANNELS_MAX); + if (cd->mic_channels <= 0 || cd->mic_channels > WEBRTC_AEC_CHANNELS_MAX) { + comp_err(dev, "webrtc_aec: invalid mic_channels %d (max %d)", + cd->mic_channels, WEBRTC_AEC_CHANNELS_MAX); + return -EINVAL; + } + if (cd->ref_channels <= 0 || cd->ref_channels > WEBRTC_AEC_CHANNELS_MAX) { + comp_err(dev, "webrtc_aec: invalid ref_channels %d (max %d)", + cd->ref_channels, WEBRTC_AEC_CHANNELS_MAX); return -EINVAL; } + cd->effective_ref_ch = (cd->downmix_ref && cd->ref_channels > 1) ? 1 : cd->ref_channels; cd->rate = mic_rate; - /* AECm operates at 16 kHz or 8 kHz natively. - * When the pipeline operates at 48 kHz, we use WebRTC APM's fixed-point - * resampler to downsample 48kHz -> 16kHz for AECm and upsample 16kHz -> 48kHz. + /* Backends operate at 16 kHz or 8 kHz natively. + * When the pipeline operates at 32 kHz or 48 kHz, downsample to 16 kHz + * before AEC processing and upsample afterward. */ if (cd->rate == 48000) { cd->proc_rate = 16000; - cd->needs_resample = true; - cd->frame_samples = WEBRTC_AEC_FRAME_SAMPLES_48K; /* 480 samples per 10 ms */ - for (ret = 0; ret < cd->channels; ret++) { - WebRtcSpl_ResetResample48khzTo16khz((void *)&cd->mic_resamp[ret]); - WebRtcSpl_ResetResample48khzTo16khz((void *)&cd->ref_resamp[ret]); - WebRtcSpl_ResetResample16khzTo48khz((void *)&cd->out_resamp[ret]); - } + cd->resamp_mode = WEBRTC_AEC_RESAMP_48_TO_16; + cd->frame_samples = WEBRTC_AEC_FRAME_SAMPLES_48K; + } else if (cd->rate == 32000) { + cd->proc_rate = 16000; + cd->resamp_mode = WEBRTC_AEC_RESAMP_32_TO_16; + cd->frame_samples = WEBRTC_AEC_FRAME_SAMPLES_32K; } else if (cd->rate == 16000 || cd->rate == 8000) { cd->proc_rate = cd->rate; - cd->needs_resample = false; + cd->resamp_mode = WEBRTC_AEC_RESAMP_NONE; cd->frame_samples = (cd->proc_rate * 10) / 1000; } else { - comp_err(dev, "webrtc_aec: unsupported pipeline rate %d (must be 48000, 16000, or 8000)", + comp_err(dev, "webrtc_aec: unsupported pipeline rate %d (must be 48000, 32000, 16000, or 8000)", cd->rate); return -EINVAL; } + webrtc_aec_reset_resamplers(cd); if ((mic_fmt != SOF_IPC_FRAME_S16_LE && mic_fmt != SOF_IPC_FRAME_S32_LE) || (ref_fmt != SOF_IPC_FRAME_S16_LE && ref_fmt != SOF_IPC_FRAME_S32_LE)) { @@ -308,75 +412,288 @@ __cold static int webrtc_aec_prepare(struct processing_module *mod, return -EINVAL; } - comp_info(dev, "webrtc_aec: mic_src=%d ref_src=%d rate=%d/%d ch=%d frame=%d %s resamp=%d", - cd->mic_src, cd->ref_src, cd->rate, cd->proc_rate, cd->channels, - cd->frame_samples, cd->is_s32 ? "S32" : "S16", cd->needs_resample); - -#ifdef CONFIG_IPC_MAJOR_4 - /* Apply reference format override from topology pin descriptor. */ - if (cd->ref_src >= 0) { - if (!mod->priv.cfg.input_pins || mod->priv.cfg.nb_input_pins < 2) { - comp_err(dev, "webrtc_aec: no reference pin format"); - return -EINVAL; - } - ipc4_update_source_format(sources[cd->ref_src], - &mod->priv.cfg.input_pins[1].audio_fmt); - } -#endif + comp_info(dev, "webrtc_aec: mic_src=%d ref_src=%d rate=%d/%d mic_ch=%d ref_ch=%d (eff_ref=%d) frame=%d %s resamp=%d", + cd->mic_src, cd->ref_src, cd->rate, cd->proc_rate, + cd->mic_channels, cd->ref_channels, cd->effective_ref_ch, + cd->frame_samples, cd->is_s32 ? "S32" : "S16", cd->resamp_mode); if (cd->backend->configure) { ret = cd->backend->configure(mod, cd->proc_rate, CONFIG_WEBRTC_AEC_FILTER_LEN_MS, CONFIG_WEBRTC_AEC_SUPPRESSION_LEVEL, - cd->channels); + cd->mic_channels, cd->effective_ref_ch); if (ret) { comp_err(dev, "webrtc_aec: backend configure failed %d", ret); return ret; } } + if (cd->backend->set_delay) + cd->backend->set_delay(mod, cd->delay_ms); + cd->buffered_in_frames = 0; - for (ret = 0; ret < cd->channels; ret++) + for (ret = 0; ret < cd->mic_channels; ret++) memset(cd->out_fifo[ret], 0, sizeof(int16_t) * cd->frame_samples); cd->buffered_out_frames = cd->frame_samples; cd->last_ref_ok = true; + cd->ref_mismatch_warned = false; cd->configured = true; return 0; } +static int webrtc_aec_ref_surplus(struct sof_source *mic, struct sof_source *ref, + int *ref_min_out) +{ + int fmic, fref, ref_min; + size_t ref_fb; + + if (!ref) { + if (ref_min_out) + *ref_min_out = 0; + return 0; + } + + fmic = mic ? (int)source_get_data_frames_available(mic) : 0; + fref = (int)source_get_data_frames_available(ref); + ref_fb = source_get_frame_bytes(ref); + ref_min = ref_fb ? (int)(source_get_min_available(ref) / ref_fb) : 0; + + if (ref_min_out) + *ref_min_out = ref_min; + + /* + * Preserve reference frames matching queued mic backlog (and at least + * one ref period so freshly starting capture remains aligned); only + * frames beyond MAX(fmic, ref_min) are true surplus. + */ + return fref - MAX(fmic, ref_min); +} + +static void webrtc_aec_downmix_ref_s16(int16_t dst[][WEBRTC_AEC_FIFO_FRAMES], + int ref_channels, int nsamp) +{ + int i, c; + + if (ref_channels <= 1) + return; + + for (i = 0; i < nsamp; i++) { + int32_t acc = 0; + + for (c = 0; c < ref_channels; c++) + acc += dst[c][i]; + dst[0][i] = (int16_t)(acc / ref_channels); + } +} + +static void webrtc_aec_run_block(struct processing_module *mod, + struct webrtc_aec_comp_data *cd, int fs) +{ + int c, ret; + + if (!cd->enabled) { + /* Bypassed: pass mic straight through */ + for (c = 0; c < cd->mic_channels; c++) { + memcpy(&cd->out_fifo[c][cd->buffered_out_frames], + cd->mic_buf[c], (size_t)fs * sizeof(int16_t)); + } + return; + } + + if (cd->downmix_ref && cd->ref_channels > 1) + webrtc_aec_downmix_ref_s16(cd->ref_buf, cd->ref_channels, fs); + + if (cd->resamp_mode != WEBRTC_AEC_RESAMP_NONE) { + const int16_t *mic_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + const int16_t *ref_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + int16_t *out_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + + for (c = 0; c < cd->mic_channels; c++) { + if (cd->resamp_mode == WEBRTC_AEC_RESAMP_48_TO_16) + WebRtcSpl_Resample48khzTo16khz(cd->mic_buf[c], cd->mic16[c], + (void *)&cd->mic_resamp[c], + cd->resamp_tmpmem); + else + WebRtcSpl_DownsampleBy2(cd->mic_buf[c], WEBRTC_AEC_FRAME_SAMPLES_32K, + cd->mic16[c], cd->mic_resamp32[c]); + mic_ptrs[c] = cd->mic16[c]; + out_ptrs[c] = cd->out16[c]; + } + + for (c = 0; c < cd->effective_ref_ch; c++) { + if (cd->resamp_mode == WEBRTC_AEC_RESAMP_48_TO_16) + WebRtcSpl_Resample48khzTo16khz(cd->ref_buf[c], cd->ref16[c], + (void *)&cd->ref_resamp[c], + cd->resamp_tmpmem); + else + WebRtcSpl_DownsampleBy2(cd->ref_buf[c], WEBRTC_AEC_FRAME_SAMPLES_32K, + cd->ref16[c], cd->ref_resamp32[c]); + ref_ptrs[c] = cd->ref16[c]; + } + + if (cd->backend->process_frame) { + ret = cd->backend->process_frame(mod, mic_ptrs, ref_ptrs, out_ptrs, + WEBRTC_AEC_FRAME_SAMPLES_16K, + cd->mic_channels, cd->effective_ref_ch); + if (ret) { + for (c = 0; c < cd->mic_channels; c++) + memcpy(cd->out16[c], cd->mic16[c], sizeof(cd->out16[c])); + } + } else { + if (cd->effective_ref_ch > 1 && cd->effective_ref_ch != cd->mic_channels) { + int i; + + for (i = 0; i < WEBRTC_AEC_FRAME_SAMPLES_16K; i++) { + int32_t acc = 0; + + for (c = 0; c < cd->effective_ref_ch; c++) + acc += cd->ref16[c][i]; + cd->ref16[0][i] = (int16_t)(acc / cd->effective_ref_ch); + } + } + + for (c = 0; c < cd->mic_channels; c++) { + const int16_t *ref_ch = (cd->effective_ref_ch == cd->mic_channels) ? + cd->ref16[c] : cd->ref16[0]; + + ret = cd->backend->process_ch(mod, cd->mic16[c], ref_ch, + cd->out16[c], + WEBRTC_AEC_FRAME_SAMPLES_16K, c); + if (ret) + memcpy(cd->out16[c], cd->mic16[c], sizeof(cd->out16[c])); + } + } + + for (c = 0; c < cd->mic_channels; c++) { + if (cd->resamp_mode == WEBRTC_AEC_RESAMP_48_TO_16) + WebRtcSpl_Resample16khzTo48khz(cd->out16[c], + &cd->out_fifo[c][cd->buffered_out_frames], + (void *)&cd->out_resamp[c], + cd->resamp_tmpmem); + else + WebRtcSpl_UpsampleBy2(cd->out16[c], WEBRTC_AEC_FRAME_SAMPLES_16K, + &cd->out_fifo[c][cd->buffered_out_frames], + cd->out_resamp32[c]); + } + return; + } + + /* Native 16 kHz or 8 kHz */ + if (cd->backend->process_frame) { + const int16_t *mic_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + const int16_t *ref_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + int16_t *out_ptrs[WEBRTC_AEC_CHANNELS_MAX]; + + for (c = 0; c < cd->mic_channels; c++) { + mic_ptrs[c] = cd->mic_buf[c]; + out_ptrs[c] = &cd->out_fifo[c][cd->buffered_out_frames]; + } + for (c = 0; c < cd->effective_ref_ch; c++) + ref_ptrs[c] = cd->ref_buf[c]; + + ret = cd->backend->process_frame(mod, mic_ptrs, ref_ptrs, out_ptrs, + fs, cd->mic_channels, cd->effective_ref_ch); + if (ret) { + for (c = 0; c < cd->mic_channels; c++) { + memcpy(&cd->out_fifo[c][cd->buffered_out_frames], + cd->mic_buf[c], (size_t)fs * sizeof(int16_t)); + } + } + } else { + if (cd->effective_ref_ch > 1 && cd->effective_ref_ch != cd->mic_channels) + webrtc_aec_downmix_ref_s16(cd->ref_buf, cd->effective_ref_ch, fs); + + for (c = 0; c < cd->mic_channels; c++) { + const int16_t *ref_ch = (cd->effective_ref_ch == cd->mic_channels) ? + cd->ref_buf[c] : cd->ref_buf[0]; + + ret = cd->backend->process_ch(mod, cd->mic_buf[c], ref_ch, + &cd->out_fifo[c][cd->buffered_out_frames], + fs, c); + if (ret) { + memcpy(&cd->out_fifo[c][cd->buffered_out_frames], + cd->mic_buf[c], (size_t)fs * sizeof(int16_t)); + } + } + } +} + static int webrtc_aec_process(struct processing_module *mod, struct sof_source **sources, int num_of_sources, struct sof_sink **sinks, int num_of_sinks) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); - struct sof_source *mic = sources[cd->mic_src]; - struct sof_source *ref = cd->ref_src >= 0 ? sources[cd->ref_src] : NULL; - struct sof_sink *out = sinks[0]; - int fmic = (int)source_get_data_frames_available(mic); - int fref = ref ? (int)source_get_data_frames_available(ref) : 0; - int n, drain, c; - - if (fmic <= 0) + struct sof_source *mic; + struct sof_source *ref; + struct sof_sink *out; + int mic_idx, ref_idx; + int fmic, fref, n, drain, c, ref_min, surplus; + bool ref_s32; + + if (num_of_sources < 1 || num_of_sinks < 1) return 0; - /* Cap to available space in input accumulation buffers */ + webrtc_aec_resolve_sources(sources, num_of_sources, sinks, num_of_sinks, + &mic_idx, &ref_idx); + cd->mic_src = mic_idx; + cd->ref_src = ref_idx; + + mic = sources[mic_idx]; + ref = ref_idx >= 0 ? sources[ref_idx] : NULL; + out = sinks[0]; + fmic = (int)source_get_data_frames_available(mic); + fref = ref ? (int)source_get_data_frames_available(ref) : 0; + + /* Cap to available space in input accumulation and output sink buffers */ n = MIN(fmic, WEBRTC_AEC_FIFO_FRAMES - cd->buffered_in_frames); - if (n <= 0) + n = MIN(n, (int)sink_get_free_frames(out)); + if (n <= 0) { + surplus = webrtc_aec_ref_surplus(mic, ref, &ref_min); + if (surplus > 0 && surplus >= ref_min) + src_drop_frames(ref, surplus); return 0; + } /* Convert mic input to per-channel S16 */ - src_to_s16(mic, n, cd->mic_buf, cd->buffered_in_frames, cd->channels, cd->is_s32); + src_to_s16(mic, n, cd->mic_buf, cd->buffered_in_frames, cd->mic_channels, cd->is_s32); - /* Convert ref input to per-channel S16; if starved/silent, fill with silence */ + /* + * Validate dynamically attached reference source format/channels and trim + * only genuine surplus beyond queued mic frames so alignment stays intact. + */ + if (ref) { + int ref_ch = source_get_channels(ref); + int ref_fmt = source_get_frm_fmt(ref); + + if (ref_ch != cd->ref_channels || + (ref_fmt != SOF_IPC_FRAME_S16_LE && ref_fmt != SOF_IPC_FRAME_S32_LE)) { + if (!cd->ref_mismatch_warned) { + comp_warn(mod->dev, + "webrtc_aec: ref mismatch ch=%d (exp %d) fmt=%d, dropping", + ref_ch, cd->ref_channels, ref_fmt); + cd->ref_mismatch_warned = true; + } + src_drop_frames(ref, fref); + fref = 0; + ref_s32 = cd->is_s32; + } else { + ref_s32 = (ref_fmt == SOF_IPC_FRAME_S32_LE); + } + } else { + ref_s32 = cd->is_s32; + } + + if (fref > fmic && src_drop_frames(ref, fref - fmic) == 0) + 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++) memset(&cd->ref_buf[c][cd->buffered_in_frames + fref], 0, (size_t)(n - fref) * sizeof(int16_t)); } else { - for (c = 0; c < cd->channels; c++) + for (c = 0; c < cd->ref_channels; c++) memset(&cd->ref_buf[c][cd->buffered_in_frames], 0, (size_t)n * sizeof(int16_t)); } @@ -387,139 +704,18 @@ static int webrtc_aec_process(struct processing_module *mod, while (cd->buffered_in_frames >= cd->frame_samples && cd->buffered_out_frames + cd->frame_samples <= WEBRTC_AEC_FIFO_FRAMES) { int fs = cd->frame_samples; - int ret; - if (!cd->enabled) { - /* Bypassed: pass mic straight through */ - for (c = 0; c < cd->channels; c++) { - memcpy(&cd->out_fifo[c][cd->buffered_out_frames], - cd->mic_buf[c], - (size_t)fs * sizeof(int16_t)); - } - } else if (cd->needs_resample) { - /* 48 kHz -> 16 kHz -> AEC -> 48 kHz */ - if (cd->backend->process_frame) { - 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]; - const int16_t *mic_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - const int16_t *ref_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - int16_t *out_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - - for (c = 0; c < cd->channels; c++) { - WebRtcSpl_Resample48khzTo16khz(cd->mic_buf[c], mic16[c], - (void *)&cd->mic_resamp[c], - cd->resamp_tmpmem); - WebRtcSpl_Resample48khzTo16khz(cd->ref_buf[c], ref16[c], - (void *)&cd->ref_resamp[c], - cd->resamp_tmpmem); - mic_ptrs[c] = mic16[c]; - ref_ptrs[c] = ref16[c]; - out_ptrs[c] = out16[c]; - } - - ret = cd->backend->process_frame(mod, mic_ptrs, ref_ptrs, out_ptrs, - WEBRTC_AEC_FRAME_SAMPLES_16K, - cd->channels); - if (ret) { - for (c = 0; c < cd->channels; c++) - memcpy(out16[c], mic16[c], sizeof(out16[c])); - } - - for (c = 0; c < cd->channels; c++) { - WebRtcSpl_Resample16khzTo48khz(out16[c], - &cd->out_fifo[c][cd->buffered_out_frames], - (void *)&cd->out_resamp[c], - cd->resamp_tmpmem); - } - } else { - for (c = 0; c < cd->channels; c++) { - int16_t mic16[WEBRTC_AEC_FRAME_SAMPLES_16K]; - int16_t ref16[WEBRTC_AEC_FRAME_SAMPLES_16K]; - int16_t out16[WEBRTC_AEC_FRAME_SAMPLES_16K]; - - if (c > 0 && cd->channels > 1) { - /* Replicate processed ch0 to secondary mic channels */ - memcpy(&cd->out_fifo[c][cd->buffered_out_frames], - &cd->out_fifo[0][cd->buffered_out_frames], - (size_t)fs * sizeof(int16_t)); - continue; - } - - WebRtcSpl_Resample48khzTo16khz(cd->mic_buf[c], mic16, - (void *)&cd->mic_resamp[c], - cd->resamp_tmpmem); - WebRtcSpl_Resample48khzTo16khz(cd->ref_buf[c], ref16, - (void *)&cd->ref_resamp[c], - cd->resamp_tmpmem); - - ret = cd->backend->process_ch(mod, - mic16, - ref16, - out16, - WEBRTC_AEC_FRAME_SAMPLES_16K, - c); - if (ret) - memcpy(out16, mic16, sizeof(out16)); - - WebRtcSpl_Resample16khzTo48khz(out16, - &cd->out_fifo[c][cd->buffered_out_frames], - (void *)&cd->out_resamp[c], - cd->resamp_tmpmem); - } - } - } else { - /* Native 16 kHz or 8 kHz */ - if (cd->backend->process_frame) { - const int16_t *mic_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - const int16_t *ref_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - int16_t *out_ptrs[WEBRTC_AEC_CHANNELS_MAX]; - - for (c = 0; c < cd->channels; c++) { - mic_ptrs[c] = cd->mic_buf[c]; - ref_ptrs[c] = cd->ref_buf[c]; - out_ptrs[c] = &cd->out_fifo[c][cd->buffered_out_frames]; - } - - ret = cd->backend->process_frame(mod, mic_ptrs, ref_ptrs, out_ptrs, - fs, cd->channels); - if (ret) { - for (c = 0; c < cd->channels; c++) { - memcpy(&cd->out_fifo[c][cd->buffered_out_frames], - cd->mic_buf[c], - (size_t)fs * sizeof(int16_t)); - } - } - } else { - for (c = 0; c < cd->channels; c++) { - if (c > 0 && cd->channels > 1) { - memcpy(&cd->out_fifo[c][cd->buffered_out_frames], - &cd->out_fifo[0][cd->buffered_out_frames], - (size_t)fs * sizeof(int16_t)); - continue; - } - - ret = cd->backend->process_ch(mod, - cd->mic_buf[c], - cd->ref_buf[c], - &cd->out_fifo[c][cd->buffered_out_frames], - fs, c); - if (ret) { - memcpy(&cd->out_fifo[c][cd->buffered_out_frames], - cd->mic_buf[c], - (size_t)fs * sizeof(int16_t)); - } - } - } - } + webrtc_aec_run_block(mod, cd, fs); cd->buffered_out_frames += fs; cd->buffered_in_frames -= fs; if (cd->buffered_in_frames > 0) { - for (c = 0; c < cd->channels; c++) { + for (c = 0; c < cd->mic_channels; c++) { memmove(cd->mic_buf[c], cd->mic_buf[c] + fs, (size_t)cd->buffered_in_frames * sizeof(int16_t)); + } + for (c = 0; c < cd->ref_channels; c++) { memmove(cd->ref_buf[c], cd->ref_buf[c] + fs, (size_t)cd->buffered_in_frames * sizeof(int16_t)); } @@ -529,10 +725,10 @@ static int webrtc_aec_process(struct processing_module *mod, /* Drain exactly n frames from out_fifo to sink to maintain symmetric period I/O */ drain = MIN(n, cd->buffered_out_frames); if (drain > 0) { - s16_to_sink(out, cd->out_fifo, drain, cd->channels, cd->is_s32); + s16_to_sink(out, cd->out_fifo, drain, cd->mic_channels, cd->is_s32); cd->buffered_out_frames -= drain; if (cd->buffered_out_frames > 0) { - for (c = 0; c < cd->channels; c++) + for (c = 0; c < cd->mic_channels; c++) memmove(cd->out_fifo[c], cd->out_fifo[c] + drain, (size_t)cd->buffered_out_frames * sizeof(int16_t)); } @@ -550,9 +746,11 @@ static int webrtc_aec_reset(struct processing_module *mod) webrtc_aec_set_active_mod(mod); comp_dbg(mod->dev, "webrtc_aec: reset"); cd->buffered_in_frames = 0; - for (c = 0; c < cd->channels; c++) + cd->ref_mismatch_warned = false; + for (c = 0; c < cd->mic_channels; c++) memset(cd->out_fifo[c], 0, sizeof(int16_t) * cd->frame_samples); cd->buffered_out_frames = cd->frame_samples; + webrtc_aec_reset_resamplers(cd); if (cd->backend->reset) return cd->backend->reset(mod); @@ -568,13 +766,39 @@ __cold static int webrtc_aec_free(struct processing_module *mod) assert_can_be_cold(); comp_dbg(mod->dev, "webrtc_aec: free"); - if (cd->backend->free) + if (cd && cd->backend && cd->backend->free) cd->backend->free(mod); + if (webrtc_aec_get_active_mod() == mod) + webrtc_aec_set_active_mod(NULL); + mod_free(mod, cd); return 0; } +static int webrtc_aec_apply_ctl(struct processing_module *mod, + struct webrtc_aec_comp_data *cd, + uint32_t id, uint32_t value) +{ + struct comp_dev *dev = mod->dev; + + if (id == 0) { + cd->enabled = (value != 0); + comp_info(dev, "webrtc_aec: switch enable = %d", cd->enabled); + return 0; + } + if (id == 1) { + cd->high_suppression = (value != 0); + comp_info(dev, "webrtc_aec: high suppression = %d", cd->high_suppression); + if (cd->backend && cd->backend->set_suppression) + return cd->backend->set_suppression(mod, cd->high_suppression); + return 0; + } + + comp_err(dev, "webrtc_aec: unknown control id %d", id); + return -EINVAL; +} + static int webrtc_aec_set_config(struct processing_module *mod, uint32_t param_id, enum module_cfg_fragment_position pos, uint32_t data_offset_size, const uint8_t *fragment, size_t fragment_size, uint8_t *response, @@ -584,6 +808,7 @@ static int webrtc_aec_set_config(struct processing_module *mod, uint32_t param_i struct comp_dev *dev = mod->dev; webrtc_aec_set_active_mod(mod); +#ifdef CONFIG_IPC_MAJOR_4 if (param_id == SOF_IPC4_SWITCH_CONTROL_PARAM_ID) { const struct sof_ipc4_control_msg_payload *ctl = (const struct sof_ipc4_control_msg_payload *)fragment; @@ -600,22 +825,18 @@ static int webrtc_aec_set_config(struct processing_module *mod, uint32_t param_i return -EINVAL; } - if (ctl->id == 0) { - cd->enabled = (ctl->chanv[0].value != 0); - comp_info(dev, "webrtc_aec: switch enable = %d", cd->enabled); - return 0; - } - if (ctl->id == 1) { - cd->high_suppression = (ctl->chanv[0].value != 0); - comp_info(dev, "webrtc_aec: high suppression = %d", cd->high_suppression); - if (cd->backend && cd->backend->set_suppression) - return cd->backend->set_suppression(mod, cd->high_suppression); - return 0; - } + return webrtc_aec_apply_ctl(mod, cd, ctl->id, ctl->chanv[0].value); + } +#else + 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; - 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); } +#endif comp_err(dev, "webrtc_aec: unsupported param_id 0x%x", param_id); return -EINVAL; @@ -627,22 +848,34 @@ static int webrtc_aec_get_config(struct processing_module *mod, uint32_t config_ { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); +#ifdef CONFIG_IPC_MAJOR_4 if (config_id == SOF_IPC4_SWITCH_CONTROL_PARAM_ID) { struct sof_ipc4_control_msg_payload *ctl = (struct sof_ipc4_control_msg_payload *)fragment; + + if (fragment_size < sizeof(struct sof_ipc4_control_msg_payload) + + sizeof(struct sof_ipc4_ctrl_value_chan)) + return -EINVAL; + ctl->num_elems = 1; ctl->chanv[0].channel = 0; - if (ctl->id == 0) { + if (ctl->id == 0) ctl->chanv[0].value = cd->enabled ? 1 : 0; - } else if (ctl->id == 1) { + else if (ctl->id == 1) ctl->chanv[0].value = cd->high_suppression ? 1 : 0; - } else { + else return -EINVAL; - } *data_offset_size = sizeof(struct sof_ipc4_control_msg_payload) + sizeof(struct sof_ipc4_ctrl_value_chan); return 0; } +#else + (void)cd; + (void)config_id; + (void)data_offset_size; + (void)fragment; + (void)fragment_size; +#endif return -EINVAL; } @@ -654,17 +887,32 @@ static bool webrtc_aec_is_ready_to_process(struct processing_module *mod, int num_of_sinks) { struct webrtc_aec_comp_data *cd = module_get_private_data(mod); - struct sof_source *mic; + struct sof_source *mic, *ref; struct sof_sink *out; + int mic_idx, ref_idx; - if (!cd || !cd->configured || num_of_sources <= cd->mic_src || num_of_sinks < 1) + if (!cd || !cd->configured || num_of_sources < 1 || num_of_sinks < 1) return false; - mic = sources[cd->mic_src]; + webrtc_aec_resolve_sources(sources, num_of_sources, sinks, num_of_sinks, + &mic_idx, &ref_idx); + mic = sources[mic_idx]; + ref = ref_idx >= 0 ? sources[ref_idx] : NULL; out = sinks[0]; - return source_get_data_available(mic) >= source_get_min_available(mic) && - sink_get_free_size(out) >= sink_get_min_free_space(out); + if (source_get_data_available(mic) >= source_get_min_available(mic) && + sink_get_free_size(out) >= sink_get_min_free_space(out)) + return true; + + { + int ref_min; + int surplus = webrtc_aec_ref_surplus(mic, ref, &ref_min); + + if (ref_min > 0 && surplus >= ref_min) + return true; + } + + return false; } static const struct module_interface webrtc_aec_interface = { diff --git a/src/audio/webrtc_aec/webrtc_aec.cmake b/src/audio/webrtc_aec/webrtc_aec.cmake index 13e56d89af22..131a4180c084 100644 --- a/src/audio/webrtc_aec/webrtc_aec.cmake +++ b/src/audio/webrtc_aec/webrtc_aec.cmake @@ -33,6 +33,16 @@ set(WEBRTC_AECM_INSTALL_DIR "${CMAKE_CURRENT_BINARY_DIR}/webrtc-aecm-install" set(_aecm_src "${SOF_WEBRTC_APM_SRC_DIR}/webrtc") +if("${ARCH}" STREQUAL "xtensa") + if(CONFIG_LLEXT_BUILD_PIC) + set(_aecm_arch_cflags "-fPIC -mlongcalls -mtext-section-literals") + else() + set(_aecm_arch_cflags "-fno-pic -fno-pie -mlongcalls -mtext-section-literals") + endif() +else() + set(_aecm_arch_cflags "-fPIC") +endif() + if(CONFIG_WEBRTC_AEC_BACKEND_FLOAT) set(_aec_backend_srcs " $SRC/modules/audio_processing/aec/echo_cancellation.c @@ -58,7 +68,7 @@ OBJ=${CMAKE_CURRENT_BINARY_DIR}/webrtc-aecm-obj rm -rf \"$OBJ\" \"$INST/lib/libwebrtc_aecm.a\" mkdir -p \"$OBJ\" \"$INST/lib\" \"$INST/include\" \"$INST/include/webrtc\" -CFLAGS=\"-O2 -fPIC -DNDEBUG -I${SOF_WEBRTC_APM_SRC_DIR} -I$SRC -I$SRC/common_audio/signal_processing/include -DWEBRTC_ARCH_32_BITS= -DWEBRTC_ARCH_LITTLE_ENDIAN= -Dmalloc=webrtc_malloc -Dcalloc=webrtc_calloc -Drealloc=webrtc_realloc -Dfree=webrtc_free\" +CFLAGS=\"-O2 ${_aecm_arch_cflags} -DNDEBUG -I${SOF_WEBRTC_APM_SRC_DIR} -I$SRC -I$SRC/common_audio/signal_processing/include -DWEBRTC_ARCH_32_BITS= -DWEBRTC_ARCH_LITTLE_ENDIAN= -Dmalloc=webrtc_malloc -Dcalloc=webrtc_calloc -Drealloc=webrtc_realloc -Dfree=webrtc_free\" # AEC backend core SRCS=\"${_aec_backend_srcs} @@ -76,6 +86,7 @@ SRCS=\"${_aec_backend_srcs} $SRC/common_audio/signal_processing/randomization_functions.c $SRC/common_audio/signal_processing/real_fft.c $SRC/common_audio/signal_processing/resample_48khz.c + $SRC/common_audio/signal_processing/resample_by_2.c $SRC/common_audio/signal_processing/resample_by_2_internal.c $SRC/common_audio/signal_processing/resample_fractional.c $SRC/common_audio/signal_processing/spl_init.c @@ -95,8 +106,6 @@ cp ${_aec_backend_hdr} \"$INST/include/\" cp $SRC/typedefs.h \"$INST/include/webrtc/\" 2>/dev/null || true ") -# Only touch the script when its content changes so that the library is -# rebuilt on flag changes but not on every reconfigure. configure_file("${CMAKE_CURRENT_BINARY_DIR}/webrtc-aecm-build.sh.tmp" "${CMAKE_CURRENT_BINARY_DIR}/webrtc-aecm-build.sh" COPYONLY) diff --git a/src/audio/webrtc_aec/webrtc_aec.h b/src/audio/webrtc_aec/webrtc_aec.h index cc79fea7239c..79f4986f31bc 100644 --- a/src/audio/webrtc_aec/webrtc_aec.h +++ b/src/audio/webrtc_aec/webrtc_aec.h @@ -21,25 +21,32 @@ #define __SOF_AUDIO_WEBRTC_AEC_H__ #include -#include #include #include -/* AECm operates on 10 ms frames. +/* WebRTC AEC operates on 10 ms frames. * At 16 kHz: 160 samples/channel. - * At 48 kHz: 480 samples/channel (resampled to/from 16 kHz for AECm). + * At 32 kHz: 320 samples/channel (resampled to/from 16 kHz). + * At 48 kHz: 480 samples/channel (resampled to/from 16 kHz). */ #define WEBRTC_AEC_FRAME_SAMPLES_16K 160 +#define WEBRTC_AEC_FRAME_SAMPLES_32K 320 #define WEBRTC_AEC_FRAME_SAMPLES_48K 480 #define WEBRTC_AEC_FRAME_SAMPLES_MAX WEBRTC_AEC_FRAME_SAMPLES_48K #define WEBRTC_AEC_FIFO_FRAMES (WEBRTC_AEC_FRAME_SAMPLES_MAX * 2) -/* Maximum supported channel count (AECm is mono; multi-ch runs N instances). */ +/* Maximum supported channel count per stream (mic or ref). */ #define WEBRTC_AEC_CHANNELS_MAX 4 /* Maximum DMA buffer alignment. */ #define WEBRTC_AEC_MEM_ALIGN 64 +enum webrtc_aec_resamp_mode { + WEBRTC_AEC_RESAMP_NONE = 0, + WEBRTC_AEC_RESAMP_32_TO_16, + WEBRTC_AEC_RESAMP_48_TO_16, +}; + /* Fixed-point 48kHz <-> 16kHz resampler states (WebRTC APM SPL). */ struct webrtc_aec_state_48_to_16 { int32_t s_48_48[16]; @@ -54,7 +61,7 @@ struct webrtc_aec_state_16_to_48 { }; /** - * struct webrtc_aec_backend - AECm backend operations. + * struct webrtc_aec_backend - AEC backend operations. */ struct webrtc_aec_backend { const char *name; @@ -63,42 +70,55 @@ struct webrtc_aec_backend { int (*init)(struct processing_module *mod); /** - * Open/configure AECm state. Called from prepare(). - * @sample_rate_hz: 8000 or 16000 - * @filter_len_ms: adaptive filter length (32/64/128) - * @suppression: CNG level 0..2 - * @num_channels: mic and ref channel count (same; AECm runs per-ch) + * Open/configure AEC state. Called from prepare(). + * @sample_rate_hz: 8000 or 16000 + * @filter_len_ms: adaptive filter length (32/64/128) + * @suppression: CNG/NLP level 0..2 + * @num_mic_channels: capture microphone channel count (1..MAX) + * @num_ref_channels: playback echo reference channel count (1..MAX) */ int (*configure)(struct processing_module *mod, int sample_rate_hz, - int filter_len_ms, int suppression, int num_channels); + int filter_len_ms, int suppression, + int num_mic_channels, int num_ref_channels); /* Runtime update of suppression / echo mode. */ int (*set_suppression)(struct processing_module *mod, bool high_suppression); + /* Runtime update of nominal echo path delay (ms). */ + int (*set_delay)(struct processing_module *mod, int delay_ms); + + /* Optional metrics readback (ERL, ERLE in dB, estimated delay in ms). */ + int (*get_metrics)(struct processing_module *mod, + int *erl_db, int *erle_db, int *delay_ms); + /** - * Process one 10 ms frame (interleaved S16 mic + ref → interleaved S16 out). + * Process one 10 ms frame (per-channel S16 mic + ref -> S16 out). * All arrays are mono; caller provides per-channel slices. * @mic: mic input S16 samples (frame_samples) * @ref: echo reference S16 samples (frame_samples) * @out: denoised output S16 samples (frame_samples) - * @ch: channel index (for multi-channel instances) + * @ch: mic channel index (for multi-channel instances) */ int (*process_ch)(struct processing_module *mod, const int16_t *mic, const int16_t *ref, int16_t *out, int frame_samples, int ch); /** - * Process complete multi-channel 10 ms frame. + * Process complete multi-channel 10 ms frame (supports asymmetric R x C). * If provided, called instead of per-channel process_ch loop. - * @mic: array of mic channel pointers - * @ref: array of echo reference channel pointers - * @out: array of output channel pointers + * @mic: array of mic channel pointers (num_mic_channels) + * @ref: array of echo reference channel pointers (num_ref_channels) + * @out: array of output channel pointers (num_mic_channels) + * @frame_samples: samples per channel at proc_rate + * @num_mic_channels: number of mic/output channels + * @num_ref_channels: number of echo reference channels */ int (*process_frame)(struct processing_module *mod, const int16_t *const *mic, const int16_t *const *ref, int16_t *const *out, - int frame_samples, int num_channels); + int frame_samples, + int num_mic_channels, int num_ref_channels); /* Reset adaptive filters (keep configuration). Called from reset(). */ int (*reset)(struct processing_module *mod); @@ -109,10 +129,6 @@ struct webrtc_aec_backend { /** * struct webrtc_aec_comp_data - webrtc_aec module private data. - * - * All buffers are S16 because AECm is a fixed-point Q15 algorithm. - * We do S32→S16 downshift on input and S16→S32 upshift on output when - * the pipeline format is S32. */ struct webrtc_aec_comp_data { const struct webrtc_aec_backend *backend; @@ -121,22 +137,26 @@ struct webrtc_aec_comp_data { /* Runtime ALSA mixer controls */ bool enabled; /* master bypass switch (ctl->id == 0) */ bool high_suppression; /* suppression level switch (ctl->id == 1) */ + int delay_ms; /* echo path / soundcard buffer delay (ms) */ + bool downmix_ref; /* downmix multi-ch ref to mono before backend */ - /* Source routing (resolved in prepare). */ + /* Source routing (resolved in prepare / process). */ int mic_src; /* index into sources[] for microphone */ int ref_src; /* index into sources[] for echo reference */ /* Negotiated format. */ int rate; /* pipeline sample rate (Hz) */ - int proc_rate; /* AECm processing rate (8000 or 16000 Hz) */ - int channels; + int proc_rate; /* AEC processing rate (8000 or 16000 Hz) */ + int mic_channels; /* microphone / output channel count */ + int ref_channels; /* playback reference channel count */ + int effective_ref_ch; /* ref channels fed to backend (1 if downmixed) */ int mic_frame_bytes; /* bytes per pipeline frame on mic input */ int ref_frame_bytes; /* bytes per pipeline frame on ref input */ int out_frame_bytes; bool is_s32; /* true for S32_LE pipeline */ - bool needs_resample; /* true when rate == 48000 and proc_rate == 16000 */ + enum webrtc_aec_resamp_mode resamp_mode; - /* Processing frame size at proc_rate. */ + /* Processing frame size at pipeline rate. */ int frame_samples; /* pipeline frames per 10 ms */ /* Accumulation and lookahead FIFO state. */ @@ -147,6 +167,9 @@ struct webrtc_aec_comp_data { int16_t mic_buf[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FIFO_FRAMES]; int16_t ref_buf[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FIFO_FRAMES]; int16_t out_fifo[WEBRTC_AEC_CHANNELS_MAX][WEBRTC_AEC_FIFO_FRAMES]; + 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]; /* Resampler state for 48kHz <-> 16kHz */ struct webrtc_aec_state_48_to_16 mic_resamp[WEBRTC_AEC_CHANNELS_MAX]; @@ -154,11 +177,14 @@ struct webrtc_aec_comp_data { struct webrtc_aec_state_16_to_48 out_resamp[WEBRTC_AEC_CHANNELS_MAX]; int32_t resamp_tmpmem[512]; - /* Ref stream liveness (IPC4: always active). */ - bool last_ref_ok; + /* Resampler state for 32kHz <-> 16kHz (WebRtcSpl_DownsampleBy2/UpsampleBy2) */ + int32_t mic_resamp32[WEBRTC_AEC_CHANNELS_MAX][8]; + int32_t ref_resamp32[WEBRTC_AEC_CHANNELS_MAX][8]; + int32_t out_resamp32[WEBRTC_AEC_CHANNELS_MAX][8]; - /* IPC4 tuning (echo path delay, etc.) — reserved for set_config. */ - struct sof_ipc4_aec_config config; + /* Ref stream liveness. */ + bool last_ref_ok; + bool ref_mismatch_warned; bool configured; }; diff --git a/src/audio/webrtc_aec/webrtc_aec3_wrapper.cpp b/src/audio/webrtc_aec/webrtc_aec3_wrapper.cpp index c79d16ec7b6c..71e05c2cf85b 100644 --- a/src/audio/webrtc_aec/webrtc_aec3_wrapper.cpp +++ b/src/audio/webrtc_aec/webrtc_aec3_wrapper.cpp @@ -6,74 +6,138 @@ #include "webrtc_aec3_wrapper.h" #include "modules/audio_processing/aec3/echo_canceller3.h" #include "modules/audio_processing/aec3_buffer/audio_buffer.h" +#include +#include #include #include +#include struct webrtc_aec3_inst { std::unique_ptr aec3; std::unique_ptr render_buf; std::unique_ptr capture_buf; - int sample_rate_hz; - int num_render_channels; - int num_capture_channels; + webrtc_aec3_cfg cfg; + std::atomic pending_delay_ms{-1}; + std::atomic high_suppression{false}; }; -extern "C" { +static webrtc::EchoCanceller3Config build_aec3_config(const webrtc_aec3_cfg& cfg, bool multichannel) { + webrtc::EchoCanceller3Config config = multichannel + ? webrtc::EchoCanceller3::CreateDefaultMultichannelConfig() + : webrtc::EchoCanceller3Config(); -webrtc_aec3_inst_t* webrtc_aec3_create(int sample_rate_hz, int num_render_channels, int num_capture_channels) { - auto inst = std::make_unique(); - inst->sample_rate_hz = sample_rate_hz; - inst->num_render_channels = num_render_channels; - inst->num_capture_channels = num_capture_channels; - - webrtc::EchoCanceller3Config config; - config.delay.use_external_delay_estimator = true; + config.delay.use_external_delay_estimator = cfg.use_external_delay_estimator; config.delay.default_delay = 5; + config.delay.delay_headroom_samples = cfg.use_external_delay_estimator ? 0 : 32; - config.delay.delay_headroom_samples = 0; + size_t blocks = (size_t)std::max(1, std::min(cfg.filter_length_blocks, 30)); + size_t init_blocks = std::min(blocks, (size_t)12); + config.filter.refined.length_blocks = blocks; + config.filter.refined_initial.length_blocks = init_blocks; + config.filter.coarse.length_blocks = blocks; + config.filter.coarse_initial.length_blocks = init_blocks; + config.filter.enable_coarse_filter_output_usage = cfg.enable_coarse_filter; - // Reduce filter partition count for real-time DSP performance (1 block = 4ms tail) - config.filter.refined.length_blocks = 1; - config.filter.refined_initial.length_blocks = 1; - config.filter.coarse.length_blocks = 1; - config.filter.coarse_initial.length_blocks = 1; + config.erle.num_sections = 1; + config.echo_model.model_reverb_in_nonlinear_mode = false; + config.multi_channel.detect_stereo_content = cfg.detect_stereo_content; + + if (cfg.high_suppression) { + config.suppressor.normal_tuning.mask_lf.enr_transparent = 0.15f; + config.suppressor.normal_tuning.mask_lf.enr_suppress = 0.25f; + config.suppressor.normal_tuning.mask_hf.enr_transparent = 0.04f; + config.suppressor.normal_tuning.mask_hf.enr_suppress = 0.07f; + config.suppressor.normal_tuning.max_dec_factor_lf = 0.15f; + config.suppressor.nearend_tuning.mask_lf.enr_transparent = 0.7f; + config.suppressor.nearend_tuning.mask_lf.enr_suppress = 0.9f; + config.suppressor.conservative_hf_suppression = true; + } - // Disable coarse filter to save 50% subtractor FFT/filter cycles - config.filter.enable_coarse_filter_output_usage = false; + webrtc::EchoCanceller3Config::Validate(&config); + return config; +} - // Disable heavy sub-band ERLE estimator by setting num_sections = 1 - config.erle.num_sections = 1; +static void create_aec3_buffers(webrtc_aec3_inst* inst) { + inst->render_buf = std::make_unique( + inst->cfg.sample_rate_hz, inst->cfg.num_render_channels, + inst->cfg.sample_rate_hz, inst->cfg.num_render_channels, + inst->cfg.sample_rate_hz, inst->cfg.num_render_channels); + inst->capture_buf = std::make_unique( + inst->cfg.sample_rate_hz, inst->cfg.num_capture_channels, + inst->cfg.sample_rate_hz, inst->cfg.num_capture_channels, + inst->cfg.sample_rate_hz, inst->cfg.num_capture_channels); +} - // Disable reverb modeling in nonlinear mode to reduce cycle count - config.echo_model.model_reverb_in_nonlinear_mode = false; +static void create_aec3_engine(webrtc_aec3_inst* inst) { + inst->cfg.high_suppression = inst->high_suppression.load(std::memory_order_acquire); + webrtc::EchoCanceller3Config config = build_aec3_config(inst->cfg, false); + std::optional mc_config; + if (inst->cfg.num_render_channels > 1) { + mc_config = build_aec3_config(inst->cfg, true); + } - // Multi-channel downmixing: downmix stereo render reference to mono for linear subtractor - config.multi_channel.detect_stereo_content = false; + int delay_ms = inst->pending_delay_ms.exchange(-1, std::memory_order_acq_rel); + if (delay_ms >= 0) { + inst->cfg.delay_ms = delay_ms; + } - webrtc::EchoCanceller3Config::Validate(&config); inst->aec3 = std::make_unique( - config, std::nullopt, sample_rate_hz, num_render_channels, num_capture_channels); - inst->aec3->SetAudioBufferDelay(40); + config, mc_config, inst->cfg.sample_rate_hz, + inst->cfg.num_render_channels, inst->cfg.num_capture_channels); + inst->aec3->SetAudioBufferDelay(inst->cfg.delay_ms); inst->aec3->SetCaptureOutputUsage(true); +} - inst->render_buf = std::make_unique( - sample_rate_hz, num_render_channels, sample_rate_hz, num_render_channels, sample_rate_hz, num_render_channels); - inst->capture_buf = std::make_unique( - sample_rate_hz, num_capture_channels, sample_rate_hz, num_capture_channels, sample_rate_hz, num_capture_channels); +extern "C" { + +webrtc_aec3_inst_t* webrtc_aec3_create_cfg(const struct webrtc_aec3_cfg* cfg) { + if (!cfg || (cfg->sample_rate_hz != 8000 && cfg->sample_rate_hz != 16000)) return nullptr; + auto inst = std::make_unique(); + inst->cfg = *cfg; + inst->high_suppression.store(cfg->high_suppression, std::memory_order_relaxed); + inst->pending_delay_ms.store(-1, std::memory_order_relaxed); + + create_aec3_engine(inst.get()); + create_aec3_buffers(inst.get()); return inst.release(); } +webrtc_aec3_inst_t* webrtc_aec3_create(int sample_rate_hz, int num_render_channels, int num_capture_channels) { + webrtc_aec3_cfg cfg = {}; + cfg.sample_rate_hz = sample_rate_hz; + cfg.num_render_channels = num_render_channels; + cfg.num_capture_channels = num_capture_channels; + cfg.delay_ms = 20; + cfg.filter_length_blocks = 12; + cfg.use_external_delay_estimator = false; + cfg.enable_coarse_filter = true; + cfg.detect_stereo_content = true; + cfg.high_suppression = false; + return webrtc_aec3_create_cfg(&cfg); +} + int webrtc_aec3_init(webrtc_aec3_inst_t* inst, int sample_rate_hz) { if (!inst || !inst->aec3) return -1; - inst->aec3->SetAudioBufferDelay(40); + if (sample_rate_hz != 8000 && sample_rate_hz != 16000) return -1; + if (inst->cfg.sample_rate_hz != sample_rate_hz) { + inst->cfg.sample_rate_hz = sample_rate_hz; + create_aec3_buffers(inst); + } + create_aec3_engine(inst); return 0; } int webrtc_aec3_buffer_farend(webrtc_aec3_inst_t* inst, const float* const* ref, size_t num_render_channels, size_t num_samples) { - if (!inst || !inst->aec3 || !ref) return -1; - if (num_samples != 160) return -1; - if (num_render_channels != (size_t)inst->num_render_channels) return -1; + if (!inst || !inst->aec3 || !inst->render_buf || !ref) return -1; + if (num_samples != (size_t)(inst->cfg.sample_rate_hz / 100)) return -1; + if (num_render_channels != (size_t)inst->cfg.num_render_channels) return -1; + + int pending_delay = inst->pending_delay_ms.exchange(-1, std::memory_order_acq_rel); + if (pending_delay >= 0) { + inst->cfg.delay_ms = pending_delay; + inst->aec3->SetAudioBufferDelay(pending_delay); + } for (size_t ch = 0; ch < num_render_channels; ++ch) { float* dst = inst->render_buf->split_bands(ch)[0]; @@ -86,9 +150,9 @@ int webrtc_aec3_buffer_farend(webrtc_aec3_inst_t* inst, const float* const* ref, int webrtc_aec3_process(webrtc_aec3_inst_t* inst, const float* const* mic, size_t num_capture_channels, float* const* out, size_t num_samples) { - if (!inst || !inst->aec3 || !mic || !out) return -1; - if (num_samples != 160) return -1; - if (num_capture_channels != (size_t)inst->num_capture_channels) return -1; + if (!inst || !inst->aec3 || !inst->capture_buf || !mic || !out) return -1; + if (num_samples != (size_t)(inst->cfg.sample_rate_hz / 100)) return -1; + if (num_capture_channels != (size_t)inst->cfg.num_capture_channels) return -1; for (size_t ch = 0; ch < num_capture_channels; ++ch) { float* dst = inst->capture_buf->split_bands(ch)[0]; @@ -105,8 +169,24 @@ int webrtc_aec3_process(webrtc_aec3_inst_t* inst, const float* const* mic, size_ } int webrtc_aec3_set_suppression(webrtc_aec3_inst_t* inst, bool high_suppression) { - (void)inst; - (void)high_suppression; + if (!inst) return -1; + /* Defer EchoCanceller3 reconstruction to prepare()/reset() to avoid RT allocation. */ + inst->high_suppression.store(high_suppression, std::memory_order_release); + return 0; +} + +int webrtc_aec3_set_delay(webrtc_aec3_inst_t* inst, int delay_ms) { + if (!inst || delay_ms < 0) return -1; + inst->pending_delay_ms.store(delay_ms, std::memory_order_release); + return 0; +} + +int webrtc_aec3_get_metrics(webrtc_aec3_inst_t* inst, int* erl_db, int* erle_db, int* delay_ms) { + if (!inst || !inst->aec3) return -1; + webrtc::EchoControl::Metrics m = inst->aec3->GetMetrics(); + if (erl_db) *erl_db = (int)m.echo_return_loss; + if (erle_db) *erle_db = (int)m.echo_return_loss_enhancement; + if (delay_ms) *delay_ms = m.delay_ms; return 0; } diff --git a/src/audio/webrtc_aec/webrtc_aec3_wrapper.h b/src/audio/webrtc_aec/webrtc_aec3_wrapper.h index 4e9b91447de2..11c34844f025 100644 --- a/src/audio/webrtc_aec/webrtc_aec3_wrapper.h +++ b/src/audio/webrtc_aec/webrtc_aec3_wrapper.h @@ -16,12 +16,27 @@ extern "C" { typedef struct webrtc_aec3_inst webrtc_aec3_inst_t; +struct webrtc_aec3_cfg { + int sample_rate_hz; + int num_render_channels; + int num_capture_channels; + int delay_ms; + int filter_length_blocks; + bool use_external_delay_estimator; + bool enable_coarse_filter; + bool detect_stereo_content; + bool high_suppression; +}; + +webrtc_aec3_inst_t* webrtc_aec3_create_cfg(const struct webrtc_aec3_cfg* cfg); webrtc_aec3_inst_t* webrtc_aec3_create(int sample_rate_hz, int num_render_channels, int num_capture_channels); int webrtc_aec3_init(webrtc_aec3_inst_t* inst, int sample_rate_hz); int webrtc_aec3_buffer_farend(webrtc_aec3_inst_t* inst, const float* const* ref, size_t num_render_channels, size_t num_samples); int webrtc_aec3_process(webrtc_aec3_inst_t* inst, const float* const* mic, size_t num_capture_channels, float* const* out, size_t num_samples); int webrtc_aec3_set_suppression(webrtc_aec3_inst_t* inst, bool high_suppression); +int webrtc_aec3_set_delay(webrtc_aec3_inst_t* inst, int delay_ms); +int webrtc_aec3_get_metrics(webrtc_aec3_inst_t* inst, int* erl_db, int* erle_db, int* delay_ms); void webrtc_aec3_free(webrtc_aec3_inst_t* inst); #ifdef __cplusplus diff --git a/test/ztest/unit/audio/webrtc_aec/CMakeLists.txt b/test/ztest/unit/audio/webrtc_aec/CMakeLists.txt new file mode 100644 index 000000000000..3462df3ec3c3 --- /dev/null +++ b/test/ztest/unit/audio/webrtc_aec/CMakeLists.txt @@ -0,0 +1,116 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(sof_unit_audio_webrtc_aec) + +set(SOF_ROOT "${PROJECT_SOURCE_DIR}/../../../../../") +set(sof_top_dir ${SOF_ROOT}) + +if(NOT DEFINED SOF_WEBRTC_APM_SRC_DIR) + set(SOF_WEBRTC_APM_SRC_DIR "${SOF_ROOT}/../modules/audio/webrtc-apm") +endif() +cmake_path(NORMAL_PATH SOF_WEBRTC_APM_SRC_DIR) + +include(${SOF_ROOT}/scripts/cmake/misc.cmake) +include(${SOF_ROOT}/scripts/cmake/uuid-registry.cmake) + +target_include_directories(app PRIVATE + ${SOF_ROOT}/zephyr/include + ${SOF_ROOT}/src/include + ${SOF_ROOT}/src/kernel/include + ${SOF_ROOT}/src/kernel/platform/posix/include + ${SOF_ROOT}/src/platform/posix/include + ${SOF_ROOT}/src/audio + ${SOF_ROOT}/src/audio/webrtc_aec + ${SOF_ROOT}/test/cmocka/include + ${PROJECT_BINARY_DIR}/include/generated + ${SOF_WEBRTC_APM_SRC_DIR} + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aec/include + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aecm/include + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/include +) + +target_compile_definitions(app PRIVATE + -DCONFIG_ZEPHYR_POSIX=1 + -DCONFIG_LIBRARY=1 + -DUNIT_TEST=1 + -DNDEBUG=1 +) + +set(_webrtc_apm_c_srcs + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aec/echo_cancellation.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aec/aec_core.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aec/aec_rdft.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/aec/aec_resampler.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/ring_buffer.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/utility/delay_estimator.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/modules/audio_processing/utility/delay_estimator_wrapper.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/complex_bit_reverse.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/complex_fft.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/cross_correlation.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/downsample_fast.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/real_fft.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/sqrt_of_one_minus_x_squared.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/vector_scaling_operations.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/min_max_operations.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/spl_sqrt_floor.c + ${SOF_WEBRTC_APM_SRC_DIR}/webrtc/common_audio/signal_processing/randomization_functions.c + ${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/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 +) + +set(_webrtc_aec_c_srcs + ${SOF_ROOT}/src/audio/webrtc_aec/webrtc_aec-aec.c + ${_webrtc_apm_c_srcs} +) + +set_source_files_properties(${_webrtc_aec_c_srcs} PROPERTIES + COMPILE_DEFINITIONS "malloc=webrtc_malloc;calloc=webrtc_calloc;realloc=webrtc_realloc;free=webrtc_free" + COMPILE_OPTIONS "-Wno-error=deprecated-declarations;-Wno-double-promotion;-Wno-unused-function" +) + +target_sources(app PRIVATE + webrtc_aec_ztest.c + webrtc_aec_test_alloc.c + ${SOF_ROOT}/src/audio/webrtc_aec/webrtc_aec.c + ${SOF_ROOT}/src/audio/webrtc_aec/webrtc_aec-aec.c + ${SOF_ROOT}/src/audio/webrtc_aec/webrtc_aec-math.c + ${SOF_ROOT}/src/audio/webrtc_aec/webrtc_aec-shims.c + ${_webrtc_apm_c_srcs} + ${SOF_ROOT}/src/audio/module_adapter/module_adapter.c + ${SOF_ROOT}/src/audio/module_adapter/module_adapter_ipc3.c + ${SOF_ROOT}/src/audio/module_adapter/module/generic.c + ${SOF_ROOT}/src/audio/buffers/comp_buffer.c + ${SOF_ROOT}/src/audio/buffers/audio_buffer.c + ${SOF_ROOT}/src/audio/source_api_helper.c + ${SOF_ROOT}/src/audio/sink_api_helper.c + ${SOF_ROOT}/src/audio/sink_source_utils.c + ${SOF_ROOT}/src/math/numbers.c + ${SOF_ROOT}/src/audio/audio_stream.c + ${SOF_ROOT}/src/audio/component.c + ${SOF_ROOT}/src/audio/data_blob.c + ${SOF_ROOT}/src/module/audio/source_api.c + ${SOF_ROOT}/src/module/audio/sink_api.c + ${SOF_ROOT}/src/kernel/ipc/ipc3/helper.c + ${SOF_ROOT}/src/ipc/ipc-common.c + ${SOF_ROOT}/src/kernel/ipc/ipc-common-kernel.c + ${SOF_ROOT}/src/ipc/ipc-helper.c + ${SOF_ROOT}/src/lib/objpool.c + ${SOF_ROOT}/src/audio/pipeline/pipeline-graph.c + ${SOF_ROOT}/src/audio/pipeline/pipeline-params.c + ${SOF_ROOT}/src/audio/pipeline/pipeline-schedule.c + ${SOF_ROOT}/src/audio/pipeline/pipeline-stream.c + ${SOF_ROOT}/src/audio/pipeline/pipeline-xrun.c +) + +sof_append_relative_path_definitions(app) diff --git a/test/ztest/unit/audio/webrtc_aec/prj.conf b/test/ztest/unit/audio/webrtc_aec/prj.conf new file mode 100644 index 000000000000..e0b957cac290 --- /dev/null +++ b/test/ztest/unit/audio/webrtc_aec/prj.conf @@ -0,0 +1,14 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +CONFIG_ZTEST=y +CONFIG_SOF_FULL_ZEPHYR_APPLICATION=n +CONFIG_LOG=y +CONFIG_COMP_WEBRTC_AEC=y +CONFIG_COMP_WEBRTC_AEC_STUB=n +CONFIG_WEBRTC_AEC_BACKEND_FLOAT=y +CONFIG_WEBRTC_AEC_DELAY_AGNOSTIC=n +CONFIG_WEBRTC_AEC_DELAY_MS=20 +CONFIG_FORMAT_S16LE=y +CONFIG_FORMAT_S32LE=y diff --git a/test/ztest/unit/audio/webrtc_aec/testcase.yaml b/test/ztest/unit/audio/webrtc_aec/testcase.yaml new file mode 100644 index 000000000000..fe9e01066153 --- /dev/null +++ b/test/ztest/unit/audio/webrtc_aec/testcase.yaml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: BSD-3-Clause +# +# Copyright(c) 2026 Intel Corporation. + +common: + tags: + - SOF + - unit_test + - audio + - webrtc_aec + integration_platforms: + - native_sim + arch_exclude: xtensa + +tests: + sof.unit.audio.webrtc_aec: + platform_allow: + - native_sim diff --git a/test/ztest/unit/audio/webrtc_aec/webrtc_aec_test_alloc.c b/test/ztest/unit/audio/webrtc_aec/webrtc_aec_test_alloc.c new file mode 100644 index 000000000000..e9fff53a2279 --- /dev/null +++ b/test/ztest/unit/audio/webrtc_aec/webrtc_aec_test_alloc.c @@ -0,0 +1,96 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. + +#include +#include +#include + +#include +#include +#include +#undef malloc +#undef calloc +#undef realloc +#undef free +#include + +static struct sof sof_context; +static bool sof_context_initialized; + +struct sof *sof_get(void) +{ + if (!sof_context_initialized) { + sys_comp_init(&sof_context); + sof_context_initialized = true; + } + + return &sof_context; +} + +void *rmalloc_align(uint32_t flags, size_t bytes, uint32_t alignment) +{ + (void)flags; + (void)alignment; + return malloc(bytes); +} + +void *rmalloc(uint32_t flags, size_t bytes) +{ + (void)flags; + return malloc(bytes); +} + +void *rzalloc(uint32_t flags, size_t bytes) +{ + (void)flags; + return calloc(bytes, 1); +} + +void *rballoc_align(uint32_t flags, size_t bytes, uint32_t alignment) +{ + (void)flags; + (void)alignment; + return malloc(bytes); +} + +void rfree(void *ptr) +{ + free(ptr); +} + +void *sof_heap_alloc(struct k_heap *heap, uint32_t flags, size_t bytes, + size_t alignment) +{ + (void)heap; + (void)flags; + (void)alignment; + return malloc(bytes); +} + +void sof_heap_free(struct k_heap *heap, void *addr) +{ + (void)heap; + free(addr); +} + +struct k_heap *sof_sys_user_heap_get(void) +{ + return NULL; +} + +static int stub_cpu_info(int feature) +{ + (void)feature; + return 0; +} + +int (*WebRtc_GetCPUInfo)(int feature) = stub_cpu_info; + +void WebRtcAec_InitAec_SSE2(void) +{ +} + +void aec_rdft_init_sse2(void) +{ +} diff --git a/test/ztest/unit/audio/webrtc_aec/webrtc_aec_ztest.c b/test/ztest/unit/audio/webrtc_aec/webrtc_aec_ztest.c new file mode 100644 index 000000000000..15192853d904 --- /dev/null +++ b/test/ztest/unit/audio/webrtc_aec/webrtc_aec_ztest.c @@ -0,0 +1,478 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2026 Intel Corporation. + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "webrtc_aec.h" + +extern void sys_comp_module_webrtc_aec_interface_init(void); + +struct aec_test_ctx { + struct comp_dev *dev; + struct comp_buffer *mic_buf; + struct comp_buffer *ref_buf; + struct comp_buffer *out_buf; + int rate; + int mic_ch; + int ref_ch; + uint32_t fmt; +}; + +static struct comp_buffer *create_buf(struct comp_dev *dev, uint32_t pipeline_id, + uint32_t fmt, uint16_t ch, uint32_t rate, + uint32_t size_bytes, bool is_source) +{ + struct sof_ipc_buffer desc = { + .comp = { .pipeline_id = pipeline_id }, + .size = size_bytes, + }; + struct comp_buffer *buf = buffer_new(NULL, &desc, BUFFER_USAGE_NOT_SHARED); + + if (!buf) + return NULL; + + memset(buf->stream.addr, 0, size_bytes); + if (is_source) { + buf->source = calloc(1, sizeof(*buf->source)); + if (!buf->source) { + buffer_free(buf); + return NULL; + } + if (dev) + list_item_append(&buf->sink_list, &dev->bsource_list); + buf->source->state = COMP_STATE_PREPARE; + } else { + buf->sink = calloc(1, sizeof(*buf->sink)); + if (!buf->sink) { + buffer_free(buf); + return NULL; + } + if (dev) + list_item_append(&buf->source_list, &dev->bsink_list); + buf->sink->state = COMP_STATE_PREPARE; + } + + audio_stream_set_frm_fmt(&buf->stream, fmt); + audio_stream_set_channels(&buf->stream, ch); + audio_stream_set_rate(&buf->stream, rate); + return buf; +} + +static void destroy_ctx(struct aec_test_ctx *ctx) +{ + if (!ctx) + return; + if (ctx->mic_buf) + list_item_del(&ctx->mic_buf->sink_list); + if (ctx->ref_buf) + list_item_del(&ctx->ref_buf->sink_list); + if (ctx->out_buf) + list_item_del(&ctx->out_buf->source_list); + if (ctx->dev) + comp_free(ctx->dev); + 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); + } + free(ctx); +} + +static struct sof_ipc_comp_process *create_aec_ipc(void) +{ + struct sof_ipc_comp_process *ipc; + const struct sof_uuid uuid = SOF_REG_UUID(webrtc_aec); + + ipc = calloc(1, sizeof(*ipc) + SOF_UUID_SIZE); + if (!ipc) + return NULL; + + memcpy(ipc + 1, &uuid, SOF_UUID_SIZE); + ipc->comp.hdr.size = sizeof(*ipc) + SOF_UUID_SIZE; + ipc->comp.type = SOF_COMP_MODULE_ADAPTER; + ipc->config.hdr.size = sizeof(struct sof_ipc_comp_config); + ipc->comp.ext_data_length = SOF_UUID_SIZE; + return ipc; +} + +static int set_switch_ctl(struct processing_module *mod, uint32_t id, uint32_t val) +{ + const struct module_interface *ops = mod->dev->drv->adapter_ops; + struct { + struct sof_ipc_ctrl_data cdata; + struct sof_ipc_ctrl_value_chan chan; + } msg = { + .cdata = { + .cmd = SOF_CTRL_CMD_SWITCH, + .index = id, + .num_elems = 1, + }, + .chan = { .channel = 0, .value = val }, + }; + + return ops->set_configuration(mod, 0, MODULE_CFG_FRAGMENT_SINGLE, 0, + (const uint8_t *)&msg, sizeof(msg), NULL, 0); +} + +static struct aec_test_ctx *setup_aec_ctx(int rate, int mic_ch, int ref_ch, + uint32_t fmt, bool enable) +{ + struct aec_test_ctx *ctx = calloc(1, sizeof(*ctx)); + struct sof_ipc_comp_process *ipc; + struct processing_module *mod; + struct sof_source *sources[2]; + struct sof_sink *sinks[1]; + uint32_t samp_sz = (fmt == SOF_IPC_FRAME_S32_LE) ? 4 : 2; + uint32_t block_frames = (uint32_t)(rate / 100); + uint32_t mic_sz = block_frames * (uint32_t)mic_ch * samp_sz * 4; + uint32_t ref_sz = block_frames * (uint32_t)ref_ch * samp_sz * 4; + int ret; + + zassert_not_null(ctx); + ctx->rate = rate; + ctx->mic_ch = mic_ch; + ctx->ref_ch = ref_ch; + ctx->fmt = fmt; + + ipc = create_aec_ipc(); + zassert_not_null(ipc); + ctx->dev = comp_new((struct sof_ipc_comp *)ipc); + free(ipc); + zassert_not_null(ctx->dev); + + ctx->dev->frames = block_frames; + mod = comp_mod(ctx->dev); + + ctx->mic_buf = create_buf(ctx->dev, 0, fmt, mic_ch, rate, mic_sz, true); + ctx->ref_buf = create_buf(ctx->dev, 1, fmt, ref_ch, rate, ref_sz, true); + ctx->out_buf = create_buf(ctx->dev, 0, fmt, mic_ch, rate, mic_sz, false); + zassert_not_null(ctx->mic_buf); + zassert_not_null(ctx->ref_buf); + zassert_not_null(ctx->out_buf); + + zassert_equal(set_switch_ctl(mod, 0, enable ? 1 : 0), 0); + zassert_equal(set_switch_ctl(mod, 1, 1), 0); + + sources[0] = audio_buffer_get_source(&ctx->mic_buf->audio_buffer); + sources[1] = audio_buffer_get_source(&ctx->ref_buf->audio_buffer); + sinks[0] = audio_buffer_get_sink(&ctx->out_buf->audio_buffer); + + ret = module_prepare(mod, sources, 2, sinks, 1); + zassert_equal(ret, 0, "module_prepare failed: %d", ret); + + { + const struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + + if (cd && cd->backend && cd->backend->set_delay) + zassert_equal(cd->backend->set_delay(mod, 15), 0); + } + return ctx; +} + +static void push_block_s16(struct comp_buffer *buf, const int16_t *samples, int frames, int ch) +{ + uint32_t bytes = (uint32_t)(frames * ch * (int)sizeof(int16_t)); + int16_t *wptr = audio_stream_get_wptr(&buf->stream); + + for (int i = 0; i < frames * ch; i++) { + *wptr = samples[i]; + wptr = audio_stream_wrap(&buf->stream, wptr + 1); + } + audio_stream_produce(&buf->stream, bytes); +} + +static void pop_block_s16(struct comp_buffer *buf, int16_t *samples, int frames, int ch) +{ + uint32_t bytes = (uint32_t)(frames * ch * (int)sizeof(int16_t)); + int16_t *rptr = audio_stream_get_rptr(&buf->stream); + + for (int i = 0; i < frames * ch; i++) { + samples[i] = *rptr; + rptr = audio_stream_wrap(&buf->stream, rptr + 1); + } + audio_stream_consume(&buf->stream, bytes); +} + +static void run_one_block(struct aec_test_ctx *ctx) +{ + struct processing_module *mod = comp_mod(ctx->dev); + const struct module_interface *ops = mod->dev->drv->adapter_ops; + struct sof_source *sources[2] = { + audio_buffer_get_source(&ctx->mic_buf->audio_buffer), + audio_buffer_get_source(&ctx->ref_buf->audio_buffer), + }; + struct sof_sink *sinks[1] = { + audio_buffer_get_sink(&ctx->out_buf->audio_buffer), + }; + + zassert_equal(ops->process(mod, sources, 2, sinks, 1), 0); +} + +ZTEST(webrtc_aec_suite, test_stereo_2x2_independence_and_erle) +{ + const int rate = 16000; + const int fs = 160; + const int nblocks = 500; /* 5.0 s */ + struct aec_test_ctx *ctx = setup_aec_ctx(rate, 2, 2, SOF_IPC_FRAME_S16_LE, true); + int16_t ref_blk[160 * 2], mic_blk[160 * 2], out_blk[160 * 2]; + int16_t ref_hist[160 * 2 * 6]; + int hist_idx = 0; + const int delay_samp = 320; /* 20 ms echo delay */ + uint32_t rng0 = 0x12345678u, rng1 = 0x9abcdef1u; + double echo_in_e = 0.0, echo_out_e = 0.0; + double ch_diff_e = 0.0; + + memset(ref_hist, 0, sizeof(ref_hist)); + + for (int b = 0; b < nblocks; b++) { + /* Envelope-modulated broadband speech proxy so AEC delay/ERLE converge */ + double env = ((b % 20) < 16) ? 1.0 : 0.25; + + for (int i = 0; i < fs; i++) { + int t = b * fs + i; + rng0 = rng0 * 1664525u + 1013904223u; + rng1 = rng1 * 1664525u + 1013904223u; + double n0 = ((int32_t)(rng0 >> 16) - 32768) * (14000.0 / 32768.0); + double n1 = ((int32_t)(rng1 >> 16) - 32768) * (14000.0 / 32768.0); + double r0 = env * (n0 + 4000.0 * sin(2.0 * 3.14159265 * 430.0 * t / rate)); + double r1 = env * (n1 + 4000.0 * sin(2.0 * 3.14159265 * 610.0 * t / rate)); + ref_blk[2 * i + 0] = (int16_t)r0; + ref_blk[2 * i + 1] = (int16_t)r1; + + int cur = (hist_idx + i) % (160 * 6); + int del = (cur - delay_samp + 160 * 6) % (160 * 6); + ref_hist[2 * cur + 0] = ref_blk[2 * i + 0]; + ref_hist[2 * cur + 1] = ref_blk[2 * i + 1]; + + double echo0 = 0.5 * ref_hist[2 * del + 0]; + double echo1 = 0.5 * ref_hist[2 * del + 1]; + + /* Last 40 blocks: add distinct near-end tones per mic channel */ + double near0 = (b >= 460) ? 5000.0 * sin(2.0 * 3.14159265 * 997.0 * t / rate) : 0.0; + double near1 = (b >= 460) ? 5000.0 * sin(2.0 * 3.14159265 * 1597.0 * t / rate) : 0.0; + + mic_blk[2 * i + 0] = (int16_t)(echo0 + near0); + mic_blk[2 * i + 1] = (int16_t)(echo1 + near1); + } + hist_idx = (hist_idx + fs) % (160 * 6); + + push_block_s16(ctx->ref_buf, ref_blk, fs, 2); + push_block_s16(ctx->mic_buf, mic_blk, fs, 2); + run_one_block(ctx); + pop_block_s16(ctx->out_buf, out_blk, fs, 2); + + /* Single-talk converged window: blocks 400..459 */ + if (b >= 400 && b < 460) { + for (int i = 0; i < fs; i++) { + echo_in_e += (double)mic_blk[2 * i + 0] * mic_blk[2 * i + 0] + + (double)mic_blk[2 * i + 1] * mic_blk[2 * i + 1]; + echo_out_e += (double)out_blk[2 * i + 0] * out_blk[2 * i + 0] + + (double)out_blk[2 * i + 1] * out_blk[2 * i + 1]; + } + } + /* Double-talk channel independence window: blocks 465..499 */ + if (b >= 465) { + for (int i = 0; i < fs; i++) { + double d = (double)out_blk[2 * i + 0] - (double)out_blk[2 * i + 1]; + ch_diff_e += d * d; + } + } + } + + int erle_cb = (int)(100.0 * 10.0 * log10((echo_in_e + 1.0) / (echo_out_e + 1.0))); + + TC_PRINT("webrtc_aec stereo 2x2 ERLE = %d.%02d dB, ch_diff_e = %llu\n", + erle_cb / 100, abs(erle_cb % 100), (unsigned long long)ch_diff_e); + zassert_true(erle_cb > 800, "Expected stereo ERLE > 8.00 dB, got %d.%02d dB", + erle_cb / 100, abs(erle_cb % 100)); + zassert_true(ch_diff_e > 1e7, "Stereo ch1 cloned from ch0"); + destroy_ctx(ctx); +} + +ZTEST(webrtc_aec_suite, test_asymmetric_2r1c_and_2r4c_32k) +{ + /* Case 1: 2R x 1C @ 16 kHz */ + struct aec_test_ctx *c1 = setup_aec_ctx(16000, 1, 2, SOF_IPC_FRAME_S16_LE, true); + int16_t ref1[160 * 2], mic1[160], out1[160]; + + for (int b = 0; b < 40; b++) { + for (int i = 0; i < 160; i++) { + int t = b * 160 + i; + ref1[2 * i + 0] = (int16_t)(6000.0 * sin(2.0 * 3.14159265 * 500.0 * t / 16000)); + ref1[2 * i + 1] = (int16_t)(6000.0 * sin(2.0 * 3.14159265 * 800.0 * t / 16000)); + mic1[i] = (int16_t)((ref1[2 * i + 0] + ref1[2 * i + 1]) / 4); + } + push_block_s16(c1->ref_buf, ref1, 160, 2); + push_block_s16(c1->mic_buf, mic1, 160, 1); + run_one_block(c1); + pop_block_s16(c1->out_buf, out1, 160, 1); + } + destroy_ctx(c1); + + /* Case 2: 2R x 4C @ 32 kHz (validates 32kHz resampler + 4ch independence) */ + struct aec_test_ctx *c2 = setup_aec_ctx(32000, 4, 2, SOF_IPC_FRAME_S16_LE, true); + int16_t ref2[320 * 2], mic2[320 * 4], out2[320 * 4]; + double diff01 = 0.0, diff23 = 0.0; + + for (int b = 0; b < 30; b++) { + for (int i = 0; i < 320; i++) { + int t = b * 320 + i; + ref2[2 * i + 0] = (int16_t)(4000.0 * sin(2.0 * 3.14159265 * 450.0 * t / 32000)); + ref2[2 * i + 1] = (int16_t)(4000.0 * sin(2.0 * 3.14159265 * 750.0 * t / 32000)); + mic2[4 * i + 0] = (int16_t)(5000.0 * sin(2.0 * 3.14159265 * 997.0 * t / 32000)); + mic2[4 * i + 1] = (int16_t)(5000.0 * sin(2.0 * 3.14159265 * 1301.0 * t / 32000)); + mic2[4 * i + 2] = (int16_t)(5000.0 * sin(2.0 * 3.14159265 * 1597.0 * t / 32000)); + mic2[4 * i + 3] = (int16_t)(5000.0 * sin(2.0 * 3.14159265 * 1889.0 * t / 32000)); + } + push_block_s16(c2->ref_buf, ref2, 320, 2); + push_block_s16(c2->mic_buf, mic2, 320, 4); + run_one_block(c2); + pop_block_s16(c2->out_buf, out2, 320, 4); + if (b >= 10) { + for (int i = 0; i < 320; i++) { + double d01 = (double)out2[4 * i + 0] - out2[4 * i + 1]; + double d23 = (double)out2[4 * i + 2] - out2[4 * i + 3]; + diff01 += d01 * d01; + diff23 += d23 * d23; + } + } + } + zassert_true(diff01 > 1e7 && diff23 > 1e7, "4ch @ 32kHz channels were cloned"); + destroy_ctx(c2); +} + +static void push_block_s32(struct comp_buffer *buf, const int32_t *samples, int frames, int ch) +{ + uint32_t bytes = (uint32_t)(frames * ch * (int)sizeof(int32_t)); + int32_t *wptr = audio_stream_get_wptr(&buf->stream); + + for (int i = 0; i < frames * ch; i++) { + *wptr = samples[i]; + wptr = audio_stream_wrap(&buf->stream, wptr + 1); + } + audio_stream_produce(&buf->stream, bytes); +} + +static void pop_block_s32(struct comp_buffer *buf, int32_t *samples, int frames, int ch) +{ + uint32_t bytes = (uint32_t)(frames * ch * (int)sizeof(int32_t)); + int32_t *rptr = audio_stream_get_rptr(&buf->stream); + + for (int i = 0; i < frames * ch; i++) { + samples[i] = *rptr; + rptr = audio_stream_wrap(&buf->stream, rptr + 1); + } + audio_stream_consume(&buf->stream, bytes); +} + +ZTEST(webrtc_aec_suite, test_bypass_48k_s32_and_controls) +{ + const int rate = 48000; + const int fs = 480; + struct aec_test_ctx *ctx = setup_aec_ctx(rate, 2, 2, SOF_IPC_FRAME_S32_LE, false); + struct processing_module *mod = comp_mod(ctx->dev); + const struct webrtc_aec_comp_data *cd = module_get_private_data(mod); + int32_t ref_s32[480 * 2], mic_s32[480 * 2], out_s32[480 * 2]; + int32_t prev_mic[480 * 2]; + int erl = 0, erle = 0, dms = 0; + double diff_ch = 0.0; + + memset(prev_mic, 0, sizeof(prev_mic)); + zassert_false(cd->enabled); + + for (int b = 0; b < 6; b++) { + for (int i = 0; i < fs; i++) { + int t = b * fs + i; + int16_t s0 = (int16_t)(6000.0 * sin(2.0 * 3.14159265 * 700.0 * t / rate)); + int16_t s1 = (int16_t)(6000.0 * sin(2.0 * 3.14159265 * 1100.0 * t / rate)); + + ref_s32[2 * i + 0] = (int32_t)s0 << 16; + ref_s32[2 * i + 1] = (int32_t)s1 << 16; + mic_s32[2 * i + 0] = (int32_t)s0 << 16; + mic_s32[2 * i + 1] = (int32_t)s1 << 16; + } + push_block_s32(ctx->ref_buf, ref_s32, fs, 2); + push_block_s32(ctx->mic_buf, mic_s32, fs, 2); + run_one_block(ctx); + pop_block_s32(ctx->out_buf, out_s32, fs, 2); + + /* Skip block 0 initial 10ms FIFO prime; blocks 1..5 match prev_mic in bypass */ + if (b >= 1) { + for (int i = 0; i < fs * 2; i++) + zassert_equal(out_s32[i], prev_mic[i], + "48k S32 bypass mismatch at b=%d i=%d", b, i); + } + memcpy(prev_mic, mic_s32, sizeof(prev_mic)); + } + + /* Verify runtime control updates, reset preservation, and 48k active resampling path */ + zassert_equal(set_switch_ctl(mod, 0, 1), 0); + zassert_equal(set_switch_ctl(mod, 1, 0), 0); + if (cd->backend && cd->backend->set_delay) + zassert_equal(cd->backend->set_delay(mod, 18), 0); + zassert_true(cd->enabled); + zassert_false(cd->high_suppression); + zassert_equal(mod->dev->drv->adapter_ops->reset(mod), 0); + + for (int b = 0; b < 20; b++) { + for (int i = 0; i < fs; i++) { + int t = b * fs + i; + + ref_s32[2 * i + 0] = (int32_t)(5000.0 * sin(2.0 * 3.14159265 * 430.0 * t / rate)) << 16; + ref_s32[2 * i + 1] = (int32_t)(5000.0 * sin(2.0 * 3.14159265 * 610.0 * t / rate)) << 16; + mic_s32[2 * i + 0] = (int32_t)(5000.0 * sin(2.0 * 3.14159265 * 997.0 * t / rate)) << 16; + mic_s32[2 * i + 1] = (int32_t)(5000.0 * sin(2.0 * 3.14159265 * 1493.0 * t / rate)) << 16; + } + push_block_s32(ctx->ref_buf, ref_s32, fs, 2); + push_block_s32(ctx->mic_buf, mic_s32, fs, 2); + run_one_block(ctx); + pop_block_s32(ctx->out_buf, out_s32, fs, 2); + if (b >= 5) { + for (int i = 0; i < fs; i++) { + double d = (double)(out_s32[2 * i + 0] >> 16) - + (double)(out_s32[2 * i + 1] >> 16); + diff_ch += d * d; + } + } + } + zassert_true(diff_ch > 1e7, "48k S32 stereo active output channels were cloned"); + if (cd->backend && cd->backend->get_metrics) { + zassert_equal(cd->backend->get_metrics(mod, &erl, &erle, &dms), 0); + zassert_equal(dms, 18); + } + destroy_ctx(ctx); +} + +static void *webrtc_aec_suite_setup(void) +{ + sys_comp_init(sof_get()); + sys_comp_module_webrtc_aec_interface_init(); + return NULL; +} + +ZTEST_SUITE(webrtc_aec_suite, NULL, webrtc_aec_suite_setup, NULL, NULL, NULL); diff --git a/tools/topology/topology2/development/cavs-dmic-ssp-lbm-webrtc-aec.conf b/tools/topology/topology2/development/cavs-dmic-ssp-lbm-webrtc-aec.conf new file mode 100644 index 000000000000..16bb3fed01ee --- /dev/null +++ b/tools/topology/topology2/development/cavs-dmic-ssp-lbm-webrtc-aec.conf @@ -0,0 +1,307 @@ +# +# cAVS hybrid DMIC + SSP2 digital loopback topology for webrtc-aec +# +# Uses onboard DMIC0 (or ESP32-P4 PDM DMIC injector) for microphone capture +# and SSP2 in internal digital loopback (lbm_mode / SSCR1_LBM) for speaker +# playback echo reference: +# +# PCM2 playback ──(5)──> [SSP2 TX -> lbm_mode -> SSP2 RX] ──(12)──┐ +# ▼ +# DMIC0 RX ───────(8)──────────────────────────────> WEBRTC-AEC ──(7)──> PCM0 capture +# + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Define { + MCLK 24576000 + PLATFORM "none" + DMIC_DRIVER_VERSION 1 + DMIC_IO_CLK 38400000 + DMIC0_ID 6 + DMIC0_PCM_ID 0 + DMIC0_PCM_NAME "DMIC0" + DMIC0_NAME "dmic01" + SSP2_PCM_NAME "Port2" + AEC_RATE 16000 + AEC_BCLK 1024000 + AEC_BITS 16 + AEC_FMT "S16_LE" + MIC_CH 2 + REF_CH 2 +} + +IncludeByKey.PLATFORM { + "tgl" "platform/intel/tgl.conf" + "adl" "platform/intel/tgl.conf" + "mtl" "platform/intel/mtl.conf" + "lnl" "platform/intel/lnl.conf" + "ptl" "platform/intel/ptl.conf" + "nvl" "platform/intel/ptl.conf" # Note: Assume same configuration as PTL +} + +Object.Dai.DMIC [ + { + dai_index 0 + name $DMIC0_NAME + id $DMIC0_ID + driver_version $DMIC_DRIVER_VERSION + io_clk $DMIC_IO_CLK + sample_rate $AEC_RATE + clk_min 500000 + clk_max 4800000 + unmute_ramp_time_ms 200 + num_pdm_active 2 + + Object.Base.hw_config.1 { + id 0 + name "DMIC0" + } + + Object.Base.pdm_config.1 { + mic_a_enable 1 + mic_b_enable 1 + ctrl_id 0 + } + } +] + +Object.Dai.SSP [ + { + id 2 + dai_index 2 + direction "duplex" + name "NoCodec-2" + default_hw_conf_id 0 + sample_bits 32 + quirks "lbm_mode" + io_clk $MCLK + Object.Base.hw_config.1 { + name "SSP2" + id 0 + bclk_freq 1024000 + fsync_freq 16000 + tdm_slot_width 32 + Object.Base.link_config.1 { clock_source 1 } + } + } +] + +Object.Pipeline.io-gateway [ + { + index 6 + direction playback + Object.Widget.dai-copier.1 { + dai_index 2 dai_type "SSP" copier_type "SSP" + stream_name "NoCodec-2" node_type $I2S_LINK_OUTPUT_CLASS + num_input_pins 1 + num_input_audio_formats 1 + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $REF_CH + }] + num_output_audio_formats 1 + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth 32 out_valid_bit_depth 32 + out_channels $REF_CH + }] + } + } +] + +Object.Pipeline.host-gateway-playback [ + { + index 5 + Object.Widget.host-copier.1 { + stream_name 'SSP2 Playback' pcm_id 2 + num_input_audio_formats 1 + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $REF_CH + }] + num_output_audio_formats 1 + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $REF_CH + }] + } + } +] + +Object.Pipeline.host-gateway-capture [ + { + index 7 + Object.Widget.host-copier.1 { + stream_name 'DMIC0 Capture' pcm_id $DMIC0_PCM_ID + num_input_audio_formats 1 + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH + }] + num_output_audio_formats 1 + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH + }] + } + } +] + +Object.Pipeline.io-gateway-capture [ + { + index 8 + direction capture + Object.Widget.dai-copier.1 { + dai_index 0 dai_type "DMIC" type dai_out copier_type "DMIC" + stream_name $DMIC0_NAME node_type $DMIC_LINK_INPUT_CLASS + num_input_audio_formats 1 + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth 32 in_valid_bit_depth 32 + in_channels $MIC_CH + }] + num_output_audio_formats 1 + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH + }] + } + } + { + index 12 + direction capture + Object.Widget.dai-copier.1 { + dai_index 2 dai_type "SSP" type dai_out copier_type "SSP" + stream_name "NoCodec-2" node_type $I2S_LINK_INPUT_CLASS + num_input_audio_formats 1 + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth 32 in_valid_bit_depth 32 + in_channels $REF_CH + }] + num_output_audio_formats 1 + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $REF_CH + }] + } + } +] + +Object.Widget.webrtc-aec [ + { + index 7 + name "webrtc-aec.7.1" + num_input_pins 2 + num_input_audio_formats 2 + num_output_audio_formats 1 + + Object.Base.input_audio_format [ + { + input_pin_index 0 + in_rate $AEC_RATE + in_bit_depth $AEC_BITS + in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH + ibs "$[(($in_channels * ($[($in_rate + 999)] / 1000)) * ($in_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + { + input_pin_index 1 + in_rate $AEC_RATE + in_bit_depth $AEC_BITS + in_valid_bit_depth $AEC_BITS + in_channels $REF_CH + ibs "$[(($in_channels * ($[($in_rate + 999)] / 1000)) * ($in_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + ] + + Object.Base.output_audio_format [ + { + out_rate $AEC_RATE + out_bit_depth $AEC_BITS + out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH + obs "$[(($out_channels * ($[($out_rate + 999)] / 1000)) * ($out_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + ] + + Object.Control { + mixer."1" { + name 'DMIC0 Capture AEC Switch' + } + mixer."2" { + name 'DMIC0 Capture AEC Suppression Switch' + } + } + + Object.Base.input_pin_binding.1 { + input_pin_binding_name "dai-copier.DMIC.$DMIC0_NAME.capture" + } + Object.Base.input_pin_binding.2 { + input_pin_binding_name "dai-copier.SSP.NoCodec-2.capture" + } + } +] + +Object.PCM.pcm [ + { + name "$DMIC0_PCM_NAME" + id $DMIC0_PCM_ID + direction "capture" + Object.Base.fe_dai.1 { name "$DMIC0_PCM_NAME" } + Object.PCM.pcm_caps.1 { + direction "capture" name "DMIC0 Capture" formats $AEC_FMT + rate_min $AEC_RATE rate_max $AEC_RATE channels_min $MIC_CH channels_max $MIC_CH + } + } + { + name "$SSP2_PCM_NAME" + id 2 + direction "playback" + Object.Base.fe_dai.1 { name "$SSP2_PCM_NAME" } + Object.PCM.pcm_caps.1 { + direction "playback" name "SSP2 Playback" formats $AEC_FMT + rate_min $AEC_RATE rate_max $AEC_RATE channels_min $REF_CH channels_max $REF_CH + } + } +] + +Object.Base.route [ + { source "host-copier.2.playback" sink "dai-copier.SSP.NoCodec-2.playback" } + { source "dai-copier.DMIC.$DMIC0_NAME.capture" sink "webrtc-aec.7.1" } + { source "dai-copier.SSP.NoCodec-2.capture" sink "webrtc-aec.7.1" } + { source "webrtc-aec.7.1" sink "host-copier.0.capture" } +] diff --git a/tools/topology/topology2/development/cavs-nocodec-webrtc-aec.conf b/tools/topology/topology2/development/cavs-nocodec-webrtc-aec.conf index 1b2df443aaef..fe9833f17a3a 100644 --- a/tools/topology/topology2/development/cavs-nocodec-webrtc-aec.conf +++ b/tools/topology/topology2/development/cavs-nocodec-webrtc-aec.conf @@ -64,6 +64,16 @@ Define { SSP0_PCM_ID 0 SSP0_PCM_NAME "Port0" SSP2_PCM_NAME "Port2" + AEC_RATE 48000 + AEC_HW_CONF_ID 0 + AEC_BITS 16 + AEC_FMT "S16_LE" + MIC_CH 2 + REF_CH 2 + MIC_CH_CFG $CHANNEL_CONFIG_STEREO + MIC_CH_MAP $CHANNEL_MAP_STEREO + REF_CH_CFG $CHANNEL_CONFIG_STEREO + REF_CH_MAP $CHANNEL_MAP_STEREO } IncludeByKey.PLATFORM { @@ -72,6 +82,7 @@ IncludeByKey.PLATFORM { "mtl" "platform/intel/mtl.conf" "lnl" "platform/intel/lnl.conf" "ptl" "platform/intel/ptl.conf" + "nvl" "platform/intel/ptl.conf" # Note: Assume same configuration as PTL } Object.Dai.SSP [ @@ -80,7 +91,7 @@ Object.Dai.SSP [ dai_index 0 direction "duplex" name NoCodec-0 - default_hw_conf_id 0 + default_hw_conf_id $AEC_HW_CONF_ID sample_bits 32 quirks "lbm_mode" io_clk $MCLK @@ -88,6 +99,15 @@ Object.Dai.SSP [ name "SSP0" id 0 bclk_freq 3072000 + fsync_freq 48000 + tdm_slot_width 32 + Object.Base.link_config.1 { clock_source 1 } + } + Object.Base.hw_config.2 { + name "SSP0-16k" + id 1 + bclk_freq 1024000 + fsync_freq 16000 tdm_slot_width 32 Object.Base.link_config.1 { clock_source 1 } } @@ -97,7 +117,7 @@ Object.Dai.SSP [ dai_index 2 direction "duplex" name NoCodec-2 - default_hw_conf_id 0 + default_hw_conf_id $AEC_HW_CONF_ID sample_bits 32 quirks "lbm_mode" io_clk $MCLK @@ -105,6 +125,15 @@ Object.Dai.SSP [ name "SSP2" id 0 bclk_freq 3072000 + fsync_freq 48000 + tdm_slot_width 32 + Object.Base.link_config.1 { clock_source 1 } + } + Object.Base.hw_config.2 { + name "SSP2-16k" + id 1 + bclk_freq 1024000 + fsync_freq 16000 tdm_slot_width 32 Object.Base.link_config.1 { clock_source 1 } } @@ -121,9 +150,15 @@ Object.Pipeline.io-gateway [ stream_name "NoCodec-0" node_type $I2S_LINK_OUTPUT_CLASS num_input_pins 1 num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 16 in_valid_bit_depth 16 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH in_ch_cfg $MIC_CH_CFG in_ch_map $MIC_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 32 out_valid_bit_depth 32 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth 32 out_valid_bit_depth 32 + out_channels $MIC_CH out_ch_cfg $MIC_CH_CFG out_ch_map $MIC_CH_MAP + }] } } { @@ -134,9 +169,15 @@ Object.Pipeline.io-gateway [ stream_name "NoCodec-2" node_type $I2S_LINK_OUTPUT_CLASS num_input_pins 1 num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 16 in_valid_bit_depth 16 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $REF_CH in_ch_cfg $REF_CH_CFG in_ch_map $REF_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 32 out_valid_bit_depth 32 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth 32 out_valid_bit_depth 32 + out_channels $REF_CH out_ch_cfg $REF_CH_CFG out_ch_map $REF_CH_MAP + }] } } ] @@ -147,9 +188,15 @@ Object.Pipeline.host-gateway-playback [ Object.Widget.host-copier.1 { stream_name 'SSP0 Playback' pcm_id 0 num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 16 in_valid_bit_depth 16 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH in_ch_cfg $MIC_CH_CFG in_ch_map $MIC_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 16 out_valid_bit_depth 16 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH out_ch_cfg $MIC_CH_CFG out_ch_map $MIC_CH_MAP + }] } } { @@ -157,9 +204,15 @@ Object.Pipeline.host-gateway-playback [ Object.Widget.host-copier.1 { stream_name 'SSP2 Playback' pcm_id 2 num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 16 in_valid_bit_depth 16 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $REF_CH in_ch_cfg $REF_CH_CFG in_ch_map $REF_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 16 out_valid_bit_depth 16 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $REF_CH out_ch_cfg $REF_CH_CFG out_ch_map $REF_CH_MAP + }] } } ] @@ -171,9 +224,15 @@ Object.Pipeline.host-gateway-capture [ Object.Widget.host-copier.1 { stream_name 'SSP0 Capture' pcm_id 0 num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 16 in_valid_bit_depth 16 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth $AEC_BITS in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH in_ch_cfg $MIC_CH_CFG in_ch_map $MIC_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 16 out_valid_bit_depth 16 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH out_ch_cfg $MIC_CH_CFG out_ch_map $MIC_CH_MAP + }] } } ] @@ -186,9 +245,15 @@ Object.Pipeline.io-gateway-capture [ dai_index 0 dai_type "SSP" type dai_out copier_type "SSP" stream_name "NoCodec-0" node_type $I2S_LINK_INPUT_CLASS num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 32 in_valid_bit_depth 32 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth 32 in_valid_bit_depth 32 + in_channels $MIC_CH in_ch_cfg $MIC_CH_CFG in_ch_map $MIC_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 16 out_valid_bit_depth 16 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH out_ch_cfg $MIC_CH_CFG out_ch_map $MIC_CH_MAP + }] } } { @@ -198,9 +263,15 @@ Object.Pipeline.io-gateway-capture [ dai_index 2 dai_type "SSP" type dai_out copier_type "SSP" stream_name "NoCodec-2" node_type $I2S_LINK_INPUT_CLASS num_input_audio_formats 1 - Object.Base.input_audio_format [{ in_bit_depth 32 in_valid_bit_depth 32 }] + Object.Base.input_audio_format [{ + in_rate $AEC_RATE in_bit_depth 32 in_valid_bit_depth 32 + in_channels $REF_CH in_ch_cfg $REF_CH_CFG in_ch_map $REF_CH_MAP + }] num_output_audio_formats 1 - Object.Base.output_audio_format [{ out_bit_depth 16 out_valid_bit_depth 16 }] + Object.Base.output_audio_format [{ + out_rate $AEC_RATE out_bit_depth $AEC_BITS out_valid_bit_depth $AEC_BITS + out_channels $REF_CH out_ch_cfg $REF_CH_CFG out_ch_map $REF_CH_MAP + }] } } ] @@ -213,6 +284,52 @@ Object.Widget.webrtc-aec [ index 7 name "webrtc-aec.7.1" num_input_pins 2 + num_input_audio_formats 2 + num_output_audio_formats 1 + + Object.Base.input_audio_format [ + { + input_pin_index 0 + in_rate $AEC_RATE + in_bit_depth $AEC_BITS + in_valid_bit_depth $AEC_BITS + in_channels $MIC_CH + in_ch_cfg $MIC_CH_CFG + in_ch_map $MIC_CH_MAP + ibs "$[(($in_channels * ($[($in_rate + 999)] / 1000)) * ($in_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + { + input_pin_index 1 + in_rate $AEC_RATE + in_bit_depth $AEC_BITS + in_valid_bit_depth $AEC_BITS + in_channels $REF_CH + in_ch_cfg $REF_CH_CFG + in_ch_map $REF_CH_MAP + ibs "$[(($in_channels * ($[($in_rate + 999)] / 1000)) * ($in_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + ] + + Object.Base.output_audio_format [ + { + out_rate $AEC_RATE + out_bit_depth $AEC_BITS + out_valid_bit_depth $AEC_BITS + out_channels $MIC_CH + out_ch_cfg $MIC_CH_CFG + out_ch_map $MIC_CH_MAP + obs "$[(($out_channels * ($[($out_rate + 999)] / 1000)) * ($out_bit_depth / 8)) * $WEBRTC_AEC_PERIOD_MS]" + } + ] + + Object.Control { + mixer."1" { + name 'SSP0 Capture AEC Switch' + } + mixer."2" { + name 'SSP0 Capture AEC Suppression Switch' + } + } # Pin 0: microphone (same pipeline 7 as the host-copier sink) Object.Base.input_pin_binding.1 { @@ -232,10 +349,12 @@ Object.PCM.pcm [ direction "duplex" Object.Base.fe_dai.1 { name "$SSP0_PCM_NAME" } Object.PCM.pcm_caps.1 { - direction "playback" name "SSP0 Playback" formats 'S16_LE' + direction "playback" name "SSP0 Playback" formats $AEC_FMT + rate_min $AEC_RATE rate_max $AEC_RATE channels_min $MIC_CH channels_max $MIC_CH } Object.PCM.pcm_caps.2 { - direction "capture" name "SSP0 Capture" formats 'S16_LE' + direction "capture" name "SSP0 Capture" formats $AEC_FMT + rate_min $AEC_RATE rate_max $AEC_RATE channels_min $MIC_CH channels_max $MIC_CH } } { @@ -244,7 +363,8 @@ Object.PCM.pcm [ direction "playback" Object.Base.fe_dai.1 { name "$SSP2_PCM_NAME" } Object.PCM.pcm_caps.1 { - direction "playback" name "SSP2 Playback" formats 'S16_LE' + direction "playback" name "SSP2 Playback" formats $AEC_FMT + rate_min $AEC_RATE rate_max $AEC_RATE channels_min $REF_CH channels_max $REF_CH } } ] diff --git a/tools/topology/topology2/development/tplg-targets.cmake b/tools/topology/topology2/development/tplg-targets.cmake index 07f91662df7e..f04ba5219609 100644 --- a/tools/topology/topology2/development/tplg-targets.cmake +++ b/tools/topology/topology2/development/tplg-targets.cmake @@ -339,9 +339,24 @@ PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-tgl-nocodec-rtcaec.bin" "development/cavs-nocodec-webrtc-ns\;sof-tgl-nocodec-webrtc-ns\;PLATFORM=tgl,\ PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-tgl-nocodec-webrtc-ns.bin" -# WebRTC AECm echo canceller (dual SSP: mic + ref) on TGL nocodec +# WebRTC AEC echo canceller (dual SSP lbm_mode: mic + ref) on TGL/PTL nocodec "development/cavs-nocodec-webrtc-aec\;sof-tgl-nocodec-webrtc-aec\;PLATFORM=tgl,\ PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-tgl-nocodec-webrtc-aec.bin" +"development/cavs-nocodec-webrtc-aec\;sof-ptl-nocodec-webrtc-aec\;PLATFORM=ptl,\ +PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-ptl-nocodec-webrtc-aec.bin" +"development/cavs-nocodec-webrtc-aec\;sof-tgl-nocodec-webrtc-aec-16k\;PLATFORM=tgl,\ +AEC_RATE=16000,AEC_HW_CONF_ID=1,PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-tgl-nocodec-webrtc-aec-16k.bin" +"development/cavs-nocodec-webrtc-aec\;sof-ptl-nocodec-webrtc-aec-16k\;PLATFORM=ptl,\ +AEC_RATE=16000,AEC_HW_CONF_ID=1,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,AEC_HW_CONF_ID=1,MIC_CH=1,REF_CH=2,MIC_CH_CFG=0,MIC_CH_MAP=0xFFFFFFF0,\ +PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-ptl-nocodec-webrtc-aec-2r1c.bin" + +# WebRTC AEC hybrid DMIC0 capture + SSP2 digital loopback (lbm_mode) echo reference +"development/cavs-dmic-ssp-lbm-webrtc-aec\;sof-tgl-dmic-ssp-lbm-webrtc-aec\;PLATFORM=tgl,\ +PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-tgl-dmic-ssp-lbm-webrtc-aec.bin" +"development/cavs-dmic-ssp-lbm-webrtc-aec\;sof-ptl-dmic-ssp-lbm-webrtc-aec\;PLATFORM=ptl,\ +PREPROCESS_PLUGINS=nhlt,NHLT_BIN=nhlt-sof-ptl-dmic-ssp-lbm-webrtc-aec.bin" # WebRTC NS2/RNNoise (48 kHz float) on TGL nocodec SSP "development/cavs-nocodec-webrtc-ns2\;sof-tgl-nocodec-webrtc-ns2\;PLATFORM=tgl,\ diff --git a/west.yml b/west.yml index 6a89bbecf3cd..3f15d72ac3ff 100644 --- a/west.yml +++ b/west.yml @@ -51,7 +51,7 @@ manifest: - name: webrtc-apm repo-path: webrtc-audio-processing path: modules/audio/webrtc-apm - revision: 3e9c41a268fbeb36a7de2c5cb2f1b02bc7fef098 + revision: 07232bb5e5252210da688796eac66538ca8d5939 # rnnoise — xiph/rnnoise deep-learning noise suppressor (webrtc_ns2) - name: rnnoise