Skip to content
Draft
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: 3 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ endif()
if(CONFIG_COMP_DRC)
add_subdirectory(drc)
endif()
if(CONFIG_COMP_ECNS)
add_subdirectory(ecns)
endif()
if(CONFIG_COMP_FFMPEG_DEC)
add_subdirectory(ffmpeg_dec)
endif()
Expand Down
67 changes: 67 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,73 @@ config COMP_STUBS
Select to force all 3P blocks to link against stubs rather than their libraries. This
should only be used in testing environments like fuzzers or CI.

config COMP_ECNS
bool "ECNS data processing component"
default y
depends on IPC_MAJOR_4
select MATH_IIR
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.

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

endif # COMP_ECNS

config COMP_KPB
bool "KPB component"
default y
Expand Down
3 changes: 3 additions & 0 deletions src/audio/ecns/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# SPDX-License-Identifier: BSD-3-Clause

add_local_sources(sof ecns.c)
152 changes: 152 additions & 0 deletions src/audio/ecns/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
# ECNS (Echo Cancellation & Noise Suppression) Processing Module

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

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

---

## 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`) |
| 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)
- [Developer Integration Guide: Custom WOV & ECNS Algorithms](../../../doc/developer_guides/wov_ecns_integration_guide.md)
Loading
Loading