diff --git a/app/boards/intel_adsp_ace30_ptl.conf b/app/boards/intel_adsp_ace30_ptl.conf
index ca6e3130289a..536972afd6e2 100644
--- a/app/boards/intel_adsp_ace30_ptl.conf
+++ b/app/boards/intel_adsp_ace30_ptl.conf
@@ -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
diff --git a/app/boards/intel_adsp_ace30_wcl.conf b/app/boards/intel_adsp_ace30_wcl.conf
index 89805dc7dc74..3fa050817d3a 100644
--- a/app/boards/intel_adsp_ace30_wcl.conf
+++ b/app/boards/intel_adsp_ace30_wcl.conf
@@ -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
diff --git a/app/boards/intel_adsp_ace40_nvl.conf b/app/boards/intel_adsp_ace40_nvl.conf
index e12395f53385..336f19561acd 100644
--- a/app/boards/intel_adsp_ace40_nvl.conf
+++ b/app/boards/intel_adsp_ace40_nvl.conf
@@ -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
diff --git a/app/boards/intel_adsp_cavs25.conf b/app/boards/intel_adsp_cavs25.conf
index bd653610bbac..000f512f7c44 100644
--- a/app/boards/intel_adsp_cavs25.conf
+++ b/app/boards/intel_adsp_cavs25.conf
@@ -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
diff --git a/build/sof-ptl-dmic-wov-multi-4ch.tplg b/build/sof-ptl-dmic-wov-multi-4ch.tplg
deleted file mode 100644
index 550a0a376ac4..000000000000
Binary files a/build/sof-ptl-dmic-wov-multi-4ch.tplg and /dev/null differ
diff --git a/build/sof-tgl-dmic-wov-multi-4ch.tplg b/build/sof-tgl-dmic-wov-multi-4ch.tplg
deleted file mode 100644
index 5c4b5790f076..000000000000
Binary files a/build/sof-tgl-dmic-wov-multi-4ch.tplg and /dev/null differ
diff --git a/build/sof-wcl-dmic-wov-multi-4ch.tplg b/build/sof-wcl-dmic-wov-multi-4ch.tplg
deleted file mode 100644
index 550a0a376ac4..000000000000
Binary files a/build/sof-wcl-dmic-wov-multi-4ch.tplg and /dev/null differ
diff --git a/doc/developer_guides/wov_ecns_integration_guide.md b/doc/developer_guides/wov_ecns_integration_guide.md
index e4bddfac24c7..91cfe8e7aced 100644
--- a/doc/developer_guides/wov_ecns_integration_guide.md
+++ b/doc/developer_guides/wov_ecns_integration_guide.md
@@ -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 4-channel 16 kHz microphone and echo reference data directly from the DMIC DAI 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.120.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
@@ -30,74 +30,80 @@ flowchart TD
%% Hardware PDM Interfaces
subgraph PDM_INTERFACES ["Digital Microphone Interfaces (2 Separate PDM DAIs)"]
direction LR
- PDM_48K["PDM Interface: dmic01
DAI Index: 0 (PDM0)
Rate: 48 kHz · 2ch Stereo · 16-bit"]
- PDM_16K["PDM Interface: dmic16k
DAI Index: 1 (PDM1)
Rate: 16 kHz · 2ch Stereo · 16-bit"]
+ PDM_48K["PDM Interface: dmic01
DAI Index: 0 (PDM0)
Rate: 48 kHz · 2/4ch · 32-bit"]
+ PDM_16K["PDM Interface: dmic16k
DAI Index: 1 (PDM1)
Rate: 16 kHz · 2/4ch · 32-bit"]
end
- %% Pipeline 110: 48 kHz DAI Capture
- subgraph P110 ["Pipeline 110: 48 kHz DAI Ingest (Core 0, LL 1ms)"]
- DAI_48K["dai-copier.DMIC.dmic01.capture
(48 kHz · 2ch · S16_LE)"]
- MIXIN_110["mixin.110.1
(48 kHz · 2ch)"]
- DAI_48K --> MIXIN_110
+ %% Pipeline 101: 48 kHz regular DMIC0 DAI capture (SoundWire IDs)
+ subgraph P101 ["Pipeline 101: 48 kHz DMIC0 DAI Ingest (Core 0, LL 1ms)"]
+ DAI_48K["dai-copier.DMIC.dmic01.capture
(48 kHz · 2/4ch · S32_LE)"]
+ GAIN_101["gain.101.1
(Dmic0 Capture Volume / Switch)"]
+ IIR_101["eqiir.101.1
(DMIC0_DAI_EQIIR, 40 Hz high-pass)"]
+ MCP_101["module-copier.101.2"]
+ DAI_48K --> GAIN_101 --> IIR_101 --> MCP_101
end
%% Pipeline 119: 16 kHz DAI Capture
subgraph P119 ["Pipeline 119: 16 kHz DAI Ingest (Core 0, LL 1ms)"]
- DAI_16K["dai-copier.DMIC.dmic16k.capture
(16 kHz · 2ch · S16_LE)"]
- MIXIN_119["mixin.119.1
(16 kHz · 2ch)"]
- DAI_16K --> MIXIN_119
+ DAI_16K["dai-copier.DMIC.dmic16k.capture
(16 kHz · 2/4ch · S32_LE)"]
end
PDM_48K --> DAI_48K
PDM_16K --> DAI_16K
- %% Pipeline 115: Dual-Rate ECNS DP Pipeline
- subgraph P115 ["Pipeline 115: ECNS Processing (Core 0, DP 20ms, lp_mode 1)"]
- direction TB
-
- MIXOUT_115_2["mixout.115.2
(Pin 0 In: 16 kHz · 2ch stereo)"]
- MIXOUT_115_1["mixout.115.1
(Pin 1 In: 48 kHz · 2ch stereo)"]
-
- ECNS["ecns.115.1 (Custom ECNS DP Module · 20ms Period)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Pin 0 In: 16 kHz, 2ch (IBS 1280 bytes)
Pin 1 In: 48 kHz, 2ch (IBS 3840 bytes)
─────────────────────────────────
Processing:
• Pin 0: Extract Left Ch → 16k Mono Clean
• Pin 1: 1-to-1 Stereo Copy → 48k Stereo Clean
─────────────────────────────────
Pin 0 Out: 16 kHz, 1ch mono (OBS 640 bytes)
Pin 1 Out: 48 kHz, 2ch stereo (OBS 3840 bytes)"]
+ %% Pipeline 120: Speaker echo reference
+ SPK["Speaker playback
(module-copier + loopback DAI,
per platform)"]
+ subgraph P120 ["Pipeline 120: Speaker Echo Reference (Core 0, LL 1ms)"]
+ SIGGEN["siggen.120.1
(48 kHz · 2ch · passthrough,
silence when speaker is idle)"]
+ SRC_120["src.120.1
(48 kHz → 16 kHz · 2ch · S32_LE)"]
+ SIGGEN --> SRC_120
+ end
+ SPK --> SIGGEN
- MIXOUT_115_2 -->|"Pin 0 In (16k)"| ECNS
- MIXOUT_115_1 -->|"Pin 1 In (48k)"| ECNS
+ %% Pipeline 115: ECNS DP Pipeline
+ subgraph P115 ["Pipeline 115: ECNS Processing (Core 0, DP 20ms, lp_mode 1)"]
+ ECNS["ecns.115.1 (Custom ECNS DP Module · 20ms Period)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Pin 0 In: 16 kHz mic, 2/4ch s32 (IBS 2560 bytes)
Pin 1 In: 16 kHz echo ref, 2ch s32 (IBS 2560 bytes)
─────────────────────────────────
Processing (reference ecns.c):
• Mic channel enum: average or MicN
• 100 Hz HPF (boost +30 dB / 0 dB)
• AEC switch: subtract (L+R)/2 of ref
• NS switch: no function yet
─────────────────────────────────
Pin 0 Out: 16 kHz, 1ch mono (OBS 640 bytes)"]
end
- MIXIN_119 --> MIXOUT_115_2
- MIXIN_110 --> MIXOUT_115_1
+ DAI_16K -->|"Pin 0 In (16k mic)"| ECNS
+ SRC_120 -->|"Pin 1 In (16k echo ref)"| ECNS
- %% Pipeline 117: Host Capture PCM 11
- subgraph P117 ["Pipeline 117: ECNS Clean Host Capture (Core 0, LL 1ms)"]
- HOST_11["host-copier.11.capture
(PCM 11: hw:0,11)
2ch Stereo Clean Speech
capture_compatible_d0i3: true"]
+ %% Pipeline 100: Host Capture PCM 10 (regular DMIC0, SoundWire IDs)
+ subgraph P100 ["Pipeline 100: DMIC0 Host Capture (Core 0, LL 1ms)"]
+ HOST_10["host-copier.10.capture
(PCM 10 'DMIC Raw': hw:0,10)
2/4ch 48 kHz DMIC, no ECNS"]
end
+ MCP_101 --> HOST_10
+
%% Pipeline 116: KPB History Buffer
- subgraph P116 ["Pipeline 116: KPB History Buffer (Core 0, DP 20ms)"]
+ subgraph P116 ["Pipeline 116: KPB History Buffer (Core 0, LL 1ms)"]
KPB["kpb.116.1
(2.0s mono circular history = 64 KB)"]
- MIXIN_116["mixin.116.1
(Fan-out Bus)"]
- KPB -->|"Pin 0 (Live Feed)"| MIXIN_116
end
- ECNS -->|"Pin 1 (Stereo 48k clean direct)"| HOST_11
- ECNS -->|"Pin 0 (Mono 16k clean direct)"| KPB
+ %% Pipeline 118: Detector fanout
+ subgraph P118 ["Pipeline 118: Detector Fanout (Core 0, LL 1ms)"]
+ FANOUT["module-copier.118.1
(Fan-out)"]
+ end
+ KPB -->|"Pin 0 (Live Feed)"| FANOUT
+
+ ECNS -->|"Pin 0 Out (Mono 16k)"| KPB
%% WOV Keyword Spotter Slots
subgraph WOV_Slots ["Pipelines 111–113: Concurrent WOV Keyword Spotters (Core 0, DP 10ms)"]
subgraph Slot0 ["Slot 0 (Pipeline 111)"]
- M1["mixout.111.1"] --> FE0["Feature Extract
(MFCC)"] --> WOV0["WOV Engine 0
(e.g. Strawberry)"]
+ M1["module-copier.111.1"] --> FE0["Feature Extract
(MFCC)"] --> WOV0["WOV Engine 0
(e.g. Strawberry)"]
end
subgraph Slot1 ["Slot 1 (Pipeline 112)"]
- M2["mixout.112.1"] --> FE1["Feature Extract
(MFCC)"] --> WOV1["WOV Engine 1
(e.g. Hi Intel)"]
+ M2["module-copier.112.1"] --> FE1["Feature Extract
(MFCC)"] --> WOV1["WOV Engine 1
(e.g. Hi Intel)"]
end
subgraph Slot2 ["Slot 2 (Pipeline 113)"]
- M3["mixout.113.1"] --> FE2["Feature Extract
(MFCC)"] --> WOV2["WOV Engine 2
(e.g. Orange)"]
+ M3["module-copier.113.1"] --> FE2["Feature Extract
(MFCC)"] --> WOV2["WOV Engine 2
(e.g. Orange)"]
end
end
- MIXIN_116 --> M1
- MIXIN_116 --> M2
- MIXIN_116 --> M3
+ FANOUT --> M1
+ FANOUT --> M2
+ FANOUT --> M3
%% Pipeline 114: WOV Arbiter & Host Capture PCM 12
subgraph P114 ["Pipeline 114: WOV Arbiter & Capture (Core 0, LL 1ms)"]
@@ -114,7 +120,7 @@ flowchart TD
style ECNS fill:#1b4f72,stroke:#5dade2,color:#fff
style KPB fill:#1c4966,stroke:#5dade2,color:#fff
style ARB fill:#4a235a,stroke:#bb8fce,color:#fff
- style HOST_11 fill:#1e8449,stroke:#58d68d,color:#fff
+ style HOST_10 fill:#1e8449,stroke:#58d68d,color:#fff
style HOST_12 fill:#2d5a27,stroke:#58d68d,color:#fff
```
@@ -122,20 +128,26 @@ flowchart TD
## 2. Developing a Custom ECNS Module
-An ECNS component acts as a multi-sink Data Processing (DP) block. It consumes interleaved multi-channel input (speech + echo reference) and emits cleaned audio on two independent output pins.
+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.
### Audio Data Interface Contract
-- **Input Pin 0 (Source)**:
- - Channels: 4 (Ch 0,1: Near-end mic inputs; Ch 2,3: Far-end playback echo references).
+- **Input Pin 0 (Source 0 — Microphones)**:
+ - Channels: 2 or 4 near-end microphones (`DMIC_WOV_DAI_CHANNELS`), from `dai-copier.DMIC.dmic16k.capture`.
+ - Rate: 16,000 Hz.
+ - 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`).
- Rate: 16,000 Hz.
- - Sample Format: `S16_LE` (or `S32_LE` if configured).
- - Frame Period: 20 ms (320 samples per channel = 2,560 bytes per period).
+ - Sample Format: `S32_LE`.
+ - Frame Period: 20 ms (320 frames = 2,560 bytes).
- **Output Pin 0 (Sink 0 — Clean Voice to KPB / WOV)**:
- - Channels: 1 (Mono beamformed / echo-canceled speech).
- - Frame Period: 20 ms (320 samples = 640 bytes).
-- **Output Pin 1 (Sink 1 — Clean Voice to Host)**:
- - Channels: 2 (Stereo speech capture for host applications).
- - Frame Period: 20 ms (640 samples = 1,280 bytes).
+ - Channels: 1 (Mono echo-canceled speech).
+ - Rate: 16,000 Hz.
+ - Sample Format: `S16_LE` in the topology; the reference firmware follows the KPB input bit depth (16 or 32).
+ - Frame Period: 20 ms (320 samples = 640 bytes at 16-bit).
+
+There is no second output pin; the 48 kHz host capture is the regular DMIC0 capture of `dmic-generic.conf` from `dmic01` (SoundWire: `gain.101.1` -> `eqiir.101.1` -> PCM 10, HDA generic: PCM 6, ADL rt5682: PCM 99).
### C Implementation Skeleton (`src/audio/ecns/custom_ecns.c`)
@@ -144,10 +156,14 @@ An ECNS component acts as a multi-sink Data Processing (DP) block. It consumes i
#include
#include
+#define ECNS_MIC_BYTES 2560 // 20 ms @ 16 kHz 4ch s16 or 2ch s32
+#define ECNS_REF_BYTES 2560 // 20 ms @ 16 kHz 2ch s32
+#define ECNS_OUT_BYTES 640 // 20 ms @ 16 kHz 1ch s16
+
struct custom_ecns_data {
- uint32_t period_bytes_in;
- uint32_t period_bytes_out0; // Mono clean
- uint32_t period_bytes_out1; // Stereo clean
+ uint32_t period_bytes_mic; // Pin 0 in: microphones
+ uint32_t period_bytes_ref; // Pin 1 in: speaker echo reference
+ uint32_t period_bytes_out; // Pin 0 out: mono clean
void *algo_state; // Vendor algorithm state handle
};
@@ -167,44 +183,39 @@ static int custom_ecns_process(struct processing_module *mod,
struct sof_sink **sinks, int num_of_sinks)
{
struct custom_ecns_data *cd = module_get_private_data(mod);
- const int16_t *src_buf;
- int16_t *sink0_buf = NULL;
- int16_t *sink1_buf = NULL;
- size_t in_avail, out0_free, out1_free;
+ const void *mic_buf;
+ const void *ref_buf = NULL;
+ void *out_buf;
int ret;
- // 1. Check input buffer availability (20 ms @ 16kHz 4ch = 2560 bytes)
- in_avail = source_get_data_available(sources[0]);
- if (in_avail < 2560)
+ // 1. Check microphone input availability (Pin 0). A real module should
+ // map sources to pins by the IPC4 queue ID instead of the array index.
+ if (source_get_data_available(sources[0]) < ECNS_MIC_BYTES)
return 0;
- // 2. Check independent output buffer space
- out0_free = (num_of_sinks > 0 && sinks[0]) ? sink_get_free_size(sinks[0]) : 0;
- out1_free = (num_of_sinks > 1 && sinks[1]) ? sink_get_free_size(sinks[1]) : 0;
-
- // Must have space on Pin 0 (KPB path) if connected
- if (sinks[0] && out0_free < 640)
+ // 2. Check output space on Pin 0 (KPB path)
+ if (sink_get_free_size(sinks[0]) < ECNS_OUT_BYTES)
return 0;
- // 3. Acquire buffer pointers
- source_get_data(sources[0], 2560, (const void **)&src_buf, NULL, NULL);
- if (sinks[0])
- sink_get_buffer(sinks[0], 640, (void **)&sink0_buf, NULL, NULL);
- if (sinks[1] && out1_free >= 1280)
- sink_get_buffer(sinks[1], 1280, (void **)&sink1_buf, NULL, NULL);
+ // 3. Acquire buffer pointers. The echo reference (Pin 1) is consumed
+ // when available; process without it if it has not arrived.
+ source_get_data(sources[0], ECNS_MIC_BYTES, &mic_buf, NULL, NULL);
+ if (num_of_sources > 1 &&
+ source_get_data_available(sources[1]) >= ECNS_REF_BYTES)
+ source_get_data(sources[1], ECNS_REF_BYTES, &ref_buf, NULL, NULL);
+ sink_get_buffer(sinks[0], ECNS_OUT_BYTES, &out_buf, NULL, NULL);
// 4. Run Vendor DSP AEC + NR Algorithm
- // - Consumes src_buf (4ch: 0,1 mic, 2,3 ref)
- // - Writes 1ch mono clean speech to sink0_buf
- // - Writes 2ch stereo clean speech to sink1_buf (if active)
- vendor_aec_nr_process(cd->algo_state, src_buf, sink0_buf, sink1_buf, 320);
+ // - Consumes mic_buf (2 or 4ch microphones)
+ // - Consumes ref_buf (2ch speaker echo reference, may be NULL)
+ // - Writes 1ch mono clean speech to out_buf
+ vendor_aec_nr_process(cd->algo_state, mic_buf, ref_buf, out_buf, 320);
// 5. Commit & release buffers
- source_release_data(sources[0], 2560);
- if (sink0_buf)
- sink_commit_buffer(sinks[0], 640);
- if (sink1_buf)
- sink_commit_buffer(sinks[1], 1280);
+ source_release_data(sources[0], ECNS_MIC_BYTES);
+ if (ref_buf)
+ source_release_data(sources[1], ECNS_REF_BYTES);
+ sink_commit_buffer(sinks[0], ECNS_OUT_BYTES);
return 0;
}
@@ -299,16 +310,16 @@ static void on_wov_ctrl(void *arg, enum notify_id id, void *data)
## 4. WoV Arbiter & Multi-Slot Coordination
-The `wov_arbiter` component synchronizes multi-slot pipelines and multiplexes detected streams onto `host-copier.11`:
+The `wov_arbiter` component synchronizes multi-slot pipelines and multiplexes detected streams onto `host-copier.12`:
```mermaid
sequenceDiagram
autonumber
participant WOV0 as WOV Slot 0 (Strawberry)
participant WOV1 as WOV Slot 1 (Hi Intel)
- participant KPB as KPB (Pipeline 106)
- participant ARB as WOV Arbiter (Pipeline 104)
- participant HOST as Linux ALSA Driver (PCM 11)
+ participant KPB as KPB (Pipeline 116)
+ participant ARB as WOV Arbiter (Pipeline 114)
+ participant HOST as Linux ALSA Driver (PCM 12)
Note over WOV0,WOV1: Both slots actively running 20ms inference
WOV0->>WOV0: Keyword Match (Prob >= 0.70)
@@ -323,7 +334,7 @@ sequenceDiagram
Note over WOV1: Slot 1 pauses inference (saves DSP MIPS)
KPB->>ARB: Drains 2.0s Pre-roll audio history
- ARB->>HOST: Streams audio to /dev/snd/pcmC0D11c
+ ARB->>HOST: Streams audio to /dev/snd/pcmC0D12c
Note over ARB,HOST: Keyword phrase + post-trigger command audio streaming
```
@@ -464,7 +475,17 @@ Class.Control.enum."score_enum" {
}
```
-### Pipeline Instantiation in Manifest (`dmic-wov-multi-ptl-4ch-manifest.conf`)
+### Pipeline Instantiation in Manifest
+
+> [!NOTE]
+> The snippets below were taken from the standalone DMIC-only
+> `dmic-wov-multi-ptl-4ch-manifest.conf`, which has been removed because ECNS
+> requires a speaker echo reference input that a DMIC-only topology cannot
+> 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
+> `kpb.116.1`, without mixin/mixout widgets.
#### 1. ECNS Pipeline (Pipeline 105)
```conf
@@ -530,7 +551,7 @@ Object.Pipeline.custom-capture."101" {
```mermaid
stateDiagram-v2
[*] --> Off: Driver Boot / Card Instantiated
- Off --> Ready: PCM Open (/dev/snd/pcmC0D11c)
+ Off --> Ready: PCM Open (/dev/snd/pcmC0D12c)
Ready --> Active: arecord Started / DSP Stream Running
state Active {
@@ -574,7 +595,7 @@ Follow this step-by-step checklist to integrate your own algorithms:
### Step 1: Implement DSP Module C/C++ Code
1. Place source code under `src/audio//`.
2. Implement standard `module_interface` (`init`, `prepare`, `process`, `set_configuration`, `get_configuration`, `reset`, `free`).
-3. For ECNS, handle 4ch in, 1ch out (Pin 0), 2ch out (Pin 1).
+3. For ECNS, handle 2 or 4ch microphones in (Pin 0), 2ch speaker echo reference in (Pin 1), and 1ch out (Pin 0).
4. For WOV, implement multi-instance state isolation, 2 Hz scoring notification, and register for `NOTIFIER_ID_WOV_CTRL`.
### Step 2: Register Module UUID
@@ -585,18 +606,25 @@ Follow this step-by-step checklist to integrate your own algorithms:
### Step 3: Define Topology Components
1. Create Topology2 component definitions in `tools/topology/topology2/include/components/.conf`.
2. Reference the scoring enum in `score_enum.conf` (ensuring no `volatile` access flag).
-3. Connect widgets in the platform manifest files:
- - Panther Lake: `tools/topology/topology2/dmic-wov-multi-ptl-4ch-manifest.conf`
- - Tiger Lake: `tools/topology/topology2/dmic-wov-multi-4ch-manifest.conf`
- - Wildcat Lake: symlink to the Panther Lake topology, no separate manifest
+3. Connect widgets in the shared multi-slot WoV topology
+ `tools/topology/topology2/platform/intel/dmic-wov-multi.conf`, used e.g. by the
+ `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,
+ 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
+ of `siggen.120.1` (e.g. `alh-copier.Loopback_Virtual.25` or the SSP loopback
+ capture DAI) starts the setup of pipeline 120 with the WoV capture; HDA has
+ no such DAI and it is untested whether the kernel sets the pipeline up there.
### Step 4: Compile Topology & Firmware
-1. Build topologies with `alsatplg -p`:
+1. Build the topology via its CMake target (see `tools/topology/topology2/README.md`
+ for the direct `alsatplg -p` invocation):
```bash
- alsatplg \
- -I tools/topology/topology2 \
- -p -c tools/topology/topology2/dmic-wov-multi-ptl-4ch-manifest.conf \
- -o /tmp/sof-ptl-dmic-wov-multi-4ch.tplg
+ make -C build-tools topology2_prod_sof-ptl-rt721-4ch-wov-multi
```
2. Build firmware with Zephyr SDK GCC:
```bash
@@ -608,7 +636,7 @@ Follow this step-by-step checklist to integrate your own algorithms:
1. Copy firmware and topology to DUT:
```bash
scp build-sof-staging/sof/intel/sof-ipc4/ptl/community/sof-ptl.ri root@:/lib/firmware/intel/sof-ipc4/ptl/community/
- scp /tmp/sof-ptl-dmic-wov-multi-4ch.tplg root@:/lib/firmware/intel/sof-ipc4-tplg/
+ scp build-tools/topology/topology2/production/sof-ptl-rt721-4ch-wov-multi.tplg root@:/lib/firmware/intel/sof-ipc4-tplg/
```
2. Reload driver:
```bash
diff --git a/src/audio/Kconfig b/src/audio/Kconfig
index 766a19e4f5ce..145662429f5a 100644
--- a/src/audio/Kconfig
+++ b/src/audio/Kconfig
@@ -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
diff --git a/src/audio/ecns/README.md b/src/audio/ecns/README.md
index 48e6ca59b9c7..d2e3a74c36e7 100644
--- a/src/audio/ecns/README.md
+++ b/src/audio/ecns/README.md
@@ -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["PDM Interface: dmic01
DAI Index: 0 (PDM0)
Rate: 48 kHz · 2ch Stereo · 16-bit"]
- PDM_16K["PDM Interface: dmic16k
DAI Index: 1 (PDM1)
Rate: 16 kHz · 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
(48 kHz · 2ch · S16_LE)"]
- MIXIN_110["mixin.110.1
(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
(16 kHz · 2ch · S16_LE)"]
- MIXIN_119["mixin.119.1
(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
(Pin 0 In: 16 kHz · 2ch stereo)"]
- MIXOUT_115_1["mixout.115.1
(Pin 1 In: 48 kHz · 2ch stereo)"]
-
- ECNS["ecns.115.1 (DP Component · 20ms Period)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Pin 0 In: 16 kHz, 2ch (IBS 1280 bytes)
Pin 1 In: 48 kHz, 2ch (IBS 3840 bytes)
─────────────────────────────
Processing:
• Pin 0: Extract Left Ch → 16k Mono Clean
• Pin 1: 40 Hz HPF +20 dB → 48k Stereo Clean
─────────────────────────────
Pin 0 Out: 16 kHz, 1ch mono (OBS 640 bytes)
Pin 1 Out: 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
(PCM 11: 'DMIC ECNS Capture'
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
(2000 ms mono history = 64 KB)"]
- MIXIN_116["mixin.116.1
(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
• Pin 0: Drained audio stream
• Pins 1-3: Keyword triggers"]
- HOST_12["host-copier.12.capture
(PCM 12: 'DMIC Multi-WOV'
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
16 kHz · 2/4ch · s32"]
+ SPK["speaker playback module-copier
(e.g. module-copier.21.22)"]
+ LOOP["echo reference start DAI
(e.g. alh-copier.Loopback_Virtual.25)"]
+ SIGGEN["siggen.120.1
48 kHz stereo, silence without speaker"]
+ SRC["src.120.1
48 kHz → 16 kHz stereo s32"]
+ ECNS["ecns.115.1
mic average or channel → 100 Hz HPF → − (L+R)/2 ref"]
+ KPB["kpb.116.1
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)
diff --git a/src/audio/ecns/ecns.c b/src/audio/ecns/ecns.c
index bc61d4c17f27..c2fd2250a61f 100644
--- a/src/audio/ecns/ecns.c
+++ b/src/audio/ecns/ecns.c
@@ -3,6 +3,19 @@
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*/
+/**
+ * \file
+ * \brief ECNS (Echo Cancellation & Noise Suppression) DP component
+ *
+ * Input pin 0 receives the 16 kHz microphone stream and input pin 1 the
+ * 16 kHz echo reference. The microphone channels are averaged to mono, or a
+ * single channel is selected with the microphone channel enum control, and
+ * high-pass filtered. When the AEC switch is enabled the average of the echo
+ * reference channels is subtracted from the filtered microphone signal. The
+ * result is written as 16 kHz mono s16 or s32 to the single output pin. The
+ * echo reference is always consumed, also when the AEC switch is disabled.
+ */
+
#include
#include
#include
@@ -30,54 +43,63 @@ LOG_MODULE_REGISTER(ecns, CONFIG_SOF_LOG_LEVEL);
SOF_DEFINE_REG_UUID(ecns);
DECLARE_TR_CTX(ecns_tr, SOF_UUID(ecns_uuid), LOG_LEVEL_INFO);
-/* Determine the source-channel averaging window [start, start+cnt) used to
- * downmix the pin0 input to the mono KPB detection output. Selection is a
- * Kconfig choice; out-of-range channels fall back to all available channels.
+/**
+ * \brief Get the microphone channels used for the mono output.
+ *
+ * The selection comes from the microphone channel enum control. Value 0
+ * averages all channels, values 1..N select a single channel. A channel
+ * beyond the input channel count falls back to the average of all channels.
+ *
+ * \param[in] mic_sel Microphone channel enum control value
+ * \param[in] ch Number of microphone input channels
+ * \param[out] start First channel index to average
+ * \param[out] cnt Number of channels to average
*/
-static inline void ecns_mono_window(uint32_t ch, uint32_t *start, uint32_t *cnt)
+static inline void ecns_mono_window(uint32_t mic_sel, uint32_t ch, uint32_t *start,
+ uint32_t *cnt)
{
-#if CONFIG_ECNS_KPB_MONO_AVG_CH_1_2
- *start = 0;
- *cnt = MIN(2, ch);
-#elif CONFIG_ECNS_KPB_MONO_AVG_CH_3_4
- if (ch > 2) {
- *start = 2;
- *cnt = MIN(2, ch - 2);
+ if (mic_sel != ECNS_MIC_SEL_AVERAGE && mic_sel <= ch) {
+ *start = mic_sel - 1;
+ *cnt = 1;
} else {
*start = 0;
- *cnt = ch;
+ *cnt = ch ? ch : 1;
}
-#else /* CONFIG_ECNS_KPB_MONO_AVG_ALL */
- *start = 0;
- *cnt = ch;
-#endif
- if (*cnt == 0)
- *cnt = 1;
}
-static inline int32_t ecns_mono_s32(const int32_t *frame, uint32_t start, uint32_t cnt)
+/**
+ * \brief Average channels of one interleaved frame into a Q1.31 sample.
+ *
+ * \param[in] frame Pointer to the first sample of the frame
+ * \param[in] s32 True for 32-bit samples, false for 16-bit samples
+ * \param[in] start First channel index to average
+ * \param[in] cnt Number of channels to average, must be non-zero
+ * \return Average of the channels as Q1.31
+ */
+static inline int32_t ecns_frame_avg(const void *frame, bool s32, uint32_t start, uint32_t cnt)
{
int64_t acc = 0;
+ uint32_t c;
- for (uint32_t c = 0; c < cnt; c++)
- acc += frame[start + c];
- return (int32_t)(acc / (int32_t)cnt);
-}
+ if (s32) {
+ const int32_t *x = (const int32_t *)frame + start;
-static inline int16_t ecns_mono_s16(const int16_t *frame, uint32_t start, uint32_t cnt)
-{
- int32_t acc = 0;
+ for (c = 0; c < cnt; c++)
+ acc += x[c];
+ } else {
+ const int16_t *x = (const int16_t *)frame + start;
+
+ for (c = 0; c < cnt; c++)
+ acc += (int32_t)x[c] << 16;
+ }
- for (uint32_t c = 0; c < cnt; c++)
- acc += frame[start + c];
- return (int16_t)(acc / (int32_t)cnt);
+ return (int32_t)(acc / (int32_t)cnt);
}
#if CONFIG_ECNS_KPB_HPF
/**
* \brief 100 Hz second-order high-pass filter with +30 dB gain at 16 kHz.
*
- * Built-in coefficient set for the KPB detection path (Pin 0 mono mix).
* Converted from tools/topology/topology2/include/components/eqiir/highpass_100hz_30db_16khz.conf
* consisting of struct sof_eq_iir_header (6 words) followed by one
* struct sof_eq_iir_biquad (7 words):
@@ -100,102 +122,39 @@ static const uint32_t hp_100hz_0db_16k[13] = {
};
#endif
-#if CONFIG_ECNS_HOST_HPF
-/**
- * \brief 40 Hz second-order high-pass filters with +20 dB gain for Pin 1.
- *
- * Converted from highpass_40hz_20db_48khz.conf and highpass_40hz_20db_16khz.conf
- * in tools/topology/topology2/include/components/eqiir/ with the same layout
- * as hp_100hz_30db_16k.
- */
-static const uint32_t hp_40hz_20db_48k[13] = {
- 0x00000001, 0x00000001, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0xc078df4c, 0x7f86ae23,
- 0x1ff51b12, 0xc015c9db, 0x1ff51b12, 0xfffffffc,
- 0x00004fd0
-};
-
-static const uint32_t hp_40hz_20db_16k[13] = {
- 0x00000001, 0x00000001, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0xc167f2ba, 0x7e940dc3,
- 0x1fb8bfff, 0xc08e8003, 0x1fb8bfff, 0xfffffffc,
- 0x00004fd0
-};
-
-/**
- * \brief 40 Hz high-pass filters with 0 dB gain for Pin 1.
- *
- * From highpass_40hz_0db_48khz.conf and highpass_40hz_0db_16khz.conf.
- */
-static const uint32_t hp_40hz_0db_48k[13] = {
- 0x00000001, 0x00000001, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0xc078df4c, 0x7f86ae23,
- 0x1ff51b12, 0xc015c9db, 0x1ff51b12, 0x00000000,
- 0x00007fb2
-};
-
-static const uint32_t hp_40hz_0db_16k[13] = {
- 0x00000001, 0x00000001, 0x00000000, 0x00000000,
- 0x00000000, 0x00000000, 0xc167f2ba, 0x7e940dc3,
- 0x1fb8bfff, 0xc08e8003, 0x1fb8bfff, 0x00000000,
- 0x00007fb2
-};
-
-#define ECNS_HOST_MAX_CHANNELS 4
-#endif
-
-/* Switch control indexes, mixer."1" and mixer."2" in ecns.conf */
+/** \brief Switch control indexes, mixer."1" to mixer."3" in ecns.conf */
#define ECNS_CTRL_INDEX_CAPTURE_BOOST 0
-#define ECNS_CTRL_INDEX_TEST_SIGNAL 1
+#define ECNS_CTRL_INDEX_AEC 1
+#define ECNS_CTRL_INDEX_NS 2
+
+/** \brief Enum control indexes, enum."1" in the ECNS widget instance */
+#define ECNS_CTRL_INDEX_MIC_SEL 0
+/** \brief ECNS component private data */
struct ecns_comp_data {
- struct ipc4_base_module_cfg base_cfg;
- uint32_t sample_rate;
- uint32_t channels;
- uint32_t sample_width;
- uint32_t test_signal_enabled;
- bool capture_boost;
- bool capture_boost_req;
- uint16_t test_signal_val;
- struct iir_state_df1 hp_iir;
- int32_t *hp_delay;
-#if CONFIG_ECNS_HOST_HPF
- struct iir_state_df1 host_iir[ECNS_HOST_MAX_CHANNELS];
- int32_t *host_delay;
- int host_delay_size;
- uint32_t host_rate;
-#endif
+ struct ipc4_base_module_cfg base_cfg; /**< IPC4 base config, pin 0 input format */
+ bool capture_boost; /**< Boosted high-pass filter response in use */
+ bool capture_boost_req; /**< Boost requested by the control */
+ bool aec_enable; /**< AEC switch, subtract the echo reference */
+ bool ns_enable; /**< NS switch, no function yet */
+ uint32_t mic_sel; /**< Microphone channel, 0 average, 1..N single channel */
+ struct iir_state_df1 hp_iir; /**< Output high-pass filter state */
+ int32_t *hp_delay; /**< Output high-pass filter delay line */
};
#if CONFIG_ECNS_KPB_HPF
-static struct sof_eq_iir_header *ecns_kpb_iir_coef(struct ecns_comp_data *cd)
+static struct sof_eq_iir_header *ecns_iir_coef(struct ecns_comp_data *cd)
{
return (struct sof_eq_iir_header *)
(cd->capture_boost ? hp_100hz_30db_16k : hp_100hz_0db_16k);
}
#endif
-#if CONFIG_ECNS_HOST_HPF
-static struct sof_eq_iir_header *ecns_host_iir_coef(struct ecns_comp_data *cd)
-{
- if (cd->host_rate == 16000)
- return (struct sof_eq_iir_header *)
- (cd->capture_boost ? hp_40hz_20db_16k : hp_40hz_0db_16k);
-
- return (struct sof_eq_iir_header *)
- (cd->capture_boost ? hp_40hz_20db_48k : hp_40hz_0db_48k);
-}
-#endif
-
-/* Only the coefficient pointers move, the filter delay lines are kept. */
+/* Only the coefficient pointers move, the filter delay line is kept. */
static void ecns_update_iir_coef(struct ecns_comp_data *cd)
{
#if CONFIG_ECNS_KPB_HPF
- iir_init_coef_df1(&cd->hp_iir, ecns_kpb_iir_coef(cd));
-#endif
-#if CONFIG_ECNS_HOST_HPF
- for (int c = 0; c < ECNS_HOST_MAX_CHANNELS; c++)
- iir_init_coef_df1(&cd->host_iir[c], ecns_host_iir_coef(cd));
+ iir_init_coef_df1(&cd->hp_iir, ecns_iir_coef(cd));
#endif
}
@@ -203,11 +162,17 @@ static struct comp_dev *ecns_new(const struct comp_driver *drv,
const struct comp_ipc_config *config,
const void *spec)
{
- struct comp_dev *dev;
+ const struct ipc4_base_module_cfg *base_cfg = spec;
struct ecns_comp_data *cd;
+ struct comp_dev *dev;
comp_cl_info(drv, "ecns_new");
+ if (!base_cfg) {
+ comp_cl_err(drv, "ecns_new: no base config");
+ return NULL;
+ }
+
dev = comp_alloc(drv, sizeof(*dev));
if (!dev)
return NULL;
@@ -220,17 +185,7 @@ static struct comp_dev *ecns_new(const struct comp_driver *drv,
return NULL;
}
- const struct ipc4_base_module_cfg *base_cfg = spec;
- if (base_cfg) {
- memcpy_s(&cd->base_cfg, sizeof(cd->base_cfg), base_cfg, sizeof(*base_cfg));
- cd->sample_rate = base_cfg->audio_fmt.sampling_frequency;
- cd->channels = base_cfg->audio_fmt.channels_count;
- cd->sample_width = base_cfg->audio_fmt.valid_bit_depth;
- } else {
- cd->sample_rate = 48000;
- cd->channels = ECNS_IN_CHANNELS;
- cd->sample_width = 16;
- }
+ memcpy_s(&cd->base_cfg, sizeof(cd->base_cfg), base_cfg, sizeof(*base_cfg));
comp_set_drvdata(dev, cd);
dev->direction = SOF_IPC_STREAM_CAPTURE;
@@ -242,7 +197,7 @@ static struct comp_dev *ecns_new(const struct comp_driver *drv,
cd->capture_boost_req = true;
#if CONFIG_ECNS_KPB_HPF
- struct sof_eq_iir_header *hp_hdr = ecns_kpb_iir_coef(cd);
+ struct sof_eq_iir_header *hp_hdr = ecns_iir_coef(cd);
int hp_size = iir_delay_size_df1(hp_hdr);
int32_t *delay;
@@ -264,29 +219,10 @@ static struct comp_dev *ecns_new(const struct comp_driver *drv,
iir_init_delay_df1(&cd->hp_iir, &delay);
#endif
-#if CONFIG_ECNS_HOST_HPF
- /* The 48 kHz and 16 kHz Pin 1 filters have the same section count */
- int host_size = iir_delay_size_df1((struct sof_eq_iir_header *)hp_40hz_20db_48k);
-
- if (host_size < 0) {
- rfree(cd->hp_delay);
- rfree(cd);
- comp_free_device(dev);
- return NULL;
- }
-
- cd->host_delay_size = host_size * ECNS_HOST_MAX_CHANNELS;
- cd->host_delay = rzalloc(SOF_MEM_FLAG_USER, cd->host_delay_size);
- if (!cd->host_delay) {
- rfree(cd->hp_delay);
- rfree(cd);
- comp_free_device(dev);
- return NULL;
- }
-#endif
-
- comp_info(dev, "ecns_new: rate=%u in_ch=%u sample_width=%u",
- cd->sample_rate, cd->channels, cd->sample_width);
+ comp_info(dev, "ecns_new: rate=%u in_ch=%u valid_bits=%u",
+ base_cfg->audio_fmt.sampling_frequency,
+ base_cfg->audio_fmt.channels_count,
+ base_cfg->audio_fmt.valid_bit_depth);
return dev;
}
@@ -296,9 +232,6 @@ static void ecns_free(struct comp_dev *dev)
struct ecns_comp_data *cd = comp_get_drvdata(dev);
comp_info(dev, "ecns_free");
-#if CONFIG_ECNS_HOST_HPF
- rfree(cd->host_delay);
-#endif
rfree(cd->hp_delay);
rfree(cd);
comp_free_device(dev);
@@ -316,99 +249,59 @@ static int ecns_params(struct comp_dev *dev, struct sof_ipc_stream_params *param
return 0;
}
-#if CONFIG_ECNS_HOST_HPF
-static void ecns_host_iir_init(struct ecns_comp_data *cd, uint32_t rate)
+/**
+ * \brief Get the output sample container depth.
+ *
+ * The output format is defined in topology, but the IPC4 base config of ECNS
+ * only describes the input pin 0 format. The topology output format matches
+ * the consumer input format, so the depth is taken from the consumer base
+ * config.
+ *
+ * \param[in] dev ECNS component device
+ * \param[in] sink Output buffer
+ * \return 16 or 32
+ */
+static uint32_t ecns_out_depth(struct comp_dev *dev, struct comp_buffer *sink)
{
- struct sof_eq_iir_header *hdr;
- int32_t *delay = cd->host_delay;
-
- cd->host_rate = rate;
- hdr = ecns_host_iir_coef(cd);
- memset_s(cd->host_delay, cd->host_delay_size, 0, cd->host_delay_size);
- for (int c = 0; c < ECNS_HOST_MAX_CHANNELS; c++) {
- iir_init_coef_df1(&cd->host_iir[c], hdr);
- iir_init_delay_df1(&cd->host_iir[c], &delay);
- }
-}
+ struct comp_dev *consumer = comp_buffer_get_sink_component(sink);
+ struct ipc4_base_module_cfg cfg;
-static inline int32_t ecns_host_filter(struct ecns_comp_data *cd, uint32_t c, int32_t x)
-{
- return c < ECNS_HOST_MAX_CHANNELS ? iir_df1(&cd->host_iir[c], x) : x;
-}
-#else
-static void ecns_host_iir_init(struct ecns_comp_data *cd, uint32_t rate)
-{
-}
+ if (consumer && !comp_get_attribute(consumer, COMP_ATTR_BASE_CONFIG, &cfg) &&
+ cfg.audio_fmt.depth == 16)
+ return 16;
-static inline int32_t ecns_host_filter(struct ecns_comp_data *cd, uint32_t c, int32_t x)
-{
- return x;
+ return 32;
}
-#endif
static int ecns_prepare(struct comp_dev *dev)
{
struct ecns_comp_data *cd = comp_get_drvdata(dev);
- struct comp_buffer *src0 = NULL;
- struct comp_buffer *src1 = NULL;
- struct comp_buffer *source;
struct comp_buffer *sink;
comp_info(dev, "ecns_prepare");
- /* Output buffer formats must match the topology-declared pins:
- * pin0 -> KPB mono 16 kHz, pin1 -> host.
- * When src1 (48 kHz producer) is present, use dual-rate 16-bit formats.
- * When src1 is absent (single 16 kHz DMIC input), use 32-bit formats matching the manifest.
- */
- comp_dev_for_each_producer(dev, source) {
- uint32_t pin = IPC4_SINK_QUEUE_ID(buf_get_id(source));
-
- if (pin == ECNS_PIN_16K_IN && !src0)
- src0 = source;
- else if (pin == ECNS_PIN_48K_IN && !src1)
- src1 = source;
- }
-
- /* Pin 1 output follows the dmic01 input channel count (2 or 4) */
- uint32_t pin1_ch = 2;
-
- if (src1)
- pin1_ch = audio_stream_get_channels(&src1->stream) == 2 ? 2 : 4;
-
- struct ipc4_audio_format pin0_fmt = {
- .sampling_frequency = 16000,
- .channels_count = 1,
- .depth = src1 ? 16 : 32,
- .valid_bit_depth = src1 ? 16 : 32,
- .s_type = src1 ? IPC4_TYPE_SIGNED_INTEGER : IPC4_TYPE_MSB_INTEGER,
- .interleaving_style = IPC4_CHANNELS_INTERLEAVED,
- .ch_map = ECNS_CH_MAP_MONO,
- .ch_cfg = IPC4_CHANNEL_CONFIG_MONO,
- };
- struct ipc4_audio_format pin1_fmt = {
- .sampling_frequency = src1 ? 48000 : 16000,
- .channels_count = pin1_ch,
- .depth = src1 ? 16 : 32,
- .valid_bit_depth = src1 ? 16 : 32,
- .s_type = src1 ? IPC4_TYPE_SIGNED_INTEGER : IPC4_TYPE_MSB_INTEGER,
- .interleaving_style = IPC4_CHANNELS_INTERLEAVED,
- .ch_map = pin1_ch == 4 ? ECNS_CH_MAP_4CH : ECNS_CH_MAP_STEREO,
- .ch_cfg = pin1_ch == 4 ? IPC4_CHANNEL_CONFIG_3_POINT_1 : IPC4_CHANNEL_CONFIG_STEREO,
- };
-
comp_dev_for_each_consumer(dev, sink) {
- uint32_t pin = IPC4_SRC_QUEUE_ID(buf_get_id(sink));
+ if (IPC4_SRC_QUEUE_ID(buf_get_id(sink)) != ECNS_PIN_OUT)
+ continue;
+
+ uint32_t depth = ecns_out_depth(dev, sink);
+ struct ipc4_audio_format fmt = {
+ .sampling_frequency = ECNS_RATE,
+ .channels_count = 1,
+ .depth = depth,
+ .valid_bit_depth = depth,
+ .s_type = depth == 16 ? IPC4_TYPE_SIGNED_INTEGER : IPC4_TYPE_MSB_INTEGER,
+ .interleaving_style = IPC4_CHANNELS_INTERLEAVED,
+ .ch_map = ECNS_CH_MAP_MONO,
+ .ch_cfg = IPC4_CHANNEL_CONFIG_MONO,
+ };
- if (pin == ECNS_PIN_16K_OUT)
- ipc4_update_buffer_format(sink, &pin0_fmt);
- else if (pin == ECNS_PIN_48K_OUT)
- ipc4_update_buffer_format(sink, &pin1_fmt);
+ ipc4_update_buffer_format(sink, &fmt);
+ comp_info(dev, "ecns_prepare: output s%u", depth);
}
cd->capture_boost = cd->capture_boost_req;
ecns_update_iir_coef(cd);
- ecns_host_iir_init(cd, pin1_fmt.sampling_frequency);
return comp_set_state(dev, COMP_TRIGGER_PREPARE);
}
@@ -418,19 +311,13 @@ static int ecns_reset(struct comp_dev *dev)
struct ecns_comp_data *cd = comp_get_drvdata(dev);
comp_info(dev, "ecns_reset");
- cd->test_signal_val = 0;
#if CONFIG_ECNS_KPB_HPF
if (cd->hp_delay) {
- struct sof_eq_iir_header *hp_hdr = ecns_kpb_iir_coef(cd);
- int hp_size = iir_delay_size_df1(hp_hdr);
+ int hp_size = iir_delay_size_df1(ecns_iir_coef(cd));
if (hp_size > 0)
memset_s(cd->hp_delay, hp_size, 0, hp_size);
}
-#endif
-#if CONFIG_ECNS_HOST_HPF
- if (cd->host_delay)
- memset_s(cd->host_delay, cd->host_delay_size, 0, cd->host_delay_size);
#endif
return comp_set_state(dev, COMP_TRIGGER_RESET);
}
@@ -441,61 +328,7 @@ static int ecns_trigger(struct comp_dev *dev, int cmd)
return comp_set_state(dev, cmd);
}
-#if CONFIG_ECNS_TEST_SIGNAL
-/**
- * \brief Generate 32-bit test signal on Pin 0 (KPB)
- */
-static void ecns_kpb_test_signal_s32(struct ecns_comp_data *cd,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames)
-{
- int32_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
-
- while (remaining > 0) {
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, f_snk);
-
- for (uint32_t i = 0; i < n; i++) {
- *snk_ptr++ = ((int32_t)cd->test_signal_val++) << 16;
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- }
-
- remaining -= n;
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
-}
-
-/**
- * \brief Generate 16-bit test signal on Pin 0 (KPB)
- */
-static void ecns_kpb_test_signal_s16(struct ecns_comp_data *cd,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames)
-{
- int16_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
-
- while (remaining > 0) {
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, f_snk);
-
- for (uint32_t i = 0; i < n; i++) {
- *snk_ptr++ = (int16_t)cd->test_signal_val++;
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- }
-
- remaining -= n;
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
-}
-#endif
-
-static inline int32_t ecns_kpb_filter(struct ecns_comp_data *cd, int32_t x)
+static inline int32_t ecns_filter(struct ecns_comp_data *cd, int32_t x)
{
#if CONFIG_ECNS_KPB_HPF
return iir_df1(&cd->hp_iir, x);
@@ -504,529 +337,135 @@ static inline int32_t ecns_kpb_filter(struct ecns_comp_data *cd, int32_t x)
#endif
}
-/**
- * \brief Process 32-bit DMIC input to 32-bit KPB mono output
- */
-static void ecns_kpb_s32_to_s32(struct ecns_comp_data *cd,
- struct comp_buffer *src0,
- uint32_t src0_ch,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames,
- uint32_t avg_start,
- uint32_t avg_cnt)
-{
- int32_t *src_ptr = audio_stream_get_rptr(&src0->stream);
- int32_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
-
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&src0->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- int32_t mono = ecns_mono_s32(src_ptr, avg_start, avg_cnt);
-
- mono = ecns_kpb_filter(cd, mono);
- *snk_ptr++ = mono;
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- src_ptr += src0_ch;
- }
-
- remaining -= n;
- src_ptr = audio_stream_wrap(&src0->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
-}
+/** \brief Stream properties used by the processing loop */
+struct ecns_stream {
+ struct comp_buffer *buf; /**< Buffer, NULL if the pin is not connected */
+ uint32_t ch; /**< Number of channels */
+ uint32_t frame_bytes; /**< Bytes per frame */
+ bool s32; /**< True for 32-bit, false for 16-bit samples */
+};
-/**
- * \brief Process 16-bit DMIC input to 32-bit KPB mono output
- */
-static void ecns_kpb_s16_to_s32(struct ecns_comp_data *cd,
- struct comp_buffer *src0,
- uint32_t src0_ch,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames,
- uint32_t avg_start,
- uint32_t avg_cnt)
+static void ecns_stream_init(struct ecns_stream *s, struct comp_buffer *buf)
{
- int16_t *src_ptr = audio_stream_get_rptr(&src0->stream);
- int32_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
-
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&src0->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- int32_t mono = ((int32_t)ecns_mono_s16(src_ptr, avg_start, avg_cnt)) << 16;
-
- mono = ecns_kpb_filter(cd, mono);
- *snk_ptr++ = mono;
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- src_ptr += src0_ch;
- }
-
- remaining -= n;
- src_ptr = audio_stream_wrap(&src0->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
-}
+ uint32_t sample_bytes;
-/**
- * \brief Process 32-bit DMIC input to 16-bit KPB mono output
- */
-static void ecns_kpb_s32_to_s16(struct ecns_comp_data *cd,
- struct comp_buffer *src0,
- uint32_t src0_ch,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames,
- uint32_t avg_start,
- uint32_t avg_cnt)
-{
- int32_t *src_ptr = audio_stream_get_rptr(&src0->stream);
- int16_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
+ s->buf = buf;
+ if (!buf)
+ return;
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&src0->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- int32_t mono = ecns_mono_s32(src_ptr, avg_start, avg_cnt);
-
- mono = ecns_kpb_filter(cd, mono);
- *snk_ptr++ = sat_int16(Q_SHIFT_RND(mono, 31, 15));
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- src_ptr += src0_ch;
- }
+ s->ch = audio_stream_get_channels(&buf->stream);
+ if (!s->ch)
+ s->ch = 1;
- remaining -= n;
- src_ptr = audio_stream_wrap(&src0->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
+ sample_bytes = audio_stream_sample_bytes(&buf->stream);
+ s->s32 = sample_bytes != sizeof(int16_t);
+ s->frame_bytes = s->ch * (s->s32 ? sizeof(int32_t) : sizeof(int16_t));
}
-/**
- * \brief Process 16-bit DMIC input to 16-bit KPB mono output
- */
-static void ecns_kpb_s16_to_s16(struct ecns_comp_data *cd,
- struct comp_buffer *src0,
- uint32_t src0_ch,
- struct comp_buffer *snk0,
- uint32_t snk0_ch,
- uint32_t frames,
- uint32_t avg_start,
- uint32_t avg_cnt)
+static uint32_t ecns_avail_frames(const struct ecns_stream *s)
{
- int16_t *src_ptr = audio_stream_get_rptr(&src0->stream);
- int16_t *snk_ptr = audio_stream_get_wptr(&snk0->stream);
- uint32_t remaining = frames;
-
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&src0->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk0->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- int32_t mono = ((int32_t)ecns_mono_s16(src_ptr, avg_start, avg_cnt)) << 16;
-
- mono = ecns_kpb_filter(cd, mono);
- *snk_ptr++ = sat_int16(Q_SHIFT_RND(mono, 31, 15));
- for (uint32_t c = 1; c < snk0_ch; c++)
- *snk_ptr++ = 0;
- src_ptr += src0_ch;
- }
-
- remaining -= n;
- src_ptr = audio_stream_wrap(&src0->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk0->stream, snk_ptr);
- }
+ return s->buf ? audio_stream_get_avail_bytes(&s->buf->stream) / s->frame_bytes : 0;
}
/**
- * \brief Process Pin 0: 16 kHz detection stream -> Mono clean to KPB
- *
- * Averages selected source channels into a mono stream, filters with the
- * built-in 100 Hz HPF (+30 dB gain, CONFIG_ECNS_KPB_HPF), and writes to the sink buffer (either
- * 16-bit or 32-bit container). Supports test signal generation when enabled.
+ * \brief Process microphone and echo reference frames to the output.
*
- * \param[in,out] cd ECNS component data
- * \param[in] src0 Input buffer from 16 kHz DMIC
- * \param[in,out] snk0 Output buffer to KPB
- * \return Number of frames produced to snk0
+ * \param[in,out] cd ECNS component data
+ * \param[in] mic Microphone input stream
+ * \param[in] ref Echo reference input stream, buffer may be NULL
+ * \param[in,out] out Output stream
+ * \param[in] frames Number of frames to process
+ * \param[in] ref_frames Number of available echo reference frames. The
+ * frames after these are processed as if the
+ * reference was zero.
*/
-static uint32_t ecns_process_kpb(struct ecns_comp_data *cd,
- struct comp_buffer *src0,
- struct comp_buffer *snk0)
-{
- uint32_t src0_ch = audio_stream_get_channels(&src0->stream);
- if (!src0_ch)
- src0_ch = 4;
- uint32_t src_sample_bytes = audio_stream_sample_bytes(&src0->stream);
- if (!src_sample_bytes)
- src_sample_bytes = sizeof(int32_t);
- uint32_t src0_frame_bytes = src0_ch * src_sample_bytes;
- uint32_t avail0_bytes = audio_stream_get_avail_bytes(&src0->stream);
- uint32_t avail0_frames = avail0_bytes / src0_frame_bytes;
-
- uint32_t snk0_ch = audio_stream_get_channels(&snk0->stream);
- if (!snk0_ch)
- snk0_ch = 1;
- uint32_t snk_sample_bytes0 = audio_stream_sample_bytes(&snk0->stream);
- if (!snk_sample_bytes0)
- snk_sample_bytes0 = sizeof(int32_t);
- uint32_t snk0_frame_bytes = snk0_ch * snk_sample_bytes0;
- uint32_t free0_bytes = audio_stream_get_free_bytes(&snk0->stream);
- uint32_t free0_frames = free0_bytes / snk0_frame_bytes;
-
- /* Drain all available input bounded by sink space; a one-period cap
- * would let the source ring overflow under DMIC vs DSP clock drift.
- */
- uint32_t frames0 = MIN(avail0_frames, free0_frames);
- if (!frames0)
- return 0;
-
- uint32_t src_bytes = frames0 * src0_frame_bytes;
- uint32_t snk_bytes = frames0 * snk0_frame_bytes;
-
- buffer_stream_invalidate(src0, src_bytes);
-
+static void ecns_process(struct ecns_comp_data *cd, const struct ecns_stream *mic,
+ const struct ecns_stream *ref, const struct ecns_stream *out,
+ uint32_t frames, uint32_t ref_frames)
+{
+ uint8_t *mic_ptr = audio_stream_get_rptr(&mic->buf->stream);
+ uint8_t *out_ptr = audio_stream_get_wptr(&out->buf->stream);
+ uint8_t *ref_ptr = ref_frames ? audio_stream_get_rptr(&ref->buf->stream) : NULL;
+ uint32_t mic_sample_bytes = mic->s32 ? sizeof(int32_t) : sizeof(int16_t);
uint32_t avg_start, avg_cnt;
-
- ecns_mono_window(src0_ch, &avg_start, &avg_cnt);
-
-#if CONFIG_ECNS_TEST_SIGNAL
- if (cd->test_signal_enabled) {
- if (snk_sample_bytes0 == sizeof(int32_t))
- ecns_kpb_test_signal_s32(cd, snk0, snk0_ch, frames0);
- else
- ecns_kpb_test_signal_s16(cd, snk0, snk0_ch, frames0);
- } else
-#endif
- if (snk_sample_bytes0 == sizeof(int32_t)) {
- if (src_sample_bytes == sizeof(int32_t))
- ecns_kpb_s32_to_s32(cd, src0, src0_ch, snk0, snk0_ch, frames0,
- avg_start, avg_cnt);
- else
- ecns_kpb_s16_to_s32(cd, src0, src0_ch, snk0, snk0_ch, frames0,
- avg_start, avg_cnt);
- } else {
- if (src_sample_bytes == sizeof(int32_t))
- ecns_kpb_s32_to_s16(cd, src0, src0_ch, snk0, snk0_ch, frames0,
- avg_start, avg_cnt);
- else
- ecns_kpb_s16_to_s16(cd, src0, src0_ch, snk0, snk0_ch, frames0,
- avg_start, avg_cnt);
- }
-
- buffer_stream_writeback(snk0, snk_bytes);
- comp_update_buffer_produce(snk0, snk_bytes);
-
- return frames0;
-}
-
-/**
- * \brief Filter 32-bit input to 32-bit host capture sink
- */
-static void ecns_host_s32_to_s32(struct ecns_comp_data *cd,
- struct comp_buffer *in1,
- uint32_t in1_ch,
- struct comp_buffer *snk1,
- uint32_t snk1_ch,
- uint32_t frames)
-{
- int32_t *src_ptr = audio_stream_get_rptr(&in1->stream);
- int32_t *snk_ptr = audio_stream_get_wptr(&snk1->stream);
uint32_t remaining = frames;
+ uint32_t i, n;
+ int32_t y;
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&in1->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk1->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- for (uint32_t c = 0; c < snk1_ch; c++)
- snk_ptr[c] = (c < in1_ch) ? ecns_host_filter(cd, c, src_ptr[c]) : 0;
- snk_ptr += snk1_ch;
- src_ptr += in1_ch;
- }
-
- remaining -= n;
- src_ptr = audio_stream_wrap(&in1->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk1->stream, snk_ptr);
- }
-}
-
-/**
- * \brief Filter 16-bit input to 32-bit host capture sink
- */
-static void ecns_host_s16_to_s32(struct ecns_comp_data *cd,
- struct comp_buffer *in1,
- uint32_t in1_ch,
- struct comp_buffer *snk1,
- uint32_t snk1_ch,
- uint32_t frames)
-{
- int16_t *src_ptr = audio_stream_get_rptr(&in1->stream);
- int32_t *snk_ptr = audio_stream_get_wptr(&snk1->stream);
- uint32_t remaining = frames;
+ ecns_mono_window(cd->mic_sel, mic->ch, &avg_start, &avg_cnt);
while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&in1->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk1->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- for (uint32_t c = 0; c < snk1_ch; c++)
- snk_ptr[c] = (c < in1_ch) ?
- ecns_host_filter(cd, c, ((int32_t)src_ptr[c]) << 16) : 0;
- snk_ptr += snk1_ch;
- src_ptr += in1_ch;
+ n = MIN(remaining, audio_stream_frames_without_wrap(&mic->buf->stream, mic_ptr));
+ n = MIN(n, audio_stream_frames_without_wrap(&out->buf->stream, out_ptr));
+ if (ref_frames) {
+ n = MIN(n, ref_frames);
+ n = MIN(n, audio_stream_frames_without_wrap(&ref->buf->stream, ref_ptr));
}
- remaining -= n;
- src_ptr = audio_stream_wrap(&in1->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk1->stream, snk_ptr);
- }
-}
+ for (i = 0; i < n; i++) {
+ y = ecns_filter(cd, ecns_frame_avg(mic_ptr, mic->s32, avg_start, avg_cnt));
+ mic_ptr += mic->ch * mic_sample_bytes;
-/**
- * \brief Filter 32-bit input to 16-bit host capture sink
- */
-static void ecns_host_s32_to_s16(struct ecns_comp_data *cd,
- struct comp_buffer *in1,
- uint32_t in1_ch,
- struct comp_buffer *snk1,
- uint32_t snk1_ch,
- uint32_t frames)
-{
- int32_t *src_ptr = audio_stream_get_rptr(&in1->stream);
- int16_t *snk_ptr = audio_stream_get_wptr(&snk1->stream);
- uint32_t remaining = frames;
+ if (ref_frames) {
+ if (cd->aec_enable)
+ y = sat_int32((int64_t)y -
+ ecns_frame_avg(ref_ptr, ref->s32, 0, ref->ch));
+ ref_ptr += ref->frame_bytes;
+ }
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&in1->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk1->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- for (uint32_t c = 0; c < snk1_ch; c++)
- snk_ptr[c] = (c < in1_ch) ?
- sat_int16(Q_SHIFT_RND(ecns_host_filter(cd, c, src_ptr[c]),
- 31, 15)) : 0;
- snk_ptr += snk1_ch;
- src_ptr += in1_ch;
- }
+ if (out->s32) {
+ int32_t *o = (int32_t *)out_ptr;
- remaining -= n;
- src_ptr = audio_stream_wrap(&in1->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk1->stream, snk_ptr);
- }
-}
-
-/**
- * \brief Filter 16-bit input to 16-bit host capture sink
- */
-static void ecns_host_s16_to_s16(struct ecns_comp_data *cd,
- struct comp_buffer *in1,
- uint32_t in1_ch,
- struct comp_buffer *snk1,
- uint32_t snk1_ch,
- uint32_t frames)
-{
- int16_t *src_ptr = audio_stream_get_rptr(&in1->stream);
- int16_t *snk_ptr = audio_stream_get_wptr(&snk1->stream);
- uint32_t remaining = frames;
+ o[0] = y;
+ for (uint32_t c = 1; c < out->ch; c++)
+ o[c] = 0;
+ } else {
+ int16_t *o = (int16_t *)out_ptr;
- while (remaining > 0) {
- uint32_t f_src = audio_stream_frames_without_wrap(&in1->stream, src_ptr);
- uint32_t f_snk = audio_stream_frames_without_wrap(&snk1->stream, snk_ptr);
- uint32_t n = MIN(remaining, MIN(f_src, f_snk));
-
- for (uint32_t i = 0; i < n; i++) {
- for (uint32_t c = 0; c < snk1_ch; c++)
- snk_ptr[c] = (c < in1_ch) ?
- sat_int16(Q_SHIFT_RND(ecns_host_filter(cd, c,
- ((int32_t)src_ptr[c]) << 16),
- 31, 15)) : 0;
- snk_ptr += snk1_ch;
- src_ptr += in1_ch;
+ o[0] = sat_int16(Q_SHIFT_RND(y, 31, 15));
+ for (uint32_t c = 1; c < out->ch; c++)
+ o[c] = 0;
+ }
+ out_ptr += out->frame_bytes;
}
remaining -= n;
- src_ptr = audio_stream_wrap(&in1->stream, src_ptr);
- snk_ptr = audio_stream_wrap(&snk1->stream, snk_ptr);
- }
-}
-
-/**
- * \brief Process Pin 1: 48 kHz host capture stream
- *
- * Filters the audio from the input producer (48 kHz dmic01 or fallback
- * src0) with the built-in 40 Hz HPF (+20 dB gain) per channel and writes
- * it to the host sink buffer (supporting s16 or s32).
- *
- * \param[in,out] cd ECNS component data
- * \param[in] in1 Input buffer
- * \param[in,out] snk1 Output buffer to host
- * \return Number of frames produced to snk1
- */
-static uint32_t ecns_process_host(struct ecns_comp_data *cd,
- struct comp_buffer *in1,
- struct comp_buffer *snk1)
-{
- uint32_t in1_ch = audio_stream_get_channels(&in1->stream);
- if (!in1_ch)
- in1_ch = 2;
- uint32_t in1_sample_bytes = audio_stream_sample_bytes(&in1->stream);
- if (!in1_sample_bytes)
- in1_sample_bytes = sizeof(int32_t);
- uint32_t in1_frame_bytes = in1_ch * in1_sample_bytes;
- uint32_t avail1_bytes = audio_stream_get_avail_bytes(&in1->stream);
- uint32_t avail1_frames = avail1_bytes / in1_frame_bytes;
-
- uint32_t snk1_ch = audio_stream_get_channels(&snk1->stream);
- if (!snk1_ch)
- snk1_ch = 2;
- uint32_t snk_sample_bytes1 = audio_stream_sample_bytes(&snk1->stream);
- if (!snk_sample_bytes1)
- snk_sample_bytes1 = sizeof(int32_t);
- uint32_t snk1_frame_bytes = snk1_ch * snk_sample_bytes1;
- uint32_t free1_bytes = audio_stream_get_free_bytes(&snk1->stream);
- uint32_t free1_frames = free1_bytes / snk1_frame_bytes;
-
- /* Drain all available input bounded by sink space; a one-period cap
- * would let the source ring overflow under DMIC vs DSP clock drift.
- */
- uint32_t frames1 = MIN(avail1_frames, free1_frames);
- if (!frames1)
- return 0;
-
- uint32_t in1_bytes = frames1 * in1_frame_bytes;
- uint32_t snk_bytes = frames1 * snk1_frame_bytes;
-
- buffer_stream_invalidate(in1, in1_bytes);
-
- if (snk_sample_bytes1 == sizeof(int32_t)) {
- if (in1_sample_bytes == sizeof(int32_t))
- ecns_host_s32_to_s32(cd, in1, in1_ch, snk1, snk1_ch, frames1);
- else
- ecns_host_s16_to_s32(cd, in1, in1_ch, snk1, snk1_ch, frames1);
- } else {
- if (in1_sample_bytes == sizeof(int32_t))
- ecns_host_s32_to_s16(cd, in1, in1_ch, snk1, snk1_ch, frames1);
- else
- ecns_host_s16_to_s16(cd, in1, in1_ch, snk1, snk1_ch, frames1);
+ mic_ptr = audio_stream_wrap(&mic->buf->stream, mic_ptr);
+ out_ptr = audio_stream_wrap(&out->buf->stream, out_ptr);
+ if (ref_frames) {
+ ref_frames -= n;
+ ref_ptr = ref_frames ? audio_stream_wrap(&ref->buf->stream, ref_ptr) : NULL;
+ }
}
-
- buffer_stream_writeback(snk1, snk_bytes);
- comp_update_buffer_produce(snk1, snk_bytes);
-
- return frames1;
}
-/**
- * \brief Consume from ECNS source buffers and drain inactive inputs
- *
- * Updates consumption for produced audio frames and drains unconsumed
- * input data when downstream consumer sinks are inactive or full to
- * prevent upstream DAI FIFO overruns.
- *
- * \param[in,out] src0 16 kHz input buffer
- * \param[in,out] src1 48 kHz input buffer
- * \param[in] snk0 Pin 0 (KPB) output buffer
- * \param[in] snk1 Pin 1 (Host) output buffer
- * \param[in] frames0_produced Frames produced to snk0
- * \param[in] frames1_produced Frames produced to snk1
- */
-static void ecns_consume_sources(struct comp_buffer *src0,
- struct comp_buffer *src1,
- struct comp_buffer *snk0,
- struct comp_buffer *snk1,
- uint32_t frames0_produced,
- uint32_t frames1_produced)
+/** \brief Drop all complete frames from an input stream. */
+static void ecns_drain(const struct ecns_stream *s)
{
- uint32_t snk0_free = snk0 ? audio_stream_get_free_bytes(&snk0->stream) : 0;
- uint32_t snk1_free = snk1 ? audio_stream_get_free_bytes(&snk1->stream) : 0;
-
- if (src1) {
- uint32_t src1_ch = audio_stream_get_channels(&src1->stream);
- if (!src1_ch)
- src1_ch = 4;
- uint32_t src1_sb = audio_stream_sample_bytes(&src1->stream);
- if (!src1_sb)
- src1_sb = sizeof(int32_t);
- uint32_t src1_fb = src1_ch * src1_sb;
-
- if (frames1_produced > 0) {
- comp_update_buffer_consume(src1, frames1_produced * src1_fb);
- } else if (!snk1 || comp_buffer_get_sink_state(snk1) != COMP_STATE_ACTIVE || !snk1_free) {
- uint32_t avail = audio_stream_get_avail_bytes(&src1->stream);
-
- if (src1_fb && avail >= src1_fb) {
- avail = ROUND_DOWN(avail, src1_fb);
- comp_update_buffer_consume(src1, avail);
- }
- }
- }
+ uint32_t frames = ecns_avail_frames(s);
- if (src0) {
- uint32_t src0_ch = audio_stream_get_channels(&src0->stream);
- if (!src0_ch)
- src0_ch = 4;
- uint32_t src0_sb = audio_stream_sample_bytes(&src0->stream);
- if (!src0_sb)
- src0_sb = sizeof(int32_t);
- uint32_t src0_fb = src0_ch * src0_sb;
-
- uint32_t consumed0 = frames0_produced;
- if (!src1 && frames1_produced > consumed0)
- consumed0 = frames1_produced;
-
- if (consumed0 > 0) {
- comp_update_buffer_consume(src0, consumed0 * src0_fb);
- } else if ((!snk0 || comp_buffer_get_sink_state(snk0) != COMP_STATE_ACTIVE || !snk0_free) &&
- (src1 || !snk1 || comp_buffer_get_sink_state(snk1) != COMP_STATE_ACTIVE || !snk1_free)) {
- uint32_t avail = audio_stream_get_avail_bytes(&src0->stream);
-
- if (src0_fb && avail >= src0_fb) {
- avail = ROUND_DOWN(avail, src0_fb);
- comp_update_buffer_consume(src0, avail);
- }
- }
- }
+ if (frames)
+ comp_update_buffer_consume(s->buf, frames * s->frame_bytes);
}
/*
- * Main 20ms DP processing function:
+ * Main 20 ms DP processing function:
* Consumes:
- * - Pin 0 in: 16 kHz stream from dmic16k (2 or 4 channels, 16/32-bit)
- * - Pin 1 in: 48 kHz stream from dmic01 (2 or 4 channels, 16/32-bit)
+ * - Pin 0 in: 16 kHz microphone stream (2 or 4 channels, 16/32-bit)
+ * - Pin 1 in: 16 kHz echo reference (stereo, 16/32-bit)
* Produces:
- * - Pin 0 out: 16 kHz mono clean stream to KPB (averaged mono per Kconfig, 320 frames per 20ms)
- * - Pin 1 out: 48 kHz stereo/4ch clean stream to Host PCM 11 (40 Hz HPF +20 dB, 960 frames per 20ms)
- * Sampling rates remain identical between input and output on each pin.
+ * - Pin 0 out: 16 kHz mono processed stream (16/32-bit)
*/
static int ecns_copy(struct comp_dev *dev)
{
struct ecns_comp_data *cd = comp_get_drvdata(dev);
+ struct comp_buffer *src_mic = NULL;
+ struct comp_buffer *src_ref = NULL;
+ struct comp_buffer *snk = NULL;
struct comp_buffer *source;
struct comp_buffer *sink;
- struct comp_buffer *src0 = NULL;
- struct comp_buffer *src1 = NULL;
- struct comp_buffer *snk0 = NULL;
- struct comp_buffer *snk1 = NULL;
- uint32_t frames0_produced = 0;
- uint32_t frames1_produced = 0;
+ struct ecns_stream mic, ref, out;
+ uint32_t frames, ref_frames;
if (list_is_empty(&dev->bsource_list))
return 0;
@@ -1039,38 +478,61 @@ static int ecns_copy(struct comp_dev *dev)
cd->capture_boost ? "enabled" : "disabled");
}
- /* Identify input pins (producers to ECNS) */
comp_dev_for_each_producer(dev, source) {
uint32_t pin = IPC4_SINK_QUEUE_ID(buf_get_id(source));
- if (pin == ECNS_PIN_16K_IN && !src0)
- src0 = source;
- else if (pin == ECNS_PIN_48K_IN && !src1)
- src1 = source;
+ if (pin == ECNS_PIN_MIC_IN && !src_mic)
+ src_mic = source;
+ else if (pin == ECNS_PIN_REF_IN && !src_ref)
+ src_ref = source;
}
- /* Identify output pins (consumers from ECNS) */
comp_dev_for_each_consumer(dev, sink) {
- uint32_t pin = IPC4_SRC_QUEUE_ID(buf_get_id(sink));
+ if (IPC4_SRC_QUEUE_ID(buf_get_id(sink)) == ECNS_PIN_OUT && !snk)
+ snk = sink;
+ }
- if (pin == ECNS_PIN_16K_OUT && !snk0)
- snk0 = sink;
- else if (pin == ECNS_PIN_48K_OUT && !snk1)
- snk1 = sink;
+ ecns_stream_init(&mic, src_mic);
+ ecns_stream_init(&ref, src_ref);
+ ecns_stream_init(&out, snk);
+
+ /* Drain all available input bounded by sink space; a one-period cap
+ * would let the source ring overflow under DMIC vs DSP clock drift.
+ */
+ frames = ecns_avail_frames(&mic);
+ if (snk && comp_buffer_get_sink_state(snk) == COMP_STATE_ACTIVE)
+ frames = MIN(frames, audio_stream_get_free_bytes(&snk->stream) / out.frame_bytes);
+ else
+ frames = 0;
+
+ if (!frames) {
+ /* Drop the input when the output can't take it to prevent
+ * upstream DAI FIFO overruns.
+ */
+ if (!snk || comp_buffer_get_sink_state(snk) != COMP_STATE_ACTIVE ||
+ !audio_stream_get_free_bytes(&snk->stream)) {
+ if (src_mic)
+ ecns_drain(&mic);
+ if (src_ref)
+ ecns_drain(&ref);
+ }
+ return 0;
}
- /* Process Pin 0: 16 kHz stream -> Mono clean to KPB */
- if (src0 && snk0)
- frames0_produced = ecns_process_kpb(cd, src0, snk0);
+ /* A missing echo reference is processed as zero */
+ ref_frames = MIN(frames, ecns_avail_frames(&ref));
- /* Process Pin 1: 48 kHz stream -> Host capture */
- struct comp_buffer *in1 = src1 ? src1 : src0;
+ buffer_stream_invalidate(src_mic, frames * mic.frame_bytes);
+ if (ref_frames)
+ buffer_stream_invalidate(src_ref, ref_frames * ref.frame_bytes);
- if (in1 && snk1)
- frames1_produced = ecns_process_host(cd, in1, snk1);
+ ecns_process(cd, &mic, &ref, &out, frames, ref_frames);
- /* Consume from source buffers */
- ecns_consume_sources(src0, src1, snk0, snk1, frames0_produced, frames1_produced);
+ buffer_stream_writeback(snk, frames * out.frame_bytes);
+ comp_update_buffer_produce(snk, frames * out.frame_bytes);
+ comp_update_buffer_consume(src_mic, frames * mic.frame_bytes);
+ if (ref_frames)
+ comp_update_buffer_consume(src_ref, ref_frames * ref.frame_bytes);
return 0;
}
@@ -1099,32 +561,50 @@ static int ecns_set_large_config(struct comp_dev *dev,
case SOF_IPC4_SWITCH_CONTROL_PARAM_ID: {
const struct sof_ipc4_control_msg_payload *cp =
(const struct sof_ipc4_control_msg_payload *)data;
+ bool val;
if (cp->num_elems < 1)
return -EINVAL;
+ val = !!cp->chanv[0].value;
switch (cp->id) {
- case ECNS_CTRL_INDEX_TEST_SIGNAL:
-#if CONFIG_ECNS_TEST_SIGNAL
- cd->test_signal_enabled = cp->chanv[0].value ? 1 : 0;
- if (cd->test_signal_enabled)
- cd->test_signal_val = 0;
-
- comp_info(dev, "test signal %s (kpb mono output)",
- cd->test_signal_enabled ? "enabled" : "disabled");
-#else
- if (cp->chanv[0].value)
- comp_warn(dev, "test signal not supported (CONFIG_ECNS_TEST_SIGNAL=n)");
-#endif
- return 0;
case ECNS_CTRL_INDEX_CAPTURE_BOOST:
- cd->capture_boost_req = !!cp->chanv[0].value;
+ cd->capture_boost_req = val;
+ return 0;
+ case ECNS_CTRL_INDEX_AEC:
+ cd->aec_enable = val;
+ comp_info(dev, "AEC %s", val ? "enabled" : "disabled");
+ return 0;
+ case ECNS_CTRL_INDEX_NS:
+ cd->ns_enable = val;
+ comp_info(dev, "NS %s", val ? "enabled" : "disabled");
return 0;
default:
comp_err(dev, "illegal switch control id %u", cp->id);
return -EINVAL;
}
}
+ case SOF_IPC4_ENUM_CONTROL_PARAM_ID: {
+ const struct sof_ipc4_control_msg_payload *cp =
+ (const struct sof_ipc4_control_msg_payload *)data;
+
+ if (cp->num_elems < 1)
+ return -EINVAL;
+
+ if (cp->id != ECNS_CTRL_INDEX_MIC_SEL) {
+ comp_err(dev, "illegal enum control id %u", cp->id);
+ return -EINVAL;
+ }
+
+ if (cp->chanv[0].value > ECNS_MIC_SEL_MAX) {
+ comp_err(dev, "illegal mic channel %u", cp->chanv[0].value);
+ return -EINVAL;
+ }
+
+ cd->mic_sel = cp->chanv[0].value;
+ comp_info(dev, "mic channel %u", cd->mic_sel);
+ return 0;
+ }
default:
return -EINVAL;
}
@@ -1139,32 +619,54 @@ static int ecns_get_large_config(struct comp_dev *dev,
{
struct ecns_comp_data *cd = comp_get_drvdata(dev);
+ struct sof_ipc4_control_msg_payload *cp = (struct sof_ipc4_control_msg_payload *)data;
+ uint32_t resp_size = sizeof(struct sof_ipc4_control_msg_payload) +
+ sizeof(struct sof_ipc4_ctrl_value_chan);
+ uint16_t ctl_id;
+ uint32_t val;
+
switch (param_id) {
- case SOF_IPC4_SWITCH_CONTROL_PARAM_ID: {
- struct sof_ipc4_control_msg_payload *cp =
- (struct sof_ipc4_control_msg_payload *)data;
- uint16_t ctl_id = cp->id;
- uint32_t resp_size = sizeof(struct sof_ipc4_control_msg_payload) +
- sizeof(struct sof_ipc4_ctrl_value_chan);
-
- if (resp_size > *data_offset) {
- comp_err(dev, "wrong switch control response size %u vs %u",
- resp_size, *data_offset);
+ case SOF_IPC4_SWITCH_CONTROL_PARAM_ID:
+ ctl_id = cp->id;
+ switch (ctl_id) {
+ case ECNS_CTRL_INDEX_CAPTURE_BOOST:
+ val = cd->capture_boost_req;
+ break;
+ case ECNS_CTRL_INDEX_AEC:
+ val = cd->aec_enable;
+ break;
+ case ECNS_CTRL_INDEX_NS:
+ val = cd->ns_enable;
+ break;
+ default:
+ comp_err(dev, "illegal switch control id %u", ctl_id);
return -EINVAL;
}
-
- *data_offset = resp_size;
- memset_s(cp, resp_size, 0, resp_size);
- cp->id = ctl_id;
- cp->num_elems = 1;
- cp->chanv[0].channel = 0;
- cp->chanv[0].value = ctl_id == ECNS_CTRL_INDEX_CAPTURE_BOOST ?
- cd->capture_boost_req : cd->test_signal_enabled;
- return 0;
- }
+ break;
+ case SOF_IPC4_ENUM_CONTROL_PARAM_ID:
+ ctl_id = cp->id;
+ if (ctl_id != ECNS_CTRL_INDEX_MIC_SEL) {
+ comp_err(dev, "illegal enum control id %u", ctl_id);
+ return -EINVAL;
+ }
+ val = cd->mic_sel;
+ break;
default:
return -EINVAL;
}
+
+ if (resp_size > *data_offset) {
+ comp_err(dev, "wrong control response size %u vs %u", resp_size, *data_offset);
+ return -EINVAL;
+ }
+
+ *data_offset = resp_size;
+ memset_s(cp, resp_size, 0, resp_size);
+ cp->id = ctl_id;
+ cp->num_elems = 1;
+ cp->chanv[0].channel = 0;
+ cp->chanv[0].value = val;
+ return 0;
}
static const struct comp_driver ecns_drv = {
diff --git a/src/audio/ecns/ecns.toml b/src/audio/ecns/ecns.toml
index 123c93505311..af68fad2fc2b 100644
--- a/src/audio/ecns/ecns.toml
+++ b/src/audio/ecns/ecns.toml
@@ -11,6 +11,7 @@
REM # pin = [dir, type, sample rate, size, container, channel-cfg]
pin = [0, 0, 0xfeef, 0xf, 0xf, 0x45ff,
+ 0, 0, 0xfeef, 0xf, 0xf, 0x45ff,
1, 0, 0xfeef, 0xf, 0xa, 0x45ff]
REM # mod_cfg [PAR_0 PAR_1 PAR_2 PAR_3 IS_BYTES CPS IBS OBS MOD_FLAGS CPC OBLS]
diff --git a/src/audio/microwakeword/README.md b/src/audio/microwakeword/README.md
index 68b4bd9ee640..040a595dac06 100644
--- a/src/audio/microwakeword/README.md
+++ b/src/audio/microwakeword/README.md
@@ -10,73 +10,83 @@ executes streaming inference over a stateful TensorFlow Lite Micro (TFLM) graph,
outputting a single sigmoid wake-word probability per keyword model.
In this architecture, **one unified codebase** supports **three concurrent keyword spotter instances**:
-- **Slot 0** (Pipeline 101): `"strawberry"`
-- **Slot 1** (Pipeline 102): `"hi intel"`
-- **Slot 2** (Pipeline 103): `"orange"`
+- **Slot 0** (Pipeline 111, legacy 101): `"strawberry"`
+- **Slot 1** (Pipeline 112, legacy 102): `"hi intel"`
+- **Slot 2** (Pipeline 113, legacy 103): `"orange"`
---
## Architecture & Data Flow
-The multi-slot MWW topology is unified across **Tiger Lake (TGL)**, **Panther Lake (PTL)**, and **Wildcat Lake (WCL)**:
+The multi-slot MWW topology for DMIC is defined in `tools/topology/topology2/platform/intel/dmic-wov-multi.conf` and used by the SoundWire (PTL, WCL), ADL rt5682 and HDA generic `wov-multi` topologies:
```mermaid
graph TD
- subgraph P100["Pipeline 100 — 4ch DMIC Capture (Core 0, LL 1ms)"]
- DAI["DAI Copier (dmic01 / dmic16k)\n4ch · 16 kHz · S16_LE\nCh 0,1: Mics | Ch 2,3: Echo Ref"]
- MIX100["mixin 100.1\n(4ch pass-through)"]
- DAI --> MIX100
+ subgraph P119["Pipeline 119 — 16 kHz DMIC Capture (Core 0, LL 1ms)"]
+ DAI["dai-copier.DMIC.dmic16k.capture\n2/4ch · 16 kHz · S32_LE"]
end
- subgraph P105["Pipeline 105 — ECNS DP Processing (Core 0, DP 20ms)"]
- MO105["mixout 105.1\n(4ch input)"]
- ECNS["ecns.105.1\n(ECNS DP Module, 20ms = 320 frames)\nCh 0,1: Mic | Ch 2,3: Echo Ref"]
- MO105 --> ECNS
+ subgraph P120["Pipeline 120 — Speaker Echo Reference (Core 0, LL 1ms)"]
+ SIGGEN["siggen.120.1\n(48 kHz stereo speaker playback,\nsilence when speaker is idle)"]
+ SRC120["src.120.1\n(48 kHz -> 16 kHz · 2ch · S32_LE)"]
+ SIGGEN --> SRC120
end
- subgraph P106["Pipeline 106 — KPB History Buffer (Core 0, DP 20ms)"]
- KPB["kpb.106.1\n(2.0s mono history = 64 KB)\n16 kHz · 1ch · S16_LE\nPin 0: sel_sink | Pin 1: host_sink"]
- MIX106["mixin 106.1\n(3-way fanout mixin)"]
- KPB -- "Pin 0 (sel_sink)" --> MIX106
+ subgraph P115["Pipeline 115 — ECNS DP Processing (Core 0, DP 20ms)"]
+ ECNS["ecns.115.1\n(ECNS DP Module, 20ms = 320 frames)\nPin 0 In: Mics | Pin 1 In: Echo Ref\nMono, 100 Hz HPF, optional AEC"]
end
- subgraph P101["Pipeline 101 — Slot 0: 'strawberry' (Core 0, DP 10ms)"]
- MO101["mixout 101.1"]
- MFCC0["mfcc.101.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
- MWW0["mww.101.1\n(microWakeWord)\nModel: 'strawberry'"]
+ subgraph P116["Pipeline 116 — KPB History Buffer (Core 0, LL 1ms)"]
+ KPB["kpb.116.1\n(2.0s mono history = 64 KB)\n16 kHz · 1ch · S16_LE\nPin 0: sel_sink | Pin 1: host_sink"]
+ end
+
+ subgraph P118["Pipeline 118 — Detector Fanout (Core 0, LL 1ms)"]
+ FAN["module-copier.118.1\n(3-way fanout)"]
+ end
+
+ subgraph P111["Pipeline 111 — Slot 0: 'strawberry'"]
+ MO101["module-copier.111.1"]
+ MFCC0["mfcc.111.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
+ MWW0["mww.111.1\n(microWakeWord)\nModel: 'strawberry'"]
MO101 --> MFCC0 --> MWW0
end
- subgraph P102["Pipeline 102 — Slot 1: 'hi intel' (Core 0, DP 10ms)"]
- MO102["mixout 102.1"]
- MFCC1["mfcc.102.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
- MWW1["mww.102.1\n(microWakeWord)\nModel: 'hi intel'"]
+ subgraph P112["Pipeline 112 — Slot 1: 'hi intel'"]
+ MO102["module-copier.112.1"]
+ MFCC1["mfcc.112.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
+ MWW1["mww.112.1\n(microWakeWord)\nModel: 'hi intel'"]
MO102 --> MFCC1 --> MWW1
end
- subgraph P103["Pipeline 103 — Slot 2: 'orange' (Core 0, DP 10ms)"]
- MO103["mixout 103.1"]
- MFCC2["mfcc.103.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
- MWW2["mww.103.1\n(microWakeWord)\nModel: 'orange'"]
+ subgraph P113["Pipeline 113 — Slot 2: 'orange'"]
+ MO103["module-copier.113.1"]
+ MFCC2["mfcc.113.1\n(Mel-40 10ms PCAN Compress)\nIBS: 320B | OBS: 64B"]
+ MWW2["mww.113.1\n(microWakeWord)\nModel: 'orange'"]
MO103 --> MFCC2 --> MWW2
end
- subgraph P104["Pipeline 104 — WOV Host PCM Capture (Core 0, LL 1ms)"]
- ARB["wov-arbiter.104.1\n(4 input pins, 1 output pin\nPin 0: Audio | Pins 1-3: Features\n1ch mono 16 kHz S16_LE)"]
- HC11["host-copier.11\n(hw:0,11 · PCM 11)\n1ch · 16 kHz · S16_LE / S32_LE"]
- ARB --> HC11
+ subgraph P114["Pipeline 114 — WOV Host PCM Capture (Core 0, LL 1ms)"]
+ ARB["wov-arbiter.114.1\n(4 input pins, 1 output pin\nPin 0: Audio | Pins 1-3: Features\n1ch mono 16 kHz S16_LE)"]
+ HC12["host-copier.12\n(hw:0,12 · PCM 12 'DMIC Multi-WOV')\n1ch · 16 kHz · S16_LE / S32_LE"]
+ ARB --> HC12
end
- subgraph P107["Pipeline 107 — ECNS Host PCM Capture (Core 0, LL 1ms)"]
- HC10["host-copier.10\n(hw:0,10 · PCM 10)\n2ch · 16 kHz · S16_LE / S32_LE"]
+ subgraph P101["Pipelines 101, 100 — Regular DMIC0 48k Host PCM Capture (Core 0, LL 1ms)"]
+ DAI48["dai-copier.DMIC.dmic01.capture\n(Pipeline 101 · 2/4ch · 48 kHz)"]
+ GAIN101["gain.101.1\n(Dmic0 Capture Volume / Switch)"]
+ IIR101["eqiir.101.1\n(40 Hz high-pass, +20 dB)"]
+ MC101["module-copier.101.2"]
+ HC10["host-copier.10\n(hw:0,10 · PCM 10 'DMIC Raw')\n2/4ch · 48 kHz · S32_LE"]
+ DAI48 --> GAIN101 --> IIR101 --> MC101 --> HC10
end
- MIX100 --> MO105
- ECNS -- "Pin 0 (Mono Clean direct)" --> KPB
- ECNS -- "Pin 1 (Stereo Clean direct)" --> HC10
- MIX106 --> MO101
- MIX106 --> MO102
- MIX106 --> MO103
+ DAI -- "Pin 0 In" --> ECNS
+ SRC120 -- "Pin 1 In" --> ECNS
+ ECNS -- "Pin 0 Out (Mono 16k)" --> KPB
+ KPB -- "Pin 0 (sel_sink)" --> FAN
+ FAN --> MO101
+ FAN --> MO102
+ FAN --> MO103
KPB -- "Pin 1 (host_sink / drain audio)" --> ARB
MWW0 -->|"Pin 1 (Features)"| ARB
@@ -102,19 +112,34 @@ graph TD
style MWW1 fill:#b7950b,stroke:#555,color:#fff
style MWW2 fill:#d35400,stroke:#555,color:#fff
style ARB fill:#4a235a,stroke:#555,color:#fff
- style HC11 fill:#2d5a27,stroke:#555,color:#fff
+ style HC12 fill:#2d5a27,stroke:#555,color:#fff
style HC10 fill:#1e8449,stroke:#555,color:#fff
```
+The 48 kHz DMIC capture does not pass through ECNS. It is the same regular
+DMIC0 capture of `dmic-generic.conf` as in the non-WoV topologies, without
+TDFB/DRC (`DMIC0_ENHANCED_CAPTURE` false). The IDs above are for SoundWire;
+HDA generic uses pipelines 12/11 and PCM 6, ADL rt5682 uses pipelines 14/13
+and PCM 99. The speaker
+playback is routed into `siggen.120.1` by the platform topology
+(`SDW_SPK_ECHO_REF_ECNS`, `SPEAKER_ECHO_REF_ECNS` or `HDA_SPEAKER_ECHO_REF_ECNS`).
+
+The SoundWire headset WoV (`sdw-jack-wov-multi.conf`, `INCLUDE_SDW_JACK_WOV=true`)
+has no ECNS: `module-copier.11.0` (Jack In, 48 kHz 2ch) -> `micsel.140.1`
+(`(L+R)/2` mono) -> `src.140.1` (48 -> 16 kHz) -> `module-copier.140.1`
+(to 16-bit) -> `kpb.146.1` -> detector slots 141-143 -> `wov-arbiter.144.1` ->
+PCM 14 `Headset Multi-WOV`.
+
---
## Cross-Platform Manifest Targets
-| Target Platform | Manifest File | Output Topology Binary | DMIC Driver Version |
-|---|---|---|---|
-| **Panther Lake (PTL / ACE 3.0)** | [`dmic-wov-multi-ptl-4ch-manifest.conf`](file:///home/lrg/work/sof-tgl/sof-wov/tools/topology/topology2/dmic-wov-multi-ptl-4ch-manifest.conf) | `sof-ptl-dmic-wov-multi-4ch.tplg` | 5 |
-| **Tiger Lake (TGL / CAVS 2.5)** | [`dmic-wov-multi-4ch-manifest.conf`](file:///home/lrg/work/sof-tgl/sof-wov/tools/topology/topology2/dmic-wov-multi-4ch-manifest.conf) | `sof-tgl-dmic-wov-multi-4ch.tplg` | 1 |
-| **Wildcat Lake (WCL / ACE 3.0)** | symlink to the PTL topology | `sof-wcl-dmic-wov-multi-4ch.tplg` | 5 |
+The standalone DMIC-only 4-channel manifests (`dmic-wov-multi-ptl-4ch-manifest.conf`,
+`dmic-wov-multi-4ch-manifest.conf`) and their `sof-*-dmic-wov-multi-4ch.tplg` targets
+have been removed, because ECNS requires a speaker echo reference input that a
+DMIC-only topology cannot provide. See
+[`tools/topology/topology2/README.md`](../../../tools/topology/topology2/README.md)
+for the remaining multi-slot WoV topology targets.
---
@@ -149,9 +174,9 @@ This guarantees deterministic execution, avoids heap fragmentation, and ensures
### 3. Keyword Model Dispatch
Default built-in models are bound automatically by slot/pipeline index when using `CONFIG_COMP_MWW_MODEL_PIPELINE_ID` (default):
-- **Slot 0** (`pipeline_id == 101`): `mww_model_data_strawberry`
-- **Slot 1** (`pipeline_id == 102`): `mww_model_data_hi_intel`
-- **Slot 2** (`pipeline_id == 103`): `mww_model_data_orange`
+- **Slot 0** (`pipeline_id == 111` or `101`): `mww_model_data_strawberry`
+- **Slot 1** (`pipeline_id == 112` or `102`): `mww_model_data_hi_intel`
+- **Slot 2** (`pipeline_id == 113` or `103`): `mww_model_data_orange`
Alternatively, a single built-in model can be forced via Kconfig (`CONFIG_COMP_MWW_MODEL_HI_INTEL`, `CONFIG_COMP_MWW_MODEL_HEY_JARVIS`, `CONFIG_COMP_MWW_MODEL_STRAWBERRY`, `CONFIG_COMP_MWW_MODEL_ORANGE`, or `CONFIG_COMP_MWW_MODEL_BANANA`), omitting all other models from the build to reduce firmware image size.
@@ -195,8 +220,9 @@ amixer -c 0 cget name='Jack In Phrase Detect ID'
```
### 2. Audio Capture Endpoints
-- **Stereo ECNS Stream** (PCM 10): `arecord -D hw:0,10 -f S16_LE -r 16000 -c 2 -d 5 /tmp/ecns.wav`
-- **Mono WOV Capture Stream** (PCM 11): `arecord -D hw:0,11 -f S16_LE -r 16000 -c 1 -d 5 /tmp/wov.wav` (supports both `S16_LE` and `S32_LE`).
+- **DMIC 48 kHz Stream** (PCM 10 `DMIC Raw` on SoundWire, PCM 6 on HDA generic, PCM 99 on ADL rt5682; 40 Hz high-pass, no ECNS): `arecord -D hw:0,10 -f S32_LE -r 48000 -c 4 -d 5 /tmp/dmic48k.wav` (use `-c 2` with `NUM_DMICS=2`).
+- **Mono WOV Capture Stream** (PCM 12): `arecord -D hw:0,12 -f S16_LE -r 16000 -c 1 -d 5 /tmp/wov.wav` (supports both `S16_LE` and `S32_LE`).
+- **Headset Mono WOV Capture Stream** (PCM 14): `arecord -D hw:0,14 -f S16_LE -r 16000 -c 1 -d 5 /tmp/hs_wov.wav`.
---
diff --git a/src/audio/wov_arbiter/README.md b/src/audio/wov_arbiter/README.md
index cefa8a66c95c..a76f17f527b4 100644
--- a/src/audio/wov_arbiter/README.md
+++ b/src/audio/wov_arbiter/README.md
@@ -31,94 +31,100 @@ Audio stream capture and device verification are executed using direct Linux ALS
## System Architecture
The Multi-Slot WOV subsystem supports two primary topology architectures:
-1. **4-Channel Native 16 kHz DMIC with ECNS & Multi-Slot WOV** (PTL, TGL, WCL 4ch native manifests).
+1. **2/4-Channel 16 kHz DMIC with ECNS (speaker echo reference) & Multi-Slot WOV** (`platform/intel/dmic-wov-multi.conf`, used by the SoundWire, ADL rt5682 and HDA generic `wov-multi` topologies).
2. **2-Channel DMIC / SSP Direct Multi-Slot WOV** (2ch manifests).
---
-#### Architecture A: Dual-Rate DMIC with ECNS & microWakeWord (MWW) Multi-Slot WOV
+#### Architecture A: DMIC with ECNS & microWakeWord (MWW) Multi-Slot WOV
-In this architecture, two dedicated physical PDM digital microphone interfaces feed the **ECNS DP module** running at a 20 ms period:
-- **PDM1 (`dmic16k`)**: Dedicated 16 kHz stereo stream via Pipeline 119 feeding ECNS Input Pin 0.
-- **PDM0 (`dmic01`)**: Dedicated 48 kHz stereo stream via Pipeline 110 feeding ECNS Input Pin 1.
+In this architecture, two dedicated physical PDM digital microphone interfaces and a speaker echo reference feed the topology:
+- **PDM1 (`dmic16k`)**: Dedicated 16 kHz 2ch or 4ch (`DMIC_WOV_DAI_CHANNELS`) 32-bit stream via Pipeline 119 feeding ECNS Input Pin 0.
+- **Speaker echo reference**: Pipeline 120 (`siggen-src-capture`) collects the 48 kHz stereo speaker playback in `siggen.120.1` (passthrough when bound, silence when the speaker is not running) and converts it to 16 kHz stereo 32-bit in `src.120.1`, feeding ECNS Input Pin 1. The platform topology routes the speaker playback into `siggen.120.1` (SoundWire `SDW_SPK_ECHO_REF_ECNS=true`, ADL rt5682 SSP `SPEAKER_ECHO_REF_ECNS=true`, HDA generic `HDA_SPEAKER_ECHO_REF_ECNS=true`).
+- **PDM0 (`dmic01`)**: 48 kHz 2ch or 4ch (`NUM_DMICS`) 32-bit stream captured with the same regular DMIC0 pipelines of `platform/intel/dmic-generic.conf` as in the non-WoV topologies, without the TDFB/DRC enhancements (`DMIC0_ENHANCED_CAPTURE` false). It does not pass through ECNS: `dai-copier.DMIC.dmic01.capture` -> `gain.101.1` (muting and volume) -> `eqiir.101.1` (`DMIC0_DAI_EQIIR`, 40 Hz high-pass) -> `module-copier.101.2` -> `host-copier.10.capture` (ALSA PCM 10, `hw:0,10`, `DMIC Raw`, S32_LE). The IDs are for SoundWire (DAI pipeline 101, host pipeline 100, PCM 10); HDA generic uses pipelines 12/11 and PCM 6, ADL rt5682 uses pipelines 14/13 and PCM 99. This PCM is not D0i3 compatible.
-The ECNS module processes both streams and outputs:
-- **Pin 0 (mono clean speech)**: Extracts the Left channel from Pin 0 in to produce a 16 kHz mono clean stream. Routes to KPB (Pipeline 116, 2.0s history depth = 64 KB mono buffer), then fans out via `mixin.116.1` to 3 concurrent **microWakeWord (MWW)** keyword spotting slots (running MFCC feature extraction + TFLM streaming graph in lock-step). Upon keyword detection, the detector notifies KPB (`NOTIFIER_ID_KPB_CLIENT_EVT`) to drain and the WOV Arbiter (`NOTIFIER_ID_WOV_DETECT`) to set `wov_active_slot` and pause sibling slots. The WOV Arbiter routes the active slot audio (pre-roll + live) to ALSA PCM 12 (`hw:0,12`, `DMIC Multi-WOV`, `capture_compatible_d0i3: true`).
-- **Pin 1 (stereo clean speech)**: Performs a 1-to-1 copy of Pin 1 in to produce a 48 kHz stereo clean stream routed to Host Copier 11 (ALSA PCM 11, `hw:0,11`, `DMIC ECNS Capture`, `capture_compatible_d0i3: true`).
+The ECNS DP module (20 ms period) has a single output:
+- **Pin 0 Out (16 kHz mono)**: The microphone channels of Pin 0 In are averaged to mono, or a single channel is selected with the `DMIC ECNS mic channel` enum (`Average` by default, `Mic1`..`Mic2` or `Mic1`..`Mic4`), and filtered by a 100 Hz high-pass IIR. The `DMIC ECNS boost` switch selects the +30 dB or the 0 dB filter response. When the `DMIC ECNS AEC switch` is on, the `(L+R)/2` average of the echo reference is subtracted after the IIR. The `DMIC ECNS NS switch` has no function yet. Both AEC and NS switches default to off. The output is s16 in the topology (the firmware follows the KPB input bit depth). It routes to KPB (Pipeline 116, 2.0s history depth = 64 KB mono buffer), then fans out via `module-copier.118.1` to 3 concurrent **microWakeWord (MWW)** keyword spotting slots (running MFCC feature extraction + TFLM streaming graph in lock-step). Upon keyword detection, the detector notifies KPB (`NOTIFIER_ID_KPB_CLIENT_EVT`) to drain and the WOV Arbiter (`NOTIFIER_ID_WOV_DETECT`) to set `wov_active_slot` and pause sibling slots. The WOV Arbiter routes the active slot audio (pre-roll + live) to ALSA PCM 12 (`hw:0,12`, `DMIC Multi-WOV`, `capture_compatible_d0i3: true`).
```mermaid
flowchart TD
%% Hardware PDM Interfaces
subgraph PDM_INTERFACES ["Digital Microphone Interfaces (2 Separate PDM DAIs)"]
direction LR
- PDM_48K["PDM Interface: dmic01
DAI Index: 0 (PDM0)
Rate: 48 kHz · 2ch Stereo · 16-bit"]
- PDM_16K["PDM Interface: dmic16k
DAI Index: 1 (PDM1)
Rate: 16 kHz · 2ch Stereo · 16-bit"]
+ PDM_48K["PDM Interface: dmic01
DAI Index: 0 (PDM0)
Rate: 48 kHz · 2/4ch · 32-bit"]
+ PDM_16K["PDM Interface: dmic16k
DAI Index: 1 (PDM1)
Rate: 16 kHz · 2/4ch · 32-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
(48 kHz · 2ch · S16_LE)"]
- MIXIN_110["mixin.110.1
(48 kHz · 2ch)"]
- DAI_48K --> MIXIN_110
+ %% Pipeline 101: 48 kHz DAI Capture (regular DMIC0, SoundWire IDs)
+ subgraph P101 ["Pipeline 101: 48 kHz DMIC0 DAI Capture (Core 0, LL 1ms)"]
+ DAI_48K["dai-copier.DMIC.dmic01.capture
(48 kHz · 2/4ch · S32_LE)"]
+ GAIN_101["gain.101.1
(Dmic0 Capture Volume / Switch)"]
+ IIR_101["eqiir.101.1
(DMIC0_DAI_EQIIR, 40 Hz high-pass)"]
+ MCP_101["module-copier.101.2"]
+ DAI_48K --> GAIN_101 --> IIR_101 --> MCP_101
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
(16 kHz · 2ch · S16_LE)"]
- MIXIN_119["mixin.119.1
(16 kHz · 2ch)"]
- DAI_16K --> MIXIN_119
+ DAI_16K["dai-copier.DMIC.dmic16k.capture
(16 kHz · 2/4ch · S32_LE)"]
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
(Pin 0 In: 16 kHz · 2ch stereo)"]
- MIXOUT_115_1["mixout.115.1
(Pin 1 In: 48 kHz · 2ch stereo)"]
-
- ECNS["ecns.115.1 (DP Component · 20ms Period)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Pin 0 In: 16 kHz, 2ch (IBS 1280 bytes)
Pin 1 In: 48 kHz, 2ch (IBS 3840 bytes)
─────────────────────────────
Processing:
• Pin 0: Extract Left Ch → 16k Mono Clean
• Pin 1: 1-to-1 Stereo Copy → 48k Stereo Clean
─────────────────────────────
Pin 0 Out: 16 kHz, 1ch mono (OBS 640 bytes)
Pin 1 Out: 48 kHz, 2ch stereo (OBS 3840 bytes)"]
+ %% Pipeline 120: Speaker echo reference
+ SPK["Speaker playback
(SDW / SSP / HDA module-copier
+ loopback DAI where available)"]
+ subgraph P120 ["Pipeline 120: Speaker Echo Reference (Core 0, LL 1ms)"]
+ SIGGEN["siggen.120.1
(48 kHz · 2ch · passthrough,
silence when speaker is idle)"]
+ SRC_120["src.120.1
(48 kHz → 16 kHz · 2ch · S32_LE)"]
+ SIGGEN --> SRC_120
+ end
+ SPK --> SIGGEN
- MIXOUT_115_2 -->|"Pin 0 In (16k)"| ECNS
- MIXOUT_115_1 -->|"Pin 1 In (48k)"| ECNS
+ %% Pipeline 115: ECNS DP Pipeline
+ subgraph P115 ["Pipeline 115: ECNS Engine (Core 0, DP 20ms, lp_mode 1)"]
+ ECNS["ecns.115.1 (DP Component · 20ms Period)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Pin 0 In: 16 kHz mic, 2/4ch s32
Pin 1 In: 16 kHz echo ref, 2ch s32
─────────────────────────────
Processing:
• Mic channel enum: average or MicN
• 100 Hz HPF (boost +30 dB / 0 dB)
• AEC switch: subtract (L+R)/2 of ref
• NS switch: no function yet
─────────────────────────────
Pin 0 Out: 16 kHz, 1ch mono (OBS 640 bytes)"]
end
- MIXIN_119 --> MIXOUT_115_2
- MIXIN_110 --> MIXOUT_115_1
+ DAI_16K -->|"Pin 0 In (16k mic)"| ECNS
+ SRC_120 -->|"Pin 1 In (16k echo ref)"| ECNS
- %% Pipeline 117: Host Capture PCM 11
- subgraph P117 ["Pipeline 117: ECNS Clean Host Capture (Core 0, LL 1ms)"]
- HOST_11["host-copier.11.capture
(PCM 11: 'DMIC ECNS Capture'
hw:0,11 · d0i3_compatible=true)"]
+ %% Pipeline 100: Host Capture PCM 10 (regular DMIC0, SoundWire IDs)
+ subgraph P100 ["Pipeline 100: DMIC0 Host Capture (Core 0, LL 1ms)"]
+ HOST_10["host-copier.10.capture
(PCM 10: 'DMIC Raw'
hw:0,10 · 2/4ch · S32_LE)"]
end
+ MCP_101 --> HOST_10
+
%% Pipeline 116: KPB History Buffer
- subgraph P116 ["Pipeline 116: Key Phrase Buffer (Core 0, DP 20ms)"]
+ subgraph P116 ["Pipeline 116: Key Phrase Buffer (Core 0, LL 1ms)"]
KPB["kpb.116.1
(2000 ms mono history = 64 KB)"]
- MIXIN_116["mixin.116.1
(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
+ %% Pipeline 118: Detector fanout
+ subgraph P118 ["Pipeline 118: Detector Fanout (Core 0, LL 1ms)"]
+ FANOUT["module-copier.118.1
(3-way detector fanout)"]
+ end
+ KPB -->|"Pin 0 (Live Feed)"| FANOUT
+
+ ECNS -->|"Pin 0 Out (Mono 16k)"| 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"]
+ M1["module-copier.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"]
+ M2["module-copier.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"]
+ M3["module-copier.113.1"] --> MF3["mfcc.113.1"] --> MW3["mww.113.1"]
end
end
- MIXIN_116 --> M1
- MIXIN_116 --> M2
- MIXIN_116 --> M3
+ FANOUT --> M1
+ FANOUT --> M2
+ FANOUT --> M3
%% Pipeline 114: WoV Arbiter & Host Capture PCM 12
subgraph P114 ["Pipeline 114: WoV Arbiter (Core 0, LL 1ms)"]
@@ -145,7 +151,7 @@ flowchart TD
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_10 fill:#1e8449,stroke:#555,color:#fff
style HOST_12 fill:#2d5a27,stroke:#555,color:#fff
```
@@ -153,18 +159,18 @@ flowchart TD
The dual-rate DMIC architecture is deployed across **Panther Lake (PTL)**, **Tiger Lake (TGL)**, and **Wildcat Lake (WCL)** via `platform/intel/dmic-wov-multi.conf` and `dmic-wov-feature.conf`:
-| Property | ECNS Clean Stream (PCM 11) | WOV Stream (PCM 12) |
+| Property | DMIC 48k Stream (PCM 10) | WOV Stream (PCM 12) |
|---|---|---|
-| ALSA Device | `hw:0,11` (`pcmC0D11c`) | `hw:0,12` (`pcmC0D12c`) |
+| ALSA Device | `hw:0,10` (`pcmC0D10c`) on SoundWire, PCM 6 on HDA generic, PCM 99 on ADL rt5682 | `hw:0,12` (`pcmC0D12c`) |
| Sample Rate | 48 kHz | 16 kHz |
-| Channels | 2 (Stereo clean mic) | 1 (Mono clean mic) |
-| Sample Format | S16_LE / S32_LE | S16_LE / S32_LE |
+| Channels | 2 or 4 (`NUM_DMICS`) | 1 (Mono ECNS output) |
+| Sample Format | S32_LE | S16_LE / S32_LE |
| History / Pre-roll | Live streaming | 2.0 s (64 KB mono buffer in KPB) |
| Keyword Spotters | N/A | 3 concurrent slots: 0="strawberry", 1="hi intel", 2="orange" |
| Keyword Control | N/A | `wov_active_slot` enum (0=Listening, 1=Slot 0, 2=Slot 1, 3=Slot 2) |
-| Scheduling | Core 0 (LL 1ms) | Core 0 (LL 1ms arbiter + DP 20ms KPB + DP 10ms MWW) |
-| Processing Source | ECNS Pin 1 (1-to-1 copy of 48k `dmic01`) | ECNS Pin 0 (mono Left ch of 16k `dmic16k`) via KPB & WOV Arbiter |
-| D0i3 Low Power | **Yes** (`capture_compatible_d0i3: true`) | **Yes** (`capture_compatible_d0i3: true`) |
+| Scheduling | Core 0 (LL 1ms) | Core 0 (LL 1ms KPB + arbiter, DP 20ms ECNS, DP 10ms MWW) |
+| Processing Source | 48k `dmic01` via the regular DMIC0 `gain` and `eqiir` (`DMIC0_DAI_EQIIR` 40 Hz high-pass), no ECNS | ECNS Pin 0 Out (mono average of 16k `dmic16k`, 100 Hz HPF, optional AEC with the Pin 1 echo reference) via KPB & WOV Arbiter |
+| D0i3 Low Power | No | **Yes** (`capture_compatible_d0i3: true`) |
---
@@ -926,14 +932,12 @@ ALSA_CONFIG_DIR=$ALSA_TMP ALSA_TOPOLOGY_PLUGIN_DIR=/usr/lib/alsa-topology alsatp
-I $TPLG2 -p \
-c tools/topology/topology2/dmic-wov-multi-manifest.conf \
-o /tmp/sof-tgl-dmic-wov-multi.tplg
-
-# 2. Native 16 kHz 4-Channel Multi-WOV Topology (No SRC, with embedded NHLT)
-ALSA_CONFIG_DIR=$ALSA_TMP ALSA_TOPOLOGY_PLUGIN_DIR=/usr/lib/alsa-topology alsatplg \
- -I $TPLG2 -p \
- -c tools/topology/topology2/dmic-wov-multi-4ch-manifest.conf \
- -o /tmp/sof-tgl-dmic-wov-multi-4ch.tplg
```
+The standalone native 16 kHz 4-channel DMIC-only manifest
+(`dmic-wov-multi-4ch-manifest.conf`) has been removed, because ECNS requires a
+speaker echo reference input that a DMIC-only topology cannot provide.
+
`ALSA_CONFIG_DIR` must point to a directory that contains `alsa.conf` plus
`include/` and `platform/` symlinks into `topology2/`. `ALSA_TOPOLOGY_PLUGIN_DIR` points to
the directory containing `libalsatplg_module_nhlt.so` so the NHLT preprocessor plugin can
@@ -942,8 +946,8 @@ generate and embed the hardware ACPI NHLT table into the manifest binary.
Copy the compiled topology to the DUT:
```bash
-scp /tmp/sof-tgl-dmic-wov-multi-4ch.tplg \
- root@:/lib/firmware/intel/sof-ipc4-tplg/sof-tgl-dmic-wov-multi-4ch.tplg
+scp /tmp/sof-tgl-dmic-wov-multi.tplg \
+ root@:/lib/firmware/intel/sof-ipc4-tplg/sof-tgl-dmic-wov-multi.tplg
```
### BIOS NHLT Table Override (`sof_use_tplg_nhlt=1`)
@@ -956,7 +960,7 @@ The SOF Linux kernel driver supports **overriding the BIOS NHLT table** using th
table embedded in the topology manifest binary.
#### 1. How Topology NHLT is Embedded
-In the topology manifest (`dmic-wov-multi-4ch-manifest.conf`):
+In a topology manifest that embeds its own NHLT table:
- `Define { PREPROCESS_PLUGINS "nhlt" }` enables the NHLT compiler plugin.
- `Object.Dai.DMIC` defines the DAI parameters (`sample_rate 16000`, `num_pdm_active 2`, 4 active mics).
- `Object.Base.manifest.1 { nhlt "true" }` packages the NHLT table into a `SOF_MANIFEST_DATA_TYPE_NHLT` (1) TLV data block inside the compiled `.tplg` binary.
@@ -968,7 +972,7 @@ Edit `/etc/modprobe.d/sof.conf` on the DUT:
```ini
# /etc/modprobe.d/sof.conf
-options snd_sof tplg_path=intel/sof-ipc4-tplg tplg_filename=sof-tgl-dmic-wov-multi-4ch.tplg
+options snd_sof tplg_path=intel/sof-ipc4-tplg tplg_filename=.tplg
options snd_sof_intel_hda_common sof_use_tplg_nhlt=1
```
diff --git a/src/include/sof/audio/ecns.h b/src/include/sof/audio/ecns.h
index 7bf2ab983dda..b39a91041ee5 100644
--- a/src/include/sof/audio/ecns.h
+++ b/src/include/sof/audio/ecns.h
@@ -3,31 +3,36 @@
* Copyright(c) 2026 Intel Corporation. All rights reserved.
*/
+/**
+ * \file
+ * \brief ECNS (Echo Cancellation & Noise Suppression) component definitions
+ */
+
#ifndef __SOF_AUDIO_ECNS_H__
#define __SOF_AUDIO_ECNS_H__
#include
#include
-#define ECNS_IN_CHANNELS 2
-#define ECNS_PIN_KPB 0 /* Output Pin 0: Channel 0 mono to KPB */
-#define ECNS_PIN_HOST 1 /* Output Pin 1: Channels 0,1 stereo to Host Copier */
+/** \brief Input pin 0: 16 kHz microphone stream from the DMIC DAI copier */
+#define ECNS_PIN_MIC_IN 0
+/** \brief Input pin 1: 16 kHz echo reference stream from the speaker */
+#define ECNS_PIN_REF_IN 1
+/** \brief Output pin 0: 16 kHz mono processed stream, e.g. to KPB */
+#define ECNS_PIN_OUT 0
-#define ECNS_PIN_16K_IN 0 /* Input Pin 0: 16 kHz stream from dmic16k */
-#define ECNS_PIN_48K_IN 1 /* Input Pin 1: 48 kHz stream from dmic01 */
-#define ECNS_PIN_16K_OUT 0 /* Output Pin 0: 16 kHz mono clean to KPB */
-#define ECNS_PIN_48K_OUT 1 /* Output Pin 1: 48 kHz stereo clean to Host Copier */
+/** \brief Output sample rate in Hz */
+#define ECNS_RATE 16000
-#define ECNS_PERIOD_MS 20
-#define ECNS_FRAME_SAMPLES_16K 320 /* 20ms @ 16 kHz */
-#define ECNS_FRAME_SAMPLES_48K 960 /* 20ms @ 48 kHz */
-#define ECNS_FRAME_SAMPLES ECNS_FRAME_SAMPLES_16K
+/** \brief Microphone channel enum value to average all channels */
+#define ECNS_MIC_SEL_AVERAGE 0
+/** \brief Largest microphone channel enum value, Mic4 */
+#define ECNS_MIC_SEL_MAX 4
-/* IPC4 channel maps, one nibble per channel index, 0xF marks unused */
+/** \brief IPC4 channel map for mono, one nibble per channel, 0xF marks unused */
#define ECNS_CH_MAP_MONO 0xFFFFFFF0
-#define ECNS_CH_MAP_STEREO 0xFFFFFF10
-#define ECNS_CH_MAP_4CH 0xFFFF3210
+/** \brief Register the ECNS component driver */
void sys_comp_ecns_init(void);
#endif /* __SOF_AUDIO_ECNS_H__ */
diff --git a/tools/rimage/config/tgl.toml.h b/tools/rimage/config/tgl.toml.h
index d85358fc3d1e..dd2ce3655697 100644
--- a/tools/rimage/config/tgl.toml.h
+++ b/tools/rimage/config/tgl.toml.h
@@ -144,5 +144,9 @@
#include