From d71f511c33e1db642359c836095e473757f2d601 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 9 Nov 2026 14:41:07 +0200 Subject: [PATCH 01/12] math: export functions used by MFCC for LLEXT builds The MFCC component calls FFT, DCT, matrix, auditory, window and PCAN functions from the math library, but none of them were exported. With CONFIG_COMP_MFCC=m the module could not resolve these symbols when it was loaded. Export them, along with the two TFLM microfrontend functions that the PCAN inline helpers call, from SOF code since the TFLM sources are not modified. Also add the missing mfcc_vad.c and mfcc_ipc4.c to the MFCC LLEXT build so the module contains the same code as the built-in version. Signed-off-by: Seppo Ingalsuo --- src/audio/mfcc/llext/CMakeLists.txt | 2 ++ src/math/auditory/auditory.c | 4 ++++ src/math/auditory/mel_filterbank_32.c | 3 +++ src/math/dct.c | 2 ++ src/math/fft/fft_32.c | 2 ++ src/math/fft/fft_32_hifi3.c | 2 ++ src/math/fft/fft_common.c | 3 +++ src/math/matrix.c | 3 +++ src/math/pcan/pcan.c | 7 +++++++ src/math/window.c | 6 ++++++ 10 files changed, 34 insertions(+) diff --git a/src/audio/mfcc/llext/CMakeLists.txt b/src/audio/mfcc/llext/CMakeLists.txt index 0032f469c1ef..5799e5cdb416 100644 --- a/src/audio/mfcc/llext/CMakeLists.txt +++ b/src/audio/mfcc/llext/CMakeLists.txt @@ -8,6 +8,8 @@ sof_llext_build("mfcc" ../mfcc_generic.c ../mfcc_hifi3.c ../mfcc_hifi4.c + ../mfcc_vad.c ../mfcc_agc8.c + ../mfcc_ipc4.c LIB openmodules ) diff --git a/src/math/auditory/auditory.c b/src/math/auditory/auditory.c index 0abd10de9308..8359bbdff760 100644 --- a/src/math/auditory/auditory.c +++ b/src/math/auditory/auditory.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -62,6 +63,7 @@ int16_t psy_hz_to_mel(int16_t hz) mel = Q_MULTSR_32X32((int64_t)log, LOG_MULT_HZMEL_Q20, 26, 20, 2); return mel; } +EXPORT_SYMBOL(psy_hz_to_mel); /** * Convert Mel to Hz @@ -88,6 +90,7 @@ int16_t psy_mel_to_hz(int16_t mel) hz = Q_MULTSR_32X32((int64_t)exp, 700, 20, 0, 0); return hz; } +EXPORT_SYMBOL(psy_mel_to_hz); int mod_psy_get_mel_filterbank(struct processing_module *mod, struct psy_mel_filterbank *fb) { @@ -239,6 +242,7 @@ int mod_psy_get_mel_filterbank(struct processing_module *mod, struct psy_mel_fil fb->scratch_data2, sizeof(int16_t) * fb->data_length); return 0; } +EXPORT_SYMBOL(mod_psy_get_mel_filterbank); int mod_psy_free_mel_filterbank(struct processing_module *mod, struct psy_mel_filterbank *mel_fb) { diff --git a/src/math/auditory/mel_filterbank_32.c b/src/math/auditory/mel_filterbank_32.c index c496973f64a1..ed7b2fec5e58 100644 --- a/src/math/auditory/mel_filterbank_32.c +++ b/src/math/auditory/mel_filterbank_32.c @@ -10,6 +10,7 @@ #include #include #include +#include #include static inline uint32_t mel_sqrt32(uint32_t num) @@ -127,9 +128,11 @@ void psy_apply_mel_filterbank_with_linear_32(struct psy_mel_filterbank *fb, stru } } } +EXPORT_SYMBOL(psy_apply_mel_filterbank_with_linear_32); void psy_apply_mel_filterbank_32(struct psy_mel_filterbank *fb, struct icomplex32 *fft_out, int32_t *power_spectra, int32_t *mel_log, int bitshift) { psy_apply_mel_filterbank_with_linear_32(fb, fft_out, power_spectra, mel_log, NULL, bitshift); } +EXPORT_SYMBOL(psy_apply_mel_filterbank_32); diff --git a/src/math/dct.c b/src/math/dct.c index e4bbe5623dd8..0b5d5b96704f 100644 --- a/src/math/dct.c +++ b/src/math/dct.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -78,6 +79,7 @@ int mod_dct_initialize_16(struct processing_module *mod, struct dct_plan_16 *dct return 0; } +EXPORT_SYMBOL(mod_dct_initialize_16); int mod_dct_free_16(struct processing_module *mod, struct dct_plan_16 *dct) { diff --git a/src/math/fft/fft_32.c b/src/math/fft/fft_32.c index a6f8b2aa1ab3..fa68879317ba 100644 --- a/src/math/fft/fft_32.c +++ b/src/math/fft/fft_32.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #ifdef FFT_GENERIC @@ -93,5 +94,6 @@ void fft_execute_32(struct fft_plan *plan, bool ifft) } } } +EXPORT_SYMBOL(fft_execute_32); #endif /* FFT_GENERIC */ diff --git a/src/math/fft/fft_32_hifi3.c b/src/math/fft/fft_32_hifi3.c index 1d00dacd1b7f..a078187e1742 100644 --- a/src/math/fft/fft_32_hifi3.c +++ b/src/math/fft/fft_32_hifi3.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #ifdef FFT_HIFI3 @@ -156,4 +157,5 @@ void fft_execute_32(struct fft_plan *plan, bool ifft) } } } +EXPORT_SYMBOL(fft_execute_32); #endif diff --git a/src/math/fft/fft_common.c b/src/math/fft/fft_common.c index 589571881443..715bb9736815 100644 --- a/src/math/fft/fft_common.c +++ b/src/math/fft/fft_common.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "fft_common.h" @@ -103,6 +104,7 @@ struct fft_plan *mod_fft_plan_new(struct processing_module *mod, void *inb, fft_plan_init_bit_reverse(plan->bit_reverse_idx, plan->size, plan->len); return plan; } +EXPORT_SYMBOL(mod_fft_plan_new); void mod_fft_plan_free(struct processing_module *mod, struct fft_plan *plan) { @@ -112,3 +114,4 @@ void mod_fft_plan_free(struct processing_module *mod, struct fft_plan *plan) mod_free(mod, plan->bit_reverse_idx); mod_free(mod, plan); } +EXPORT_SYMBOL(mod_fft_plan_free); diff --git a/src/math/matrix.c b/src/math/matrix.c index e4c4c1ecbfff..f3d08a71f2d1 100644 --- a/src/math/matrix.c +++ b/src/math/matrix.c @@ -5,6 +5,7 @@ // Author: Seppo Ingalsuo #include +#include #include #include @@ -57,6 +58,7 @@ int mat_multiply(struct mat_matrix_16b *a, struct mat_matrix_16b *b, struct mat_ } return 0; } +EXPORT_SYMBOL(mat_multiply); int mat_multiply_elementwise(struct mat_matrix_16b *a, struct mat_matrix_16b *b, struct mat_matrix_16b *c) @@ -94,3 +96,4 @@ int mat_multiply_elementwise(struct mat_matrix_16b *a, struct mat_matrix_16b *b, return 0; } +EXPORT_SYMBOL(mat_multiply_elementwise); diff --git a/src/math/pcan/pcan.c b/src/math/pcan/pcan.c index e212a83e51fe..e7b1f7f4eb0f 100644 --- a/src/math/pcan/pcan.c +++ b/src/math/pcan/pcan.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -197,6 +198,7 @@ int pcan_populate_state(const struct pcan_config *config, struct pcan_state *sta return 0; } +EXPORT_SYMBOL(pcan_populate_state); void pcan_free_state(struct pcan_state *state) { @@ -232,3 +234,8 @@ void pcan_log_scale(struct pcan_state *state, uint32_t *signal) for (i = state->num_channels - 1; i >= 0; --i) signal[i] = scaled[i]; } +EXPORT_SYMBOL(pcan_log_scale); + +/* the TFLM microfrontend sources can't carry SOF symbol exports */ +EXPORT_SYMBOL(NoiseReductionApply); +EXPORT_SYMBOL(PcanGainControlApply); diff --git a/src/math/window.c b/src/math/window.c index 39739ef24be3..d43db99cc790 100644 --- a/src/math/window.c +++ b/src/math/window.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -41,6 +42,7 @@ void win_rectangular_16b(int16_t *win, int length) for (i = 0; i < length; i++) win[i] = WIN_ONE_Q15; } +EXPORT_SYMBOL(win_rectangular_16b); void win_rectangular_32b(int32_t *win, int length) { @@ -76,6 +78,7 @@ void win_blackman_16b(int16_t win[], int length, int16_t a0) win[n] = sat_int16(val); } } +EXPORT_SYMBOL(win_blackman_16b); void win_blackman_32b(int32_t win[], int length, int32_t a0) { @@ -118,6 +121,7 @@ void win_hann_16b(int16_t win[], int length) win[n] = sat_int16(val); } } +EXPORT_SYMBOL(win_hann_16b); void win_hann_32b(int32_t win[], int length) { @@ -152,6 +156,7 @@ void win_hamming_16b(int16_t win[], int length) win[n] = sat_int16(Q_SHIFT_RND(val, 30, 15)); } } +EXPORT_SYMBOL(win_hamming_16b); void win_hamming_32b(int32_t win[], int length) { @@ -195,3 +200,4 @@ void win_povey_16b(int16_t win[], int length) win[n] = sat_int16(Q_SHIFT_RND(x4, 20, 15)); } } +EXPORT_SYMBOL(win_povey_16b); From 249d67ddea34026b6903363ac563aa9ad438d3ae Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 9 Nov 2026 17:19:58 +0200 Subject: [PATCH 02/12] github: testbench: fetch TFLM microfrontend sources The testbench build enables MFCC with PCAN, which compiles the PCAN gain control, noise reduction and log scale sources from the TFLM microfrontend library. The testbench workflow only checks out the SOF repository, so these sources are missing and the build fails. Add a step that fetches only the microfrontend library directory of tflite-micro next to sof/, at the revision pinned in submanifests/tflm.yml, using a shallow sparse checkout. Signed-off-by: Seppo Ingalsuo --- .github/workflows/testbench.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/.github/workflows/testbench.yml b/.github/workflows/testbench.yml index 82e26470ff17..03f02f505f8c 100644 --- a/.github/workflows/testbench.yml +++ b/.github/workflows/testbench.yml @@ -47,6 +47,19 @@ jobs: with: path: sof + # MFCC with PCAN needs the TFLM microfrontend sources next to sof/, + # use the revision pinned in the west submanifest. + - name: Checkout TFLM microfrontend + run: | + rev=$(awk '/name: tflite-micro/ {f=1} f && /revision:/ {print $2; exit}' \ + sof/submanifests/tflm.yml) + git init tflite-micro + cd tflite-micro + git remote add origin https://github.com/tensorflow/tflite-micro + git sparse-checkout set tensorflow/lite/experimental/microfrontend/lib + git fetch --depth 1 --filter=blob:none origin "$rev" + git checkout FETCH_HEAD + # note: libasound-dev needed for testbench build which still # requires system ALSA headers to be present - name: apt get From 731bca071d9155746e34144ac88f05972675a575 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:15:08 +0200 Subject: [PATCH 03/12] lib: notifier: don't overwrite pending remote core events A remote core notification shares one notify_data slot per target core. If a previous event to that core is still queued, e.g. after a blocking IDC timeout, the next event would overwrite its payload. Mark the slot pending until the target core has run its callbacks and drop new events for a busy core with an error trace instead. The blocking IDC send is not allowed in interrupt context, so use a non-blocking send there. The posix build gets a k_is_in_isr() stub. Signed-off-by: Seppo Ingalsuo --- posix/include/rtos/kernel.h | 5 +++++ src/include/sof/lib/notifier.h | 1 + src/lib/notifier.c | 31 +++++++++++++++++++++++++++++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/posix/include/rtos/kernel.h b/posix/include/rtos/kernel.h index 9fa3962a3589..0b30f1628115 100644 --- a/posix/include/rtos/kernel.h +++ b/posix/include/rtos/kernel.h @@ -36,6 +36,11 @@ static inline bool thread_is_userspace(struct k_thread *thread) return false; } +static inline bool k_is_in_isr(void) +{ + return false; +} + static inline void k_sleep(k_timeout_t timeout) { wait_delay(timeout.ticks); diff --git a/src/include/sof/lib/notifier.h b/src/include/sof/lib/notifier.h index b4e5530f48ed..09aa020bed59 100644 --- a/src/include/sof/lib/notifier.h +++ b/src/include/sof/lib/notifier.h @@ -59,6 +59,7 @@ struct notify_data { enum notify_id type; uint32_t data_size; void *data; + bool pending; /* set by sender, cleared by target core after callbacks */ }; #ifdef CLK_SSP diff --git a/src/lib/notifier.c b/src/lib/notifier.c index cc15c6cd7a23..13151ac55778 100644 --- a/src/lib/notifier.c +++ b/src/lib/notifier.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -18,6 +19,7 @@ #include #include #include +#include #include LOG_MODULE_REGISTER(notifier, CONFIG_SOF_LOG_LEVEL); @@ -27,6 +29,7 @@ SOF_DEFINE_REG_UUID(notifier); DECLARE_TR_CTX(nt_tr, SOF_UUID(notifier_uuid), LOG_LEVEL_INFO); static struct notify_data notify_data_shared[CONFIG_CORE_COUNT]; +static struct k_spinlock notify_data_lock; struct callback_handle { void *receiver; @@ -155,6 +158,7 @@ void notifier_notify_remote(void) notify_data->data); } + notify_data->pending = false; } void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask, @@ -162,6 +166,8 @@ void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask, { struct notify_data *notify_data; struct idc_msg notify_msg = { IDC_MSG_NOTIFY, IDC_MSG_NOTIFY_EXT }; + k_spinlock_key_t key; + int ret; int i; /* notify selected targets */ @@ -172,6 +178,17 @@ void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask, } else if (cpu_is_core_enabled(i)) { notify_msg.core = i; notify_data = notify_data_get() + i; + + /* previous event to this core is still queued, don't overwrite it */ + key = k_spin_lock(¬ify_data_lock); + if (notify_data->pending) { + k_spin_unlock(¬ify_data_lock, key); + tr_err(&nt_tr, "core %d busy, event %d dropped", i, type); + continue; + } + notify_data->pending = true; + k_spin_unlock(¬ify_data_lock, key); + notify_data->caller = caller; notify_data->type = type; @@ -186,8 +203,16 @@ void notifier_event(const void *caller, enum notify_id type, uint32_t core_mask, /* Wait for completion: back-to-back events to the same core would * otherwise reuse a queued IDC work item and overwrite notify_data. + * Blocking is not allowed in ISR context. */ - idc_send_msg(¬ify_msg, IDC_BLOCKING); + ret = idc_send_msg(¬ify_msg, k_is_in_isr() ? + IDC_NON_BLOCKING : IDC_BLOCKING); + if (ret < 0) { + tr_err(&nt_tr, "event %d to core %d failed %d", type, i, ret); + /* on timeout the work stays queued and clears pending */ + if (ret == -EACCES) + notify_data->pending = false; + } } } } @@ -211,8 +236,10 @@ __cold void init_system_notify(struct sof *sof) for (i = NOTIFIER_ID_CPU_FREQ; i < NOTIFIER_ID_COUNT; i++) list_init(&(*notify)->list[i]); - if (cpu_get_id() == PLATFORM_PRIMARY_CORE_ID) + if (cpu_get_id() == PLATFORM_PRIMARY_CORE_ID) { + k_spinlock_init(¬ify_data_lock); sof->notify_data = notify_data_shared; + } } void free_system_notify(void) From ff41890201e0a576468620e9ade12fe4098a2204 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 04/12] ipc4: handler: use a static D0ix notifier payload The D0ix state notification is sent to all cores. If the blocking IDC to a remote core times out, the work item stays queued and the target core may read the payload later, after the stack frame of the sender is gone. Use two constant static payloads for the enter and exit cases instead of a stack variable. Signed-off-by: Seppo Ingalsuo --- src/ipc/ipc4/handler-kernel.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/ipc/ipc4/handler-kernel.c b/src/ipc/ipc4/handler-kernel.c index 8ec1974ec254..63e5e57f0596 100644 --- a/src/ipc/ipc4/handler-kernel.c +++ b/src/ipc/ipc4/handler-kernel.c @@ -330,12 +330,14 @@ __cold static int ipc4_module_process_d0ix(struct ipc4_message_request *ipc4) * prevent_power_gating is set on the way back to D0i0 and clear when the * host allows the DSP to power gate, i.e. when the host is going to sleep. */ - struct d0ix_state_notif notif = { - .entering = !d0ix.extension.r.prevent_power_gating, - }; + /* never modified, remote cores may read them after a blocking IDC timeout */ + static struct d0ix_state_notif notif_enter = { .entering = true }; + static struct d0ix_state_notif notif_exit = { .entering = false }; + struct d0ix_state_notif *notif = d0ix.extension.r.prevent_power_gating ? + ¬if_exit : ¬if_enter; notifier_event(NULL, NOTIFIER_ID_D0IX_STATE, NOTIFIER_TARGET_CORE_ALL_MASK, - ¬if, sizeof(notif)); + notif, sizeof(*notif)); return 0; } From 7700d4b11d32d6bb1795445ceb8ef113eb291833 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 05/12] ipc: ipc-helper: cancel pipeline task and check reset when freeing When a component is freed while still active, the pipeline task could keep running on the freed components. Cancel the pipeline schedule before stopping the component when the pipeline is active and owned by the current core. If the component reset fails, the component may still hold resources that the free would leave dangling. Log the failure and return an error instead of freeing the component. Signed-off-by: Seppo Ingalsuo --- src/ipc/ipc-helper.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/ipc/ipc-helper.c b/src/ipc/ipc-helper.c index 50219fb1b8b0..593a78c54a5a 100644 --- a/src/ipc/ipc-helper.c +++ b/src/ipc/ipc-helper.c @@ -311,9 +311,24 @@ __cold int ipc_comp_free(struct ipc *ipc, uint32_t comp_id) /* check state: if not ready, stop and reset to release resources before freeing */ if (icd->cd->state != COMP_STATE_READY) { - if (icd->cd->state == COMP_STATE_ACTIVE) + struct pipeline *p = icd->cd->pipeline; + int ret; + + if (icd->cd->state == COMP_STATE_ACTIVE) { + /* the pipeline task would otherwise keep running on freed components */ + if (p && p->status == COMP_STATE_ACTIVE && cpu_is_me(p->core)) { + pipeline_schedule_cancel(p); + p->status = COMP_STATE_PAUSED; + } comp_trigger(icd->cd, COMP_TRIGGER_STOP); - comp_reset(icd->cd); + } + + ret = comp_reset(icd->cd); + if (ret) { + tr_err(&ipc_tr, "comp id: 0x%x reset failed %d, cannot be freed", + comp_id, ret); + return ret < 0 ? ret : -EBUSY; + } comp_set_state(icd->cd, COMP_TRIGGER_RESET); } From 9e3295f128bcade778cb078e60c352256264f25a Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 06/12] audio: module_adapter: refine sink checks in prepare A sink/source mode module may have no data consumer, e.g. a detector bound to a virtual sink, so don't fail its prepare for a missing sink. A module needs at least a source when it has no sink, and a raw data module still needs a sink because its buffering is sized from the sink period. Reject those cases with an error. Signed-off-by: Seppo Ingalsuo --- src/audio/module_adapter/module_adapter.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/audio/module_adapter/module_adapter.c b/src/audio/module_adapter/module_adapter.c index 1c68d50d052e..0426d5d23f33 100644 --- a/src/audio/module_adapter/module_adapter.c +++ b/src/audio/module_adapter/module_adapter.c @@ -522,14 +522,24 @@ int module_adapter_prepare(struct comp_dev *dev) * Hence check for NULL. */ sink = comp_dev_get_first_data_consumer(dev); - if (!sink && !list_is_empty(&dev->bsink_list) && mod->max_sinks) { + if (!sink && !IS_PROCESSING_MODE_SINK_SOURCE(mod) && !list_is_empty(&dev->bsink_list) && mod->max_sinks) { comp_err(dev, "no sink present on period size calculation"); return -EINVAL; } + /* A sinkless module still needs at least one source. */ + if (!sink && !comp_dev_get_first_data_producer(dev)) { + comp_err(dev, "no source or sink buffer connected"); + return -EINVAL; + } + if (sink) { mod->period_bytes = audio_stream_period_bytes(&sink->stream, dev->frames); comp_dbg(dev, "got period_bytes = %u", mod->period_bytes); + } else if (IS_PROCESSING_MODE_RAW_DATA(mod)) { + /* raw data buffering is sized from the sink period */ + comp_err(dev, "raw data module has no sink"); + return -EINVAL; } /* no more to do for sink/source mode */ From 3f13f63d82a818a2a5dec21ed61566825b113a99 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 07/12] audio: mfcc: agc8: avoid overflow in gain addition The AGC gain and the Mel value are both Q9.23 and their sum can overflow 32 bits before clipping. Do the attack limit and the gain addition with a 64-bit intermediate. Signed-off-by: Seppo Ingalsuo --- src/audio/mfcc/mfcc_agc8.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/audio/mfcc/mfcc_agc8.c b/src/audio/mfcc/mfcc_agc8.c index 854977372111..90f1b19dc936 100644 --- a/src/audio/mfcc/mfcc_agc8.c +++ b/src/audio/mfcc/mfcc_agc8.c @@ -36,7 +36,7 @@ void mfcc_agc8_process(struct mfcc_agc8 *agc, const int32_t *mel, int8_t *out, i { int32_t peak = mel[0]; int32_t gain; - int32_t v; + int64_t v; int i; for (i = 1; i < n; i++) { @@ -45,14 +45,14 @@ void mfcc_agc8_process(struct mfcc_agc8 *agc, const int32_t *mel, int8_t *out, i } /* Attack: instantly keep the hop peak at or below +1.0 */ - if (agc->gain > MFCC_AGC8_CLIP_MAX_Q23 - peak) + if (agc->gain > (int64_t)MFCC_AGC8_CLIP_MAX_Q23 - peak) agc->gain = MFCC_AGC8_CLIP_MAX_Q23 - peak; if (agc->gain < agc->floor) agc->gain = agc->floor; gain = agc->gain; for (i = 0; i < n; i++) { - v = mel[i] + gain; + v = (int64_t)mel[i] + gain; if (v > MFCC_AGC8_CLIP_MAX_Q23) v = MFCC_AGC8_CLIP_MAX_Q23; else if (v < MFCC_AGC8_CLIP_MIN_Q23) From 9bb20580ecf4dafdffe27cb0d437ed286149fcf2 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 08/12] topology2: nocodec: use slot 0 pipeline ID for the arbiter binding The WoV arbiter input pin binding for the slot 0 detector was hardcoded as mww.111.1. Use the WOV_SLOT0_PIPELINE_ID variable so the binding follows the pipeline definition. Signed-off-by: Seppo Ingalsuo --- tools/topology/topology2/cavs-nocodec-wov.conf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/topology/topology2/cavs-nocodec-wov.conf b/tools/topology/topology2/cavs-nocodec-wov.conf index 6a595bb0969b..ea4c20d7916d 100644 --- a/tools/topology/topology2/cavs-nocodec-wov.conf +++ b/tools/topology/topology2/cavs-nocodec-wov.conf @@ -590,7 +590,7 @@ Object.Pipeline."custom-capture" [ input_pin_binding_name "kpb.116.1" } Object.Base.input_pin_binding.2 { - input_pin_binding_name "mww.111.1" + input_pin_binding_name "mww.$WOV_SLOT0_PIPELINE_ID.1" } Object.Base.input_audio_format [ From 67f8c9b8c86b38e8cdedcc2f1d9990ba9c37b485 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Thu, 26 Nov 2026 16:48:15 +0200 Subject: [PATCH 09/12] audio: kpb: unregister notifiers on prepare failure The KPB registers for client and WoV control notifications in prepare but left them registered when prepare failed after the registration, so a stale callback could still run on a component that is not ready. Unregister them with a new helper on all error paths after the registration: the history buffer allocation, the cross-pipeline detector prepare and the sink search failures. Detector components include kpb.h also in builds without the KPB, so give KPB_MAX_NO_OF_CLIENTS a fallback value when the Kconfig option is not set. Also clarify the buffer time parameter unit. Signed-off-by: Seppo Ingalsuo --- src/audio/kpb.c | 28 ++++++++++++++++++++++++++-- src/include/ipc4/kpb.h | 2 +- src/include/sof/audio/kpb.h | 5 +++++ 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/audio/kpb.c b/src/audio/kpb.c index 2bbd906c7776..7a783a8bf147 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -812,6 +812,22 @@ static int kpb_params(struct comp_dev *dev, return 0; } +/** + * \brief Unregister the KPB from the client and WoV control notifications. + * + * Used when kpb_prepare() fails after the registration, so that no + * notification callback runs on a KPB that is not prepared. + * + * \param[in] dev KPB component device. + */ +static void kpb_unregister_notifiers(struct comp_dev *dev) +{ +#ifndef CONFIG_AMS + notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); + notifier_unregister(dev, NULL, NOTIFIER_ID_WOV_CTRL); +#endif +} + /** * \brief Prepare key phrase buffer. * \param[in] dev - kpb component device pointer. @@ -920,6 +936,7 @@ static int kpb_prepare(struct comp_dev *dev) #endif /* CONFIG_AMS */ if (ret < 0) { + kpb_unregister_notifiers(dev); kpb_free_history_buffer(kpb->hd.c_hb); kpb->hd.c_hb = NULL; return -ENOMEM; @@ -964,7 +981,7 @@ static int kpb_prepare(struct comp_dev *dev) ret = comp_prepare(sink_comp); if (ret < 0) { comp_err(dev, "kpb_prepare: cross-pipeline prepare of wov detector failed: %d", ret); - return ret; + goto err; } } } @@ -1054,7 +1071,7 @@ static int kpb_prepare(struct comp_dev *dev) dev_comp_id(sink_comp), sink_comp->state); if (ret < 0) { comp_err(dev, "kpb_prepare: cross-pipeline prepare failed: %d", ret); - return ret; + goto err; } } } @@ -1063,6 +1080,13 @@ static int kpb_prepare(struct comp_dev *dev) kpb_change_state(kpb, KPB_STATE_RUN); + if (ret < 0) + goto err; + + return ret; + +err: + kpb_unregister_notifiers(dev); return ret; } diff --git a/src/include/ipc4/kpb.h b/src/include/ipc4/kpb.h index aa33f0909994..a50ea7383a10 100644 --- a/src/include/ipc4/kpb.h +++ b/src/include/ipc4/kpb.h @@ -24,7 +24,7 @@ struct ipc4_kpb_module_cfg { enum ipc4_kpb_module_config_params { /*! Configure the module ID's which would be part of the Fast mode tasks */ KP_BUF_CFG_FM_MODULE = 1, - /*! Set history ring-buffer duration; 0 = use CONFIG_KPB_MAX_BUFF_TIME */ + /*! Set history ring-buffer duration in milliseconds; 0 = use CONFIG_KPB_MAX_BUFF_TIME */ KP_BUF_CFG_BUFF_TIME_MS = 2, /* Mic selector for client - sets microphone id for real time sink mic selector * IPC4-compatible ID - please do not change the number diff --git a/src/include/sof/audio/kpb.h b/src/include/sof/audio/kpb.h index bfbd4ab2a332..4e561e6ce990 100644 --- a/src/include/sof/audio/kpb.h +++ b/src/include/sof/audio/kpb.h @@ -37,7 +37,12 @@ struct comp_dev *get_wov_detector_comp(uint32_t ppl_id); #define KPB_MAX_BUFFER_SIZE(sw, channels_number) ((KPB_SAMPLNG_FREQUENCY / 1000) * \ (KPB_SAMPLE_CONTAINER_SIZE(sw) / 8) * KPB_MAX_BUFF_TIME * \ (channels_number)) +#ifdef CONFIG_KPB_MAX_NO_OF_CLIENTS #define KPB_MAX_NO_OF_CLIENTS CONFIG_KPB_MAX_NO_OF_CLIENTS +#else +/* header is also included by detectors in builds without KPB */ +#define KPB_MAX_NO_OF_CLIENTS 4 +#endif #define KPB_MAX_SINK_CNT (1 + KPB_MAX_NO_OF_CLIENTS) #define KPB_NO_OF_HISTORY_BUFFERS 2 /**< no of internal buffers */ #define KPB_ALLOCATION_STEP 0x100 From 75a344b6f476adb5dd64bc2f6477c3370967198a Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:30 +0200 Subject: [PATCH 10/12] math: select SQRT_FIXED for 32-bit Mel filterbank The 32-bit Mel filterbank computes magnitudes with the fixed-point square root, so select SQRT_FIXED to avoid a link failure when no other user enables it. Signed-off-by: Seppo Ingalsuo --- src/math/Kconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/src/math/Kconfig b/src/math/Kconfig index 934a6a9776e6..b55a6b0b34ce 100644 --- a/src/math/Kconfig +++ b/src/math/Kconfig @@ -279,6 +279,7 @@ config MATH_16BIT_MEL_FILTERBANK config MATH_32BIT_MEL_FILTERBANK bool "icomplex32 data support" default n + select SQRT_FIXED help This option enables function psy_apply_mel_filterbank_32(). It takes as input an array of icomplex32 From 86504bdaf7f79210aca14c299e601727a4bca417 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:30 +0200 Subject: [PATCH 11/12] math: pcan: document all gain lookup parameters Add the missing Doxygen parameter and return value descriptions for pcan_gain_lookup_function() and pcan_compute_lut(). Signed-off-by: Seppo Ingalsuo --- src/include/sof/math/pcan.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/include/sof/math/pcan.h b/src/include/sof/math/pcan.h index 4320210da89a..a326502470cd 100644 --- a/src/include/sof/math/pcan.h +++ b/src/include/sof/math/pcan.h @@ -91,6 +91,10 @@ static inline uint32_t pcan_shrink(uint32_t x) * * \param strength Exponent alpha in Q1.15. * \param offset Additive offset delta in Q8.7. + * \param gain_bits Number of fractional bits in the returned gain. + * \param input_bits Number of fractional bits in the input energy x. + * \param x Smoothed noise energy estimate. + * \return Gain value with gain_bits fractional bits. */ int16_t pcan_gain_lookup_function(int32_t strength, int32_t offset, int32_t gain_bits, int32_t input_bits, uint32_t x); @@ -100,6 +104,10 @@ int16_t pcan_gain_lookup_function(int32_t strength, int32_t offset, int32_t gain * * \param strength Exponent alpha in Q1.15. * \param offset Additive offset delta in Q8.7. + * \param gain_bits Number of fractional bits in the gain values. + * \param input_bits Number of fractional bits in the input energy. + * \param gain_lut Output table of PCAN_LUT_SIZE entries. + * \return 0 on success, -EINVAL if gain_lut is NULL. */ int pcan_compute_lut(int32_t strength, int32_t offset, int32_t gain_bits, int32_t input_bits, int16_t *gain_lut); From e9e0a4026bd205518899e6fa7d9207c11ff51750 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:47 +0200 Subject: [PATCH 12/12] audio: cmake: add wov_arbiter after the codec directory Keep the existing DTS codec entry in place and add the wov_arbiter subdirectory after it, so the WoV change does not reorder unrelated lines. Signed-off-by: Seppo Ingalsuo --- src/audio/CMakeLists.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index cf9b8edd584b..f6e91d322876 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -113,12 +113,12 @@ if(NOT CONFIG_COMP_MODULE_SHARED_LIBRARY_BUILD) if(CONFIG_COMP_VOLUME) add_subdirectory(volume) endif() - if(CONFIG_COMP_WOV_ARBITER) - add_subdirectory(wov_arbiter) - endif() if(CONFIG_DTS_CODEC) add_subdirectory(codec) endif() + if(CONFIG_COMP_WOV_ARBITER) + add_subdirectory(wov_arbiter) + endif() # end of directories and files included conditionally (alphabetical order) add_subdirectory(google)