Skip to content
Open
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
4 changes: 2 additions & 2 deletions src/audio/mfcc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ One build supports all output modes, selected at runtime by the configuration bl

AGC8 is a light alternative to PCAN without the per-channel noise estimate and the `tflite-micro` dependency. A single gain is added to all Q9.23 Mel log values of a hop. The gain attacks instantly to keep the hop peak at or below +1.0, and releases towards a target with a slower step when the VAD reports speech. The values are clamped to -1.0 .. +1.0 and converted to int8 Q1.7. The blob fields `agc_target`, `agc_floor` (Q8.7) and `agc_release`, `agc_release_speech` (Q9.23 per hop) set the parameters, zero selects the default.

The optional VAD (`enable_vad`) tracks a per-bin noise floor of the Q9.23 Mel log values, which follows the signal down instantly and rises slowly, and reports speech when the A-weighted mean of the values is more than a threshold above the A-weighted floor. In the Mel log and AGC8 modes the VAD sees the values after the `top_db` clamp, `mel_offset` and `mel_scale`, and uses `MFCC_VAD_ENERGY_THRESHOLD` (0.2). In the PCAN mode the output comes from the linear Mel energies, so the clamp, offset and scale are skipped and the VAD sees the unclamped natural log Mel power. It then uses `MFCC_VAD_ENERGY_THRESHOLD_PCAN` (2.2, i.e. 9.6 dB above the floor), which makes the decision independent of the input level. MicroWakeWord gates its detections with the VAD flag.
The optional VAD (`enable_vad`) tracks a per-bin noise floor of the Q9.23 Mel log values, which follows the signal down instantly and rises slowly, and reports speech when the A-weighted mean of the values is more than a threshold above the A-weighted floor. In the Mel log and AGC8 modes the VAD sees the values after the `top_db` clamp, `mel_offset` and `mel_scale`. The Mel log and cepstral modes use `MFCC_VAD_ENERGY_THRESHOLD` (0.30, i.e. 12 dB above the floor with the Whisper scaling) and the noise floor rise `MFCC_VAD_NOISE_RISE_ALPHA` (0.003 per hop). AGC8 uses `MFCC_VAD_ENERGY_THRESHOLD_AGC8` (0.20) and the slower rise `MFCC_VAD_NOISE_RISE_ALPHA_SLOW` (0.001 per hop). In the PCAN mode the output comes from the linear Mel energies, so the clamp, offset and scale are skipped and the VAD sees the unclamped natural log Mel power. It then uses `MFCC_VAD_ENERGY_THRESHOLD_PCAN` (2.2, i.e. 9.6 dB above the floor) and the slower rise, which makes the decision independent of the input level. MicroWakeWord gates its detections with the VAD flag.

---

Expand Down Expand Up @@ -90,7 +90,7 @@ octave-cli --eval "setup_mfcc"
Available presets generated:
- `ceps13_compress_dtx.conf`: 13-bin cepstral features with VAD and DTX silence suppression.
- `mel80_compress.conf`: 80-bin linear Mel spectrogram features.
- `mel80_compress_dtx.conf`: 80-bin Mel spectrogram with DTX gating.
- `mel80_compress_dtx.conf`: 80-bin Whisper Mel spectrogram with VAD, VAD control updates and DTX silence suppression, for the host speech-to-text scripts.
- `mel80_pcan_compress.conf`: 80-bin Mel spectrogram with Google PCAN dynamic AGC normalization.

---
Expand Down
40 changes: 38 additions & 2 deletions src/audio/mfcc/mfcc_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,11 @@ static void mfcc_prepare_output(struct mfcc_state *state, int num_ceps)
*
* Writes the pending data header (if any) followed by the pending
* int32_t Mel/cepstral payload into the sink as a contiguous blob,
* without zero padding. Every prepared hop is committed. VAD must not
* drop frames: the downstream streaming detector runs continuously.
* without zero padding. Every prepared hop is committed unless both
* VAD and DTX are enabled. With DTX, after the configured number of
* trailing silence hops, the VAD=0 hops are suppressed except for an
* optional periodic silence hop. The streaming wake-word blobs have DTX
* disabled because the detector must see every hop.
*
* \param[in,out] mod Processing module.
* \param[in,out] cd MFCC component data.
Expand All @@ -650,11 +653,44 @@ static int mfcc_output_compress(struct processing_module *mod, struct mfcc_comp_
uint8_t *dst;
int ret;
bool pending;
bool send_periodic;

pending = state->header_pending || state->out_remain > 0;
if (!pending)
return 0;

if (num_ceps > 0 && cd->config->enable_vad && !cd->vad.is_speech) {
state->vad_silence_count++;
/* With DTX enabled, send the configured number of trailing
* silence hops, then suppress. After the trailing hops,
* optionally send a periodic silence hop at the configured
* interval. This gives the host enough silence to detect the
* end of speech and keeps it updated during long silence.
* Without DTX, every hop is sent regardless of VAD.
*/
if (cd->config->enable_dtx &&
state->vad_silence_count > state->dtx_trailing_silence) {
send_periodic = false;
if (state->dtx_silence_interval > 0) {
state->dtx_silence_counter++;
if (state->dtx_silence_counter >= state->dtx_silence_interval) {
state->dtx_silence_counter = 0;
send_periodic = true;
}
}

if (!send_periodic) {
/* Suppress this hop */
state->header_pending = false;
state->out_remain = 0;
return 0;
}
}
} else {
state->vad_silence_count = 0;
state->dtx_silence_counter = 0;
}

size_t sample_size = mfcc_out_sample_size(state);

out_bytes = (state->header_pending ? sizeof(state->header) : 0) +
Expand Down
15 changes: 11 additions & 4 deletions src/audio/mfcc/mfcc_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,12 +474,19 @@ int mfcc_setup(struct processing_module *mod, int max_frames, int sample_rate, i
goto free_out_stage;
}

#if CONFIG_COMP_MFCC_PCAN
/* With PCAN the VAD sees the unclamped log Mel spectrum, see
* mfcc_stft_process(), so it needs its own threshold.
/* The PCAN and AGC8 modes use a slower noise floor rise and their
* own thresholds. With PCAN the VAD sees the unclamped log Mel
* spectrum, see mfcc_stft_process().
*/
if (config->enable_pcan)
if (config->enable_agc8) {
cd->vad.noise_rise_alpha_slow = MFCC_VAD_NOISE_RISE_ALPHA_SLOW;
cd->vad.energy_threshold = MFCC_VAD_ENERGY_THRESHOLD_AGC8;
}
#if CONFIG_COMP_MFCC_PCAN
if (config->enable_pcan) {
cd->vad.noise_rise_alpha_slow = MFCC_VAD_NOISE_RISE_ALPHA_SLOW;
cd->vad.energy_threshold = MFCC_VAD_ENERGY_THRESHOLD_PCAN;
}
#endif
}

Expand Down
23 changes: 20 additions & 3 deletions src/audio/mfcc/tune/setup_mfcc.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ function setup_mfcc()
export_mfcc_setup(gen_cfg, setup);

% Blob for mel spectrogram data
setup = get_mel_spectrogram_config();
setup = get_whisper_mel_config();
setup.tplg_fn = 'mel80.conf';
export_mfcc_setup(gen_cfg, setup);

% Blob for mel spectrogram with compress PCM output
setup = get_mel_spectrogram_config();
setup = get_whisper_mel_config();
setup.compress_output = true;
setup.tplg_fn = 'mel80_compress.conf';
export_mfcc_setup(gen_cfg, setup);
Expand Down Expand Up @@ -81,11 +81,13 @@ function setup_mfcc()
export_mfcc_setup(gen_cfg, setup);

% Blob for mel spectrogram with compress PCM output and DTX
setup = get_mel_spectrogram_config();
setup = get_whisper_mel_config();
setup.compress_output = true;
setup.enable_dtx = true;
setup.dtx_trailing_silence_hops = 20;
setup.dtx_silence_hops_interval = 500;
setup.comment = ['enable_vad=1 enable_dtx=1 update_controls=1: VAD flag for speech\n' ...
'# segmenting in the host ASR, DTX suppresses silence hops.'];
setup.tplg_fn = 'mel80_compress_dtx.conf';
export_mfcc_setup(gen_cfg, setup);

Expand Down Expand Up @@ -183,6 +185,21 @@ function setup_mfcc()
cfg.pcan_smoothing_coef = 819;
end

function cfg = get_whisper_mel_config()
% Whisper log Mel spectrogram: log10 of Mel power, clamp to the peak
% minus 8.0 (80 dB), then (x + 4.0) * 0.25. The clamp also keeps the
% VAD noise floor from following deep dips of noise in the narrow low
% Mel bands, so the VAD threshold 0.2 is 8 dB above the floor.
cfg = get_mel_spectrogram_config();
cfg.mel_log = 'log10';
cfg.top_db = 8.0;
cfg.mmax_coef = 0; % Zero locks mmax to the found peak
cfg.dynamic_mmax = true;
cfg.remove_dc_offset = false;
cfg.enable_vad = true;
cfg.update_controls = true;
end

function cfg = get_mel_spectrogram_config()
cfg.blackman_coef = 0;
cfg.cepstral_lifter = 0;
Expand Down
27 changes: 23 additions & 4 deletions src/include/sof/audio/mfcc/mfcc_vad.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,38 @@ struct processing_module;
#define MFCC_VAD_NOISE_INIT_FRAMES 100

/**
* \brief Slow noise floor rise coefficient in Q1.15 (0.001 * 2^15, tau ~10 s).
* \brief Slow noise floor rise coefficient in Q1.15 (0.003 * 2^15, tau ~3.3 s).
*
* Used in the Mel log and cepstral modes. The noise floor follows the signal
* down instantly, so a slower rise lets it drift towards the deepest per-bin
* dips of noise. With the 80-bin Whisper Mel spectrum and 0.001 the noise-only
* energy rose to 0.25 above the floor and kept the VAD active.
*/
#define MFCC_VAD_NOISE_RISE_ALPHA 98

/**
* \brief Slow noise floor rise coefficient with PCAN and AGC8 in Q1.15
* (0.001 * 2^15, tau ~10 s).
*/
#define MFCC_VAD_NOISE_RISE_ALPHA 33
#define MFCC_VAD_NOISE_RISE_ALPHA_SLOW 33

/**
* \brief Fast noise floor rise coefficient in Q1.15 (0.020 * 2^15).
*/
#define MFCC_VAD_NOISE_RISE_ALPHA_FAST 655

/**
* \brief Energy threshold for speech detection in Q9.23 (0.20 * 2^23).
* \brief Energy threshold for speech detection in Q9.23 (0.30 * 2^23).
*
* Used in the Mel log and cepstral modes. With the Whisper scaling
* (log10 Mel + 4.0) * 0.25 this is 12 dB above the tracked noise floor.
*/
#define MFCC_VAD_ENERGY_THRESHOLD 2516582

/**
* \brief Energy threshold for speech detection with AGC8 in Q9.23 (0.20 * 2^23).
*/
#define MFCC_VAD_ENERGY_THRESHOLD 1677722
#define MFCC_VAD_ENERGY_THRESHOLD_AGC8 1677722

/**
* \brief Energy threshold for speech detection with PCAN in Q9.23 (2.2 * 2^23).
Expand Down
12 changes: 6 additions & 6 deletions tools/topology/topology2/include/components/mfcc/mel80.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Exported MFCC configuration 16-Sep-2026
# Exported MFCC configuration 01-Dec-2026
# cd src/audio/mfcc/tune; octave setup_mfcc.m
Object.Base.data."mfcc_config" {
bytes "
Expand All @@ -7,18 +7,18 @@ Object.Base.data."mfcc_config" {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x74,0x00,0x00,0x00,0x00,0x02,0x00,0x04,
0x00,0x00,0xa4,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x33,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x3e,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x90,0x01,0xa0,0x00,0x40,0x1f,0x00,0x00,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x28,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x9a,0x79,
0x00,0x28,0x15,0x00,0x00,0x00,0x01,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x28,0x15,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x00,
0x00,0x00,0x00,0x00"
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Exported MFCC configuration 16-Sep-2026
# Exported MFCC configuration 01-Dec-2026
# cd src/audio/mfcc/tune; octave setup_mfcc.m
Object.Base.data."mfcc_config" {
bytes "
Expand All @@ -7,18 +7,18 @@ Object.Base.data."mfcc_config" {
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x74,0x00,0x00,0x00,0x00,0x02,0x00,0x04,
0x00,0x00,0xa4,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x33,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x3e,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x90,0x01,0xa0,0x00,0x40,0x1f,0x00,0x00,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x28,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x9a,0x79,
0x00,0x28,0x15,0x00,0x00,0x00,0x01,0x01,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x01,
0x00,0x28,0x15,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x01,0x01,0x00,0x01,0x01,
0x00,0x00,0x00,0x00"
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# Exported MFCC configuration 16-Sep-2026
# Exported MFCC configuration 01-Dec-2026
# cd src/audio/mfcc/tune; octave setup_mfcc.m
# enable_vad=1 enable_dtx=1 update_controls=1: VAD flag for speech
# segmenting in the host ASR, DTX suppresses silence hops.
Object.Base.data."mfcc_config" {
bytes "
0x53,0x4f,0x46,0x34,0x00,0x00,0x00,0x00,
0x74,0x00,0x00,0x00,0x01,0xd0,0x01,0x03,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x74,0x00,0x00,0x00,0x00,0x02,0x00,0x04,
0x00,0x00,0xa4,0x00,0x14,0x00,0xf4,0x01,
0x00,0x00,0x00,0x00,0x14,0x00,0xf4,0x01,
0x33,0x03,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x80,0x3e,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x03,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x90,0x01,0xa0,0x00,0x40,0x1f,0x00,0x00,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x28,
0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x04,
0x00,0x00,0x00,0x00,0x00,0x00,0x9a,0x79,
0x00,0x28,0x15,0x00,0x00,0x00,0x01,0x01,
0x01,0x00,0x00,0x00,0x00,0x01,0x00,0x01,
0x00,0x28,0x15,0x00,0x00,0x00,0x00,0x01,
0x01,0x00,0x00,0x01,0x01,0x01,0x01,0x01,
0x00,0x00,0x00,0x00"
}
Loading