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
3 changes: 2 additions & 1 deletion app/boards/intel_adsp_ace30_ptl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ CONFIG_COMP_WOV_ARBITER=y
CONFIG_COMP_KPB=y
CONFIG_KPB_MAX_BUFF_TIME=2000
CONFIG_COMP_ECNS=y
CONFIG_ECNS_TEST_SIGNAL=y
# Silent speaker echo reference for ECNS when playback is not running
CONFIG_COMP_TONE=y
CONFIG_SOF_STAGING=y
CONFIG_COMP_MFCC=y
CONFIG_COMP_MFCC_PCAN=y
Expand Down
3 changes: 2 additions & 1 deletion app/boards/intel_adsp_ace30_wcl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ CONFIG_COMP_MIXIN_MIXOUT=y
CONFIG_COMP_WOV_ARBITER=y
CONFIG_COMP_KPB=y
CONFIG_COMP_ECNS=y
CONFIG_ECNS_TEST_SIGNAL=y
# Silent speaker echo reference for ECNS when playback is not running
CONFIG_COMP_TONE=y
CONFIG_SOF_STAGING=y
CONFIG_COMP_MFCC=y
CONFIG_COMP_MFCC_PCAN=y
Expand Down
3 changes: 2 additions & 1 deletion app/boards/intel_adsp_ace40_nvl.conf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ CONFIG_COMP_WOV_ARBITER=y
CONFIG_COMP_KPB=y
CONFIG_KPB_MAX_BUFF_TIME=2000
CONFIG_COMP_ECNS=y
CONFIG_ECNS_TEST_SIGNAL=y
# Silent speaker echo reference for ECNS when playback is not running
CONFIG_COMP_TONE=y
CONFIG_SOF_STAGING=y
CONFIG_COMP_MFCC=y
CONFIG_COMP_MFCC_PCAN=y
Expand Down
3 changes: 2 additions & 1 deletion app/boards/intel_adsp_cavs25.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ CONFIG_COMP_WOV_ARBITER=y
CONFIG_COMP_KPB=y
CONFIG_KPB_MAX_BUFF_TIME=2000
CONFIG_COMP_ECNS=y
CONFIG_ECNS_KPB_MONO_AVG_ALL=y
# Silent speaker echo reference for ECNS when playback is not running
CONFIG_COMP_TONE=y
CONFIG_SOF_STAGING=y
CONFIG_COMP_MFCC=y
CONFIG_COMP_MFCC_PCAN=y
Expand Down
Binary file removed build/sof-ptl-dmic-wov-multi-4ch.tplg
Binary file not shown.
Binary file removed build/sof-tgl-dmic-wov-multi-4ch.tplg
Binary file not shown.
Binary file removed build/sof-wcl-dmic-wov-multi-4ch.tplg
Binary file not shown.
222 changes: 125 additions & 97 deletions doc/developer_guides/wov_ecns_integration_guide.md

Large diffs are not rendered by default.

62 changes: 12 additions & 50 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -121,62 +121,24 @@ config COMP_ECNS
select MATH_IIR_DF1
help
Select to build the ECNS (Echo Cancellation and Noise Suppression)
Data Processing (DP) component. Operates with a 20ms period to process
4 DMIC channels (2 mics + 2 echo references) and outputs clean mono
to KPB and clean stereo to host capture.
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
subtracts the echo reference from the output. The NS switch
control has no function yet.

if COMP_ECNS

choice
prompt "ECNS mono downmix source channels for KPB output"
default ECNS_KPB_MONO_AVG_ALL
help
Selects which pin0 input channels ECNS averages into the mono
detection output sent to KPB. Channel indices out of range for the
current input stream are skipped, falling back to all channels.

config ECNS_KPB_MONO_AVG_ALL
bool "Average all available input channels"
help
Average every available pin0 input channel into the mono output.

config ECNS_KPB_MONO_AVG_CH_1_2
bool "Average input channels 1 and 2"
help
Average the first two input channels (indices 0 and 1).

config ECNS_KPB_MONO_AVG_CH_3_4
bool "Average input channels 3 and 4"
help
Average the third and fourth input channels (indices 2 and 3).
Useful when the first mic pair is poor quality.

endchoice

config ECNS_KPB_HPF
bool "ECNS 100 Hz high-pass filter on KPB output"
bool "ECNS 100 Hz high-pass filter on output"
default y
help
Filter the ECNS mono KPB output (Pin 0) with a built-in 100 Hz
second-order high-pass IIR with +20 dB gain. When disabled, the
mono downmix is passed through with only s16/s32 format conversion.

config ECNS_HOST_HPF
bool "ECNS 40 Hz high-pass filter on host output"
default y
help
Filter each channel of the ECNS host output (Pin 1) with a built-in
40 Hz second-order high-pass IIR with +20 dB gain. When disabled,
the Pin 1 data is passed through with only s16/s32 format conversion.

config ECNS_TEST_SIGNAL
bool "ECNS test signal generator support"
default n
help
Enable support for the test signal generator on the ECNS clean mono
output pin (Pin 0 to KPB). When enabled, a monotonic incrementing
counter can be selected via ALSA control instead of microphone audio
to verify data continuity through the detection path.
Filter the ECNS mono output with a built-in 100 Hz second-order
high-pass IIR with +30 dB gain, or 0 dB gain when the capture boost
control is off. When disabled, the mono signal is passed through
with only s16/s32 format conversion.

endif # COMP_ECNS

Expand Down
207 changes: 77 additions & 130 deletions src/audio/ecns/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,150 +2,97 @@

## Overview

The `ecns` component is an IPC4 Data Processing (DP) module operating at a 20 ms period. It supports dual-stream, dual-rate microphone capture and preprocessing, connecting directly to physical PDM digital microphone interfaces:
- **Input Pin 0 (`dmic16k` on PDM1)**: 16 kHz stereo (2-channel, 16-bit `S16_LE`) dedicated speech capture stream.
- **Input Pin 1 (`dmic01` on PDM0)**: 48 kHz stereo (2-channel, 16-bit `S16_LE`) high-resolution capture stream.

The module performs echo cancellation, noise suppression, and channel routing, delivering two distinct output streams via separate output pins:
1. **Output Pin 0 (Mono Clean Speech / Keyword Stream)**: Operates at 16 kHz. Extracts the Left channel from Input Pin 0 and delivers a single-channel mono clean stream to the Key Phrase Buffer (`kpb.116.1`) and downstream microWakeWord (`mww`) keyword detection slots. Triggers deliver pre-roll and live speech to the host via the WOV Arbiter (`PCM 12`, `hw:0,12`).
2. **Output Pin 1 (Stereo Clean Speech Stream)**: Operates at 48 kHz. Filters each channel of Input Pin 1 with a built-in 40 Hz second-order high-pass IIR (DF1, +20 dB gain, `CONFIG_ECNS_HOST_HPF`, default `y`; when disabled the data is passed through with only s16/s32 conversion) and delivers the stereo or 4-channel clean stream to host capture (`host-copier.11.capture`, `PCM 11`, `hw:0,11`).

Both capture endpoints support low-power D0i3 listening and wake (`capture_compatible_d0i3: true`).

The `ECNS capture boost` switch control selects between the boosted high-pass responses (+30 dB 100 Hz on Pin 0 with `CONFIG_ECNS_KPB_HPF`, +20 dB 40 Hz on Pin 1) and the same filters with 0 dB gain. The firmware keeps duplicate coefficient sets and only moves the IIR coefficient pointers, so the filter state is kept. The firmware starts boosted, but the kernel sends the switch value (default off, 0 dB) when the widget is set up. The `ecns_kpb_test_signal` switch replaces Pin 0 output with a test ramp (`CONFIG_ECNS_TEST_SIGNAL`).

---

## Topology Architecture
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:

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

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.
2. Filter with the built-in 100 Hz second-order high-pass IIR
(`CONFIG_ECNS_KPB_HPF`, default `y`).
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.

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
frames are processed as zero. When the output is not active or is full, both
inputs are drained to prevent upstream overruns.

## Controls

The switch controls are identified by their order in the widget class
`tools/topology/topology2/include/components/ecns.conf`:

| Index | Topology name (DMIC WoV) | Function | Default |
|---|---|---|---|
| 0 | `DMIC ECNS boost` | 100 Hz high-pass with +30 dB gain when on, 0 dB when off | off |
| 1 | `DMIC ECNS AEC switch` | Subtract the echo reference from the output | off |
| 2 | `DMIC ECNS NS switch` | Noise suppression, no function yet | off |

The microphone channel enum control is the only enum control, index 0. It is
added in the widget instance with
`tools/topology/topology2/include/components/ecns/mic_sel_2ch.conf` or
`mic_sel_4ch.conf` to match the pin 0 channel count:

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

A channel beyond the input channel count falls back to the 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
boosted, but the kernel sends the switch value when the widget is set up.

## Topology

```mermaid
flowchart TD
%% Hardware PDM Interfaces
subgraph PDM_INTERFACES ["Digital Microphone Interfaces (2 Separate PDM DAIs)"]
direction LR
PDM_48K["<b>PDM Interface: dmic01</b><br/>DAI Index: 0 (PDM0)<br/>Rate: <b>48 kHz</b> · 2ch Stereo · 16-bit"]
PDM_16K["<b>PDM Interface: dmic16k</b><br/>DAI Index: 1 (PDM1)<br/>Rate: <b>16 kHz</b> · 2ch Stereo · 16-bit"]
end

%% Pipeline 110: 48 kHz DAI Capture
subgraph P110 ["Pipeline 110: 48 kHz DAI Capture (Core 0, LL 1ms)"]
DAI_48K["dai-copier.DMIC.dmic01.capture<br/>(48 kHz · 2ch · S16_LE)"]
MIXIN_110["mixin.110.1<br/>(48 kHz · 2ch)"]
DAI_48K --> MIXIN_110
end

%% Pipeline 119: 16 kHz DAI Capture
subgraph P119 ["Pipeline 119: 16 kHz DAI Capture (Core 0, LL 1ms)"]
DAI_16K["dai-copier.DMIC.dmic16k.capture<br/>(16 kHz · 2ch · S16_LE)"]
MIXIN_119["mixin.119.1<br/>(16 kHz · 2ch)"]
DAI_16K --> MIXIN_119
end

PDM_48K --> DAI_48K
PDM_16K --> DAI_16K

%% Pipeline 115: Dual-Rate ECNS DP Pipeline
subgraph P115 ["Pipeline 115: ECNS Engine (Core 0, DP 20ms, lp_mode 1)"]
direction TB

MIXOUT_115_2["mixout.115.2<br/>(Pin 0 In: 16 kHz · 2ch stereo)"]
MIXOUT_115_1["mixout.115.1<br/>(Pin 1 In: 48 kHz · 2ch stereo)"]

ECNS["ecns.115.1 (DP Component · 20ms Period)<br/>━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br/><b>Pin 0 In:</b> 16 kHz, 2ch (IBS 1280 bytes)<br/><b>Pin 1 In:</b> 48 kHz, 2ch (IBS 3840 bytes)<br/>─────────────────────────────<br/><b>Processing:</b><br/>• Pin 0: Extract Left Ch → 16k Mono Clean<br/>• Pin 1: 40 Hz HPF +20 dB → 48k Stereo Clean<br/>─────────────────────────────<br/><b>Pin 0 Out:</b> 16 kHz, 1ch mono (OBS 640 bytes)<br/><b>Pin 1 Out:</b> 48 kHz, 2ch stereo (OBS 3840 bytes)"]

MIXOUT_115_2 -->|"Pin 0 In (16k)"| ECNS
MIXOUT_115_1 -->|"Pin 1 In (48k)"| ECNS
end

MIXIN_119 --> MIXOUT_115_2
MIXIN_110 --> MIXOUT_115_1

%% Pipeline 117: Host Capture PCM 11
subgraph P117 ["Pipeline 117: ECNS Clean Host Capture (Core 0, LL 1ms)"]
HOST_11["host-copier.11.capture<br/>(PCM 11: 'DMIC ECNS Capture'<br/>hw:0,11 · d0i3_compatible=true)"]
end

%% Pipeline 116: KPB History Buffer
subgraph P116 ["Pipeline 116: Key Phrase Buffer (Core 0, DP 20ms)"]
KPB["kpb.116.1<br/>(2000 ms mono history = 64 KB)"]
MIXIN_116["mixin.116.1<br/>(3-way detector fanout)"]
KPB -->|"Pin 0 (Live Feed)"| MIXIN_116
end

ECNS -->|"Pin 1 Out (Stereo 48k clean direct)"| HOST_11
ECNS -->|"Pin 0 Out (Mono 16k clean direct)"| KPB

%% WoV 3-Slot Detector Subgraph
subgraph SLOTS ["Wake-on-Voice Keyword Detector Slots (16 kHz mono)"]
subgraph S1 ["Slot 0 (Pipeline 111)"]
M1["mixout.111.1"] --> MF1["mfcc.111.1"] --> MW1["mww.111.1"]
end
subgraph S2 ["Slot 1 (Pipeline 112)"]
M2["mixout.112.1"] --> MF2["mfcc.112.1"] --> MW2["mww.112.1"]
end
subgraph S3 ["Slot 2 (Pipeline 113)"]
M3["mixout.113.1"] --> MF3["mfcc.113.1"] --> MW3["mww.113.1"]
end
end

MIXIN_116 --> M1
MIXIN_116 --> M2
MIXIN_116 --> M3

%% Pipeline 114: WoV Arbiter & Host Capture PCM 12
subgraph P114 ["Pipeline 114: WoV Arbiter (Core 0, LL 1ms)"]
ARB["wov-arbiter.114.1<br/>• Pin 0: Drained audio stream<br/>• Pins 1-3: Keyword triggers"]
HOST_12["host-copier.12.capture<br/>(PCM 12: 'DMIC Multi-WOV'<br/>hw:0,12 · d0i3_compatible=true)"]
ARB --> HOST_12
end

KPB -->|"Pin 1 (Host Sink Drain)"| ARB
MW1 -->|"Pin 1 (Trigger 0)"| ARB
MW2 -->|"Pin 2 (Trigger 1)"| ARB
MW3 -->|"Pin 3 (Trigger 2)"| ARB

style ECNS fill:#1b4f72,stroke:#555,color:#fff
style KPB fill:#1c4966,stroke:#555,color:#fff
style ARB fill:#4a235a,stroke:#555,color:#fff
style HOST_11 fill:#1e8449,stroke:#555,color:#fff
style HOST_12 fill:#2d5a27,stroke:#555,color:#fff
DMIC16K["dai-copier.DMIC.dmic16k.capture<br/>16 kHz · 2/4ch · s32"]
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"]
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
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
`tools/topology/topology2/platform/intel/dmic-generic.conf`, without the
TDFB and DRC enhancements.

## Specifications

| Parameter | Specification |
|---|---|
| Module UUID | `6c:8a:4f:21:3a:49:1e:4b:8b:1e:0d:3b:6f:8a:2c:15` |
| Processing Domain | DP (Data Processing) thread (`lp_mode 1`) |
| Execution Period | 20 ms (320 frames at 16 kHz / 960 frames at 48 kHz) |
| Input Pin 0 | 16 kHz · 2 channels (Stereo from `dmic16k`) · `S16_LE` · IBS = 1280 bytes (20ms) |
| Input Pin 1 | 48 kHz · 2 channels (Stereo from `dmic01`) · `S16_LE` · IBS = 3840 bytes (20ms) |
| Output Pin 0 | 16 kHz · 1 channel (Mono left channel clean) · `S16_LE` · OBS = 640 bytes (20ms) |
| Output Pin 1 | 48 kHz · 2 channels (Stereo clean, 40 Hz HPF +20 dB) · `S16_LE` · OBS = 3840 bytes (20ms) |
| Sinks Acceptance | Independent sink buffer limit checks (`kpb_frames` vs `host_frames`) |
| 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 |
| Dynamic Pipeline | Compatible (`dynamic_pipeline 1`) |
| Power States | S0 active streaming and D0i3 low-power listening supported |

---

## Verification & Usage

### 1. Recording Clean Stereo Audio (Output Pin 1 / PCM 11)
Capture the continuous 48 kHz clean stereo microphone stream:
```bash
arecord -D hw:0,11 -c 2 -r 48000 -f S16_LE -d 3 /tmp/ecns_stereo_48k.wav
```

### 2. Recording Keyword Detection & History Buffer Audio (Output Pin 0 / PCM 12)
Capture the gated 16 kHz mono speech stream delivered by the WOV Arbiter upon keyword trigger:
```bash
arecord -D hw:0,12 -c 1 -r 16000 -f S16_LE -d 3 /tmp/wov_mono_16k.wav
```

---

## Further Reading
- [Topology2 Architecture & Verification Runbook](../../../tools/topology/topology2/README.md)
- [WOV Arbiter Architecture & State Machine](../wov_arbiter/README.md)
Expand Down
Loading
Loading