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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions doc/developer_guides/wov_ecns_integration_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ The reference topology establishes a unified 4-channel native 16 kHz architectur
## 1. System Architecture Overview

The pipeline separates real-time audio ingest into two primary scheduling domains:
- **Low-Latency (LL) Domain (1 ms period)**: Ingests 2/4-channel 16 kHz and 48 kHz microphone data from the DMIC DAIs and the speaker echo reference (48 kHz, converted to 16 kHz stereo by `src.120.1`) without frame jitter.
- **Low-Latency (LL) Domain (1 ms period)**: Ingests 2/4-channel 16 kHz and 48 kHz microphone data from the DMIC DAIs and the speaker echo reference (48 kHz, converted to 16 kHz stereo by `src.124.1`) without frame jitter.
- **Data Processing (DP) Domain (20 ms period)**: Runs block-based processing for acoustic echo cancellation, noise suppression, circular buffering, feature extraction, and neural network keyword classification.

```mermaid
Expand Down Expand Up @@ -55,9 +55,11 @@ flowchart TD
SPK["Speaker playback<br/>(module-copier + loopback DAI,<br/>per platform)"]
subgraph P120 ["Pipeline 120: Speaker Echo Reference (Core 0, LL 1ms)"]
SIGGEN["siggen.120.1<br/>(48 kHz · 2ch · passthrough,<br/>silence when speaker is idle)"]
SRC_120["src.120.1<br/>(48 kHz → 16 kHz · 2ch · S32_LE)"]
SIGGEN --> SRC_120
end
subgraph P124 ["Pipeline 124: 16 kHz Echo Reference SRC (Core 0, LL 1ms)"]
SRC_120["src.124.1<br/>(48 kHz → 16 kHz · 2ch · S32_LE)"]
end
SIGGEN --> SRC_120
SPK --> SIGGEN

%% Pipeline 115: ECNS DP Pipeline
Expand Down Expand Up @@ -128,7 +130,7 @@ flowchart TD

## 2. Developing a Custom ECNS Module

An ECNS component acts as a two-source Data Processing (DP) block. It consumes the interleaved multi-channel microphone stream and the speaker echo reference on two input pins and emits cleaned mono audio on a single output pin. The reference implementation `src/audio/ecns/ecns.c` averages the microphone channels to mono (or takes the single channel selected with the `mic channel` enum), applies a 100 Hz high-pass IIR (`boost` switch selects +30 dB or 0 dB), and when the `AEC switch` is on subtracts the `(L+R)/2` average of the echo reference after the IIR. The `NS switch` has no function yet. The echo reference is always consumed, also when the AEC switch is off.
An ECNS component acts as a two-source Data Processing (DP) block. It consumes the interleaved multi-channel microphone stream and the speaker echo reference on two input pins and emits cleaned mono audio on a single output pin. The reference implementation `src/audio/ecns/ecns.c` averages the microphone channels to mono (or takes the single channel selected with the `mic channel` enum), applies a 100 Hz high-pass IIR (`boost` switch selects +30 dB or 0 dB), and when the `AEC switch` is on subtracts the `(L+R)/2` average of the echo reference after the IIR. The `NS switch` has no function yet. The echo reference is always consumed, also when the AEC switch is off. The output channel count follows the consumer input format: the KPB path is mono, while a multichannel host capture (e.g. the 48 kHz `DMIC0 ECNS` PCM) gets the microphone channels passed through with `Average`, or the selected `MicN` duplicated to all channels, with the reference average subtracted from each channel.

### Audio Data Interface Contract
- **Input Pin 0 (Source 0 — Microphones)**:
Expand All @@ -137,7 +139,7 @@ An ECNS component acts as a two-source Data Processing (DP) block. It consumes t
- Sample Format: `S32_LE` in the topology (the firmware also accepts `S16_LE`).
- Frame Period: 20 ms (`ibs` 2,560 bytes).
- **Input Pin 1 (Source 1 — Speaker Echo Reference)**:
- Channels: 2 (far-end playback, from `src.120.1`).
- Channels: 2 (far-end playback, from `src.124.1`).
- Rate: 16,000 Hz.
- Sample Format: `S32_LE`.
- Frame Period: 20 ms (320 frames = 2,560 bytes).
Expand Down Expand Up @@ -484,7 +486,7 @@ Class.Control.enum."score_enum" {
> provide. They are kept as an illustration of the pipeline structure. The
> current ECNS in `platform/intel/dmic-wov-multi.conf` (`ecns.115.1`) has two
> input pins (16 kHz microphones from `dmic16k` and the 16 kHz stereo speaker
> echo reference from `src.120.1`) and a single 16 kHz mono output pin to
> echo reference from `src.124.1`) and a single 16 kHz mono output pin to
> `kpb.116.1`, without mixin/mixout widgets.

#### 1. ECNS Pipeline (Pipeline 105)
Expand Down Expand Up @@ -611,8 +613,11 @@ Follow this step-by-step checklist to integrate your own algorithms:
`cavs-sdw` `*-wov-multi` targets in `production/tplg-targets-ace3.cmake`.
Wildcat Lake topologies are symlinks to the Panther Lake ones.
4. Route the speaker echo reference into `siggen.120.1` of the echo reference
pipeline 120 (`siggen-src-capture`), which feeds ECNS input pin 1 through
`src.120.1`. This is enabled with `SDW_SPK_ECHO_REF_ECNS=true` (SoundWire,
pipeline 120 (`siggen-copier-capture`), which feeds ECNS input pin 1 through
`src.124.1` in pipeline 124. Keep a widget that only some of the PCMs use,
such as this SRC, out of a pipeline that other PCMs keep running: the
kernel frees the widget when its last PCM stops, but the firmware deletes
the module only with its pipeline. This is enabled with `SDW_SPK_ECHO_REF_ECNS=true` (SoundWire,
together with `SDW_SPK_ECHO_REF=true` and `SDW_ECHO_REF_DAI=true`),
`SPEAKER_ECHO_REF_ECNS=true` (ADL rt5682 SSP, needs `INCLUDE_ECHO_REF=true`)
or `HDA_SPEAKER_ECHO_REF_ECNS=true` (HDA generic). A dai_out widget upstream
Expand Down
9 changes: 5 additions & 4 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,11 @@ config COMP_ECNS
help
Select to build the ECNS (Echo Cancellation and Noise Suppression)
Data Processing (DP) component. Operates with a 20ms period. Input
pin 0 takes the 16 kHz microphone stream and input pin 1 the 16 kHz
echo reference. The single output pin provides 16 kHz mono, e.g.
to KPB. The microphone channel enum control selects the average
of all channels or a single channel. The AEC switch control
pin 0 takes the microphone stream and input pin 1 the echo
reference, both at 16 kHz or 48 kHz. The single output pin provides
mono at the same rate, e.g. 16 kHz to KPB for WoV or 48 kHz to a
host PCM for VoIP. The microphone channel enum control selects the
average of all channels or a single channel. The AEC switch control
subtracts the echo reference from the output. The NS switch
control has no function yet.

Expand Down
82 changes: 62 additions & 20 deletions src/audio/ecns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,49 @@
## Overview

The `ecns` component is an IPC4 module in a 20 ms pipeline of the multi-slot
Wake-on-Voice (WoV) topology. It has two input pins and one output pin:
Wake-on-Voice (WoV) topology. It runs at 16 kHz or 48 kHz, the rate is taken
from the input pin 0 format in the IPC4 base config. Both inputs and the
output must have the same rate, the module does not convert rates. Other
rates are rejected when the module is created, and an echo reference with a
different rate when it is prepared. It has two input pins and one output pin,
described here for the 16 kHz WoV use:

- **Input Pin 0**: 16 kHz microphone stream from the `dmic16k` DMIC DAI copier,
2 or 4 channels, 16 or 32 bit.
- **Input Pin 1**: 16 kHz stereo speaker echo reference, 16 or 32 bit. The
topology provides it from the speaker playback via a siggen and a 48 kHz to
16 kHz SRC.
- **Output Pin 0**: 16 kHz mono to the Key Phrase Buffer (`kpb.116.1`), 16 or
32 bit. The firmware follows the bit depth of the KPB input format defined in
topology.
32 bit. The firmware follows the channel count, channel map and bit depth of
the consumer input format defined in topology. Up to `ECNS_OUT_CH_MAX` (4)
output channels are supported, e.g. for a 48 kHz host capture.

ECNS is not a module adapter module, so it does not set the format of its
input buffers at bind as IPC4 consumer modules do. The copier and SRC set
the format of their output buffers, but e.g. a siggen in pass-through mode
does not. When prepared, ECNS takes the format of an input buffer without
one from the base config of the producer.

The processing for each frame is:

1. Average the microphone channels into mono, or take a single channel. The
selection is done with the microphone channel enum control.
1. Take the microphone signal. The microphone channel enum control selects
between the average and a single channel:
- Mono output: average the microphone channels into mono, or take the
selected channel.
- Two or more output channels: with `Average` pass microphone channel *c*
to output channel *c*. If the output has more channels than the
microphone input, the input channels repeat. With a single channel
selection, e.g. `Mic1`, duplicate that channel to all output channels.
2. Filter with the built-in 100 Hz second-order high-pass IIR
(`CONFIG_ECNS_KPB_HPF`, default `y`).
(`CONFIG_ECNS_KPB_HPF`, default `y`). There are coefficients for 16 kHz
and 48 kHz, the set is selected by the rate. Each output channel has its
own filter state; a duplicated channel is filtered once. The filters of
channels 1 and up are cleared when the mic channel control switches from
a single channel to pass-through.
3. When the AEC switch is on, subtract the average of the echo reference
channels, (L+R)/2 for stereo, from the filtered signal with saturation.
4. Write the mono sample as s16 or s32.
channels, (L+R)/2 for stereo, from each filtered output channel with
saturation.
4. Write the samples as s16 or s32.

The echo reference is always consumed, also when the AEC switch is off. If
the reference has fewer frames available than the microphone, the missing
Expand All @@ -47,10 +70,10 @@ added in the widget instance with

| Value | Topology name (DMIC WoV) | Function | Default |
|---|---|---|---|
| 0 | `DMIC ECNS mic channel` `Average` | Average of all microphone channels | yes |
| 1..2 or 1..4 | `Mic1`, `Mic2`, (`Mic3`, `Mic4` with 4ch) | Single microphone channel | |
| 0 | `DMIC ECNS mic channel` `Average` | Average of all microphone channels, or pass-through with a multichannel output | yes |
| 1..2 or 1..4 | `Mic1`, `Mic2`, (`Mic3`, `Mic4` with 4ch) | Single microphone channel, duplicated to all output channels | |

A channel beyond the input channel count falls back to the average.
A channel beyond the input channel count falls back to `Average`.

The firmware keeps duplicate coefficient sets for the boost and only moves the
IIR coefficient pointers, so the filter state is kept. The firmware starts
Expand All @@ -64,32 +87,51 @@ flowchart TD
SPK["speaker playback module-copier<br/>(e.g. module-copier.21.22)"]
LOOP["echo reference start DAI<br/>(e.g. alh-copier.Loopback_Virtual.25)"]
SIGGEN["siggen.120.1<br/>48 kHz stereo, silence without speaker"]
SRC["src.120.1<br/>48 kHz → 16 kHz stereo s32"]
MC120["module-copier.120.2<br/>48 kHz stereo, also to the 48 kHz ECNS"]
SRC["src.124.1, own pipeline 124<br/>48 kHz → 16 kHz stereo s32"]
ECNS["ecns.115.1<br/>mic average or channel → 100 Hz HPF → − (L+R)/2 ref"]
KPB["kpb.116.1<br/>16 kHz mono"]

DMIC16K -->|"Pin 0"| ECNS
SPK --> SIGGEN
LOOP --> SIGGEN
SIGGEN --> SRC
SIGGEN --> MC120
MC120 --> SRC
SRC -->|"Pin 1"| ECNS
ECNS -->|"Out Pin 0"| KPB
```

The 48 kHz DMIC stream is not processed by ECNS. It is captured with the
regular DMIC0 pipelines of
The 48 kHz DMIC stream is captured with the regular DMIC0 pipelines of
`tools/topology/topology2/platform/intel/dmic-generic.conf`, without the
TDFB and DRC enhancements.
TDFB and DRC enhancements, to the raw PCM. A second ECNS instance,
`ecns.122.1` in `tools/topology/topology2/platform/intel/dmic-wov-multi.conf`,
runs at 48 kHz for VoIP. It takes the microphones from the DMIC0 DAI pipeline
module-copier, before the raw PCM IIR, and the 48 kHz echo reference from
`module-copier.120.2` between the siggen and the SRC. Its controls are named
`DMIC0 ECNS boost`, `DMIC0 ECNS AEC switch`, `DMIC0 ECNS NS switch` and
`DMIC0 ECNS mic channel`. Its output and PCM 15 have the DMIC0 DAI channel
count, 2 or 4, so the multichannel output processing described above is
used.

A third instance, `ecns.151.1` in
`tools/topology/topology2/platform/intel/sdw-jack-ecns.conf`
(`INCLUDE_SDW_JACK_ECNS=true`), runs at 48 kHz for the SoundWire headset
microphone. It takes the stereo microphone from `module-copier.11.0` and the
stereo jack echo reference from `module-copier.1.12` via `siggen.150.1`. The
stereo output is captured with PCM 13 `Jack In ECNS`. Its controls are named
`Jack ECNS boost`, `Jack ECNS AEC switch`, `Jack ECNS NS switch` and
`Jack ECNS mic channel`.

## Specifications

| Parameter | Specification |
|---|---|
| Module UUID | `6c:8a:4f:21:3a:49:1e:4b:8b:1e:0d:3b:6f:8a:2c:15` |
| Execution Period | 20 ms (320 frames at 16 kHz) |
| Input Pin 0 | 16 kHz · 2 or 4 channels · s16/s32 |
| Input Pin 1 | 16 kHz · 2 channels · s16/s32 |
| Output Pin 0 | 16 kHz · 1 channel · s16/s32 |
| Sample Rate | 16 kHz or 48 kHz, the same for all pins |
| Execution Period | 20 ms (320 frames at 16 kHz, 960 frames at 48 kHz) |
| Input Pin 0 | 2 or 4 channels · s16/s32 |
| Input Pin 1 | 2 channels · s16/s32 |
| Output Pin 0 | 1 to 4 channels · s16/s32, follows the consumer input format |
| Dynamic Pipeline | Compatible (`dynamic_pipeline 1`) |
| Power States | S0 active streaming and D0i3 low-power listening supported |

Expand Down
Loading
Loading