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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/audio/webrtc_ns2/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ config COMP_WEBRTC_NS2
(music, babble, keyboard) than the classic spectral Wiener filter
(COMP_WEBRTC_NS).

The module is single-input, single-output and internally emits a
per-frame VAD probability (0.0–1.0) via NOTIFIER_ID_VAD, making it
a combined denoiser and activity detector.
The module is single-input, single-output and also computes a
per-frame VAD probability (0.0–1.0), making it a combined denoiser
and activity detector.

Requirements:
- Floating-point unit (FPU=y on ACE30/PTL; soft-float also works
Expand Down Expand Up @@ -49,13 +49,15 @@ config WEBRTC_NS2_CHANNELS_MAX
channel. Set to 1 for pure mono capture pipelines.

config WEBRTC_NS2_VAD_NOTIFY
bool "Emit NOTIFIER_ID_VAD event from RNNoise VAD probability"
bool "Make a VAD decision from the RNNoise VAD probability"
default y
help
RNNoise returns a per-frame speech probability in [0.0, 1.0]. When
this option is enabled the module broadcasts a NOTIFIER_ID_VAD event
(speech=1 / silence=0) using a configurable threshold, providing a
this option is enabled the module turns it into a speech=1 /
silence=0 decision using a configurable threshold, providing a
combined denoiser + VAD without running a separate webrtc_vad module.
Delivering the decision to other components is not implemented
yet: the module only logs changes at debug level.

config WEBRTC_NS2_VAD_THRESHOLD_PCT
int "VAD threshold as percentage of max probability (0-100)"
Expand Down
8 changes: 4 additions & 4 deletions src/audio/webrtc_ns2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Wraps Xiph's [RNNoise](https://github.com/xiph/rnnoise) — a recurrent neural n
## Features

- **Deep Learning Suppression**: Uses a hybrid DSP + deep recurrent neural network structure (GRU) for suppressing non-stationary noise (such as keyboard clicks, speech babble, or music).
- **VAD Output**: Calculates speech probability per frame and broadcasts binary voice activity events via `NOTIFIER_ID_VAD`.
- **VAD Output**: Calculates speech probability per frame and turns it into a binary voice activity decision. Delivering it to other components is not implemented yet: the module only logs changes at debug level.
- **Locked Rate (48 kHz)**: Runs exclusively at **48000 Hz** (requires an ASRC upstream if the DAI runs at another rate).
- **10 ms Process Window**: Accumulates pipeline periods to process complete 480-sample mono frames.
- **Float Scaled**: normalizes standard SOF float pipelines to the internal full-scale float representation ($\pm 32768.0$) used during training.
Expand Down Expand Up @@ -41,11 +41,11 @@ graph TD
Backend -->|Scale back to ±1.0| Core
Core -->|Interleaved output| OutBuf[Output Audio Buffer]

VAD -->|Yes: 1 / No: 0| Notifier[NOTIFIER_ID_VAD Event]
VAD -->|Yes: 1 / No: 0| Log[Debug log of state changes]
```

### Components
- `webrtc_ns2.c`: Handles format conversions, period packing, and the VAD event notifier.
- `webrtc_ns2.c`: Handles format conversions, period packing, and the VAD decision.
- `webrtc_ns2-rnn.c`: Real RNNoise library integration backend.
- `webrtc_ns2-stub.c`: Pass-through stub that always outputs `1.0` VAD probability.
- `webrtc_ns2.cmake`: Controls downloading the `rnnoise` Git repository and building its files.
Expand Down Expand Up @@ -79,7 +79,7 @@ Requires `west update` to retrieve `modules/audio/rnnoise` (SHA `70f1d256`).
| `CONFIG_COMP_WEBRTC_NS2` | n | y / m / n | Enable RNNoise module |
| `CONFIG_COMP_WEBRTC_NS2_STUB` | y | y / n | Use pass-through stub |
| `CONFIG_WEBRTC_NS2_CHANNELS_MAX` | 2 | 1 - 8 | Maximum channels supported |
| `CONFIG_WEBRTC_NS2_VAD_NOTIFY` | y | y / n | Emit NOTIFIER_ID_VAD events |
| `CONFIG_WEBRTC_NS2_VAD_NOTIFY` | y | y / n | Make a VAD decision (logged only for now) |
| `CONFIG_WEBRTC_NS2_VAD_THRESHOLD_PCT` | 50 | 0 - 100 | VAD speech threshold percentage |

---
Expand Down
5 changes: 3 additions & 2 deletions src/audio/webrtc_ns2/webrtc_ns2.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
// accumulated until a full frame is ready.
//
// As a bonus, the per-frame VAD probability returned by RNNoise is
// compared against a configurable threshold and a NOTIFIER_ID_VAD event
// is fired, making this a drop-in combined denoiser + voice detector.
// compared against a configurable threshold. Delivering the decision to
// other components is not implemented yet: the module only logs changes
// at debug level.

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/audio_stream.h>
Expand Down
2 changes: 1 addition & 1 deletion src/audio/webrtc_ns2/webrtc_ns2.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* at 48 kHz in 480-sample (10 ms) mono frames. One RNNoise instance is
* allocated per channel and processes channel audio independently.
*
* In addition to denoising, the module broadcasts a NOTIFIER_ID_VAD event
* In addition to denoising, the module makes a voice activity decision
* from the per-frame speech probability returned by rnnoise_process_frame().
*/
#ifndef __SOF_AUDIO_WEBRTC_NS2_H__
Expand Down
7 changes: 4 additions & 3 deletions src/audio/webrtc_vad/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ config COMP_WEBRTC_VAD
Select to include the WebRTC Voice Activity Detection module. It
wraps the libfvad library (a standalone pure-C extraction of the
WebRTC GMM VAD) behind the SOF module interface. The module
inspects each 10/20/30 ms PCM frame and annotates it as speech or
non-speech via a NOTIFIER_ID_VAD notifier event, leaving the audio
stream unmodified (pass-through).
inspects each 10/20/30 ms PCM frame and classifies it as speech or
non-speech, leaving the audio stream unmodified (pass-through).
Delivering the decision to other components is not implemented
yet: the module only logs state changes at debug level.

libfvad supports 8, 16, 32 and 48 kHz; it resamples to 8 kHz
internally. The GMM classifier operates in Q15 fixed-point and
Expand Down
11 changes: 5 additions & 6 deletions src/audio/webrtc_vad/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Wraps [libfvad](https://github.com/dpirch/libfvad) — a standalone, pure-C, BSD

- **GMM Classifier**: Uses Gaussian Mixture Models (GMM) for robust speech vs. noise classification.
- **Pass-through Data Flow**: Does not modify PCM audio; passes it through untouched.
- **Notifier Integration**: Broadcasts binary speech/silence decisions (`1` or `0`) via SOF's `NOTIFIER_ID_VAD` event channel.
- **Speech/Silence Decision**: Makes a binary speech/silence decision (`1` or `0`) per frame. Delivering it to other components is not implemented yet: the module only logs state changes at debug level.
- **Low Power & Fixed-Point**: Operates entirely in Q15 fixed-point; requires no floating-point hardware (FPU).
- **Flexible Frame Sizes**: Supports 10 ms, 20 ms, and 30 ms classification frame windows.
- **Multichannel Support**: Classifies channel-0 and copies remaining channels.
Expand All @@ -18,7 +18,7 @@ Wraps [libfvad](https://github.com/dpirch/libfvad) — a standalone, pure-C, BSD

## Architecture & Data Flow

The following Mermaid diagram outlines how audio data flows through the pipeline and how the classification events are broadcast to other modules:
The following Mermaid diagram outlines how audio data flows through the pipeline and where the classification is made:

```mermaid
graph TD
Expand All @@ -31,9 +31,8 @@ graph TD
RingBuf -->|10/20/30 ms Block| Backend[webrtc_vad-fvad.c Backend]
Backend -->|libfvad GMM Classify| Decision{Speech Detected?}

%% Notifications
Decision -->|Yes: 1 / No: 0| Notifier[NOTIFIER_ID_VAD Event]
Notifier -->|.subscribe| SubscribedModules[e.g., webrtc_ns2, Host, KWD]
%% Decision (delivery to consumers not implemented yet)
Decision -->|Yes: 1 / No: 0| Log[Debug log of state changes]
```

### Components
Expand Down Expand Up @@ -85,7 +84,7 @@ The module functions as a simple 1-in / 1-out effect widget. Connect it directly
DAI Copier (Mic) ---> [ webrtc-vad ] ---> [ webrtc-ns ] ---> Host Copier
```

In this routing model, `webrtc-vad` runs first. Any downstream module or host application subscribing to the `NOTIFIER_ID_VAD` event will receive real-time classification changes instantly without querying the module adapter.
In this routing model, `webrtc-vad` runs first and classifies the audio before noise suppression.

---

Expand Down
2 changes: 1 addition & 1 deletion src/audio/webrtc_vad/webrtc_vad-stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This lets the SOF module glue (init/prepare/process/reset/free, the LLEXT
// manifest and topology wiring) be built and exercised in CI without pulling
// in libfvad. The stub always reports SPEECH (decision = 1) so audio flow
// and notifier events can be validated end-to-end. The real libfvad backend
// and the classification path can be validated end-to-end. The real libfvad backend
// lives in webrtc_vad-fvad.c and provides the same webrtc_vad_backend symbol.

#include <sof/audio/module_adapter/module/generic.h>
Expand Down
11 changes: 6 additions & 5 deletions src/audio/webrtc_vad/webrtc_vad.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
//
// The module is a pass-through PCM effect: audio flows from source to sink
// unmodified. On each complete VAD frame (10/20/30 ms at the configured
// rate), the module classifies channel-0 audio and broadcasts the binary
// speech/non-speech decision via NOTIFIER_ID_VAD so that downstream
// consumers (keyword detection gating, host-side VAD) can react.
// rate), the module classifies channel-0 audio into a binary
// speech/non-speech decision. Delivering the decision to consumers (keyword
// detection gating, host-side VAD) is not implemented yet: the module only
// logs state changes at debug level.
//
// Because the WebRTC VAD requires a fixed 10 ms frame size which may differ
// from the SOF pipeline period, the module accumulates incoming S16 samples
Expand Down Expand Up @@ -208,8 +209,8 @@ static void webrtc_vad_accumulate(struct webrtc_vad_comp_data *cd,
* webrtc_vad_classify_pending() - Drain the accumulator, classifying full frames.
* @mod: Pointer to the processing module.
*
* For each complete VAD frame accumulated, calls the backend and fires a
* NOTIFIER_ID_VAD event with the binary decision.
* For each complete VAD frame accumulated, calls the backend and logs
* changes of the binary decision.
*/
static void webrtc_vad_classify_pending(struct processing_module *mod)
{
Expand Down
6 changes: 3 additions & 3 deletions src/audio/webrtc_vad/webrtc_vad.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*
* Wraps libfvad — a standalone pure-C BSD-3 port of the WebRTC GMM VAD —
* behind the SOF module_interface. The module inspects each incoming PCM
* frame and emits a binary speech/non-speech decision as a SOF notifier
* event, leaving the audio data stream unmodified (pass-through).
* frame and makes a binary speech/non-speech decision, leaving the audio
* data stream unmodified (pass-through).
*
* The actual VAD work is delegated to a pluggable backend so the SOF glue
* can be validated with a dependency-free stub (webrtc_vad-stub.c) before
Expand All @@ -23,7 +23,7 @@
/* Maximum accumulation buffer: 30 ms at 48 kHz, one channel of int16. */
#define WEBRTC_VAD_MAX_FRAME_SAMPLES (30 * 48)

/* VAD decision values emitted via notifier. */
/* VAD decision values. */
#define WEBRTC_VAD_SILENCE 0
#define WEBRTC_VAD_SPEECH 1

Expand Down
1 change: 0 additions & 1 deletion src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ enum notify_id {
NOTIFIER_ID_DMA_COPY, /* struct dma_cb_data* */
NOTIFIER_ID_DMA_IRQ, /* struct dma_chan_data * */
NOTIFIER_ID_MIC_PRIVACY_STATE_CHANGE, /* struct mic_privacy_settings * */
NOTIFIER_ID_VAD, /* int * (WEBRTC_VAD_SPEECH / WEBRTC_VAD_SILENCE) */
NOTIFIER_ID_COUNT
};

Expand Down
3 changes: 0 additions & 3 deletions src/kernel/ipc/ipc3/dai.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,9 +399,6 @@ void dai_dma_release(struct dai_data *dd, struct comp_dev *dev)
/* put the allocated DMA channel first */
#ifdef CONFIG_ZEPHYR_NATIVE_DRIVERS
if (dd->chan_index >= 0) {
/* remove callback */
notifier_unregister(dev, &dd->dma->chan[dd->chan_index],
NOTIFIER_ID_DMA_COPY);
dma_release_channel(dd->dma->z_dev, dd->chan_index);
dd->chan_index = -EINVAL;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# SSP0 RX ──────(3)──> VAD + NS ──(4)──> PCM0 capture
#
# The VAD module fires NOTIFIER_ID_VAD events; the NS module removes
# The VAD module classifies speech/silence; the NS module removes
# stationary background noise. Both run on the same capture pipeline.
#
# Board: any cAVS/ACE platform with a nocodec SSP loopback fixture.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# RNNoise deep-learning noise suppressor widget (floating-point, 48 kHz).
# Single input, single output. Processes 480-sample (10 ms) frames.
# Also emits a per-frame VAD probability as a NOTIFIER_ID_VAD event.
# Also computes a per-frame VAD probability.
#
# IMPORTANT: pipeline sample rate MUST be 48000 Hz. Insert an ASRC
# upstream if the DAI runs at a different rate.
Expand Down
4 changes: 2 additions & 2 deletions tools/topology/topology2/include/components/webrtc-vad.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# Common widget webrtc-vad
#
# WebRTC libfvad Voice Activity Detector widget. Single input, single output.
# Passes PCM audio through while broadcasting a NOTIFIER_ID_VAD event each
# 10/20/30 ms frame with speech/silence classification.
# Passes PCM audio through while classifying each 10/20/30 ms frame as
# speech or silence.
#
# Usage:
# Object.Widget.webrtc-vad."N" {
Expand Down
Loading