From b5130087aec920ee79666e342a2637d683f1e689 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Tue, 17 Nov 2026 14:59:18 +0200 Subject: [PATCH 01/15] audio: wov_arbiter: number enum control IDs from zero The kernel numbers the enum controls of a widget from zero in topology order, and uses that index as the control ID in IPC4 control messages and notifications. The arbiter expected IDs 1 and 2 for the Phrase Detect ID and WoV Call State controls, so the kernel's Phrase Detect ID (0) was rejected and every WoV PCM failed in prepare. Use IDs 0 and 1 to match the kernel. This also makes the control change notifications from the arbiter update the right host control. Signed-off-by: Seppo Ingalsuo --- src/include/sof/audio/wov_arbiter.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/include/sof/audio/wov_arbiter.h b/src/include/sof/audio/wov_arbiter.h index 0dff468fd275..b6565a42c0c7 100644 --- a/src/include/sof/audio/wov_arbiter.h +++ b/src/include/sof/audio/wov_arbiter.h @@ -12,9 +12,9 @@ /* Sentinel: no slot is currently draining. */ #define WOV_ARB_NO_ACTIVE 0xff -/** Host enum control IDs exposed by the WoV arbiter topology. */ -#define WOV_ARB_ACTIVE_SLOT_CONTROL_ID 1 -#define WOV_ARB_CALL_STATE_CONTROL_ID 2 +/** Host enum control IDs, the kernel numbers enums of a widget from 0. */ +#define WOV_ARB_ACTIVE_SLOT_CONTROL_ID 0 +#define WOV_ARB_CALL_STATE_CONTROL_ID 1 /** Values of the host WoV call-state enum control. */ #define WOV_ARB_CALL_STATE_LISTENING 0 From 2b42aee6cd3679c6ae8c61f40df668b236d0c1a1 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 9 Nov 2026 14:41:07 +0200 Subject: [PATCH 02/15] 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 89a1326620ad1adb5fd49fb0e6af0f292749d2d7 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Mon, 9 Nov 2026 17:19:58 +0200 Subject: [PATCH 03/15] 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 5453749a9a8488b84e186e07d32f1ec7239b8cd2 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:15:08 +0200 Subject: [PATCH 04/15] 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 7965a394ec62918131b5fd8394f95d07d8cccd19 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 05/15] 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 659e22eb0960363593d0635a13a29382e4128820 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 06/15] 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 f62594ae44ab71c63afca91ff386476b4cd89de9 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 07/15] 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 bc21a35d28c3650efec3ccfcf8e234daea72e967 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 08/15] 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 6622ddd377d596e4508d58c6f5c88780520bcbea Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:17:37 +0200 Subject: [PATCH 09/15] 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 76935cfbbbb1c41937ddfaf3c25264fe0003cd4a Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:15 +0200 Subject: [PATCH 10/15] audio: kpb: unregister notifiers on prepare failure and reset The KPB registers for client and WoV control notifications in prepare but left them registered when prepare failed or the component was reset, so a stale callback could still run on a component that is not ready. Unregister them on both paths. 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 drop a duplicate sink declaration in the IPC3 prepare path, use the right format for the size_t copy size trace and clarify the buffer time parameter unit. Signed-off-by: Seppo Ingalsuo --- src/audio/kpb.c | 17 ++++++++++++----- src/include/ipc4/kpb.h | 2 +- src/include/sof/audio/kpb.h | 5 +++++ 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/audio/kpb.c b/src/audio/kpb.c index ed75ff59cb53..085a3e062615 100644 --- a/src/audio/kpb.c +++ b/src/audio/kpb.c @@ -387,9 +387,9 @@ static int kpb_bind(struct comp_dev *dev, const struct bind_info *bind_data) sink_buf_id = buf_get_id(sink); if (sink_buf_id == buf_id) { - struct comp_dev *sc = comp_buffer_get_sink_component(sink); comp_dbg(dev, "kpb_bind: buf_id=%d sink_comp=0x%x -> %s", - buf_id, sc ? dev_comp_id(sc) : 0, sink_buf_id == 0 ? "sel_sink" : "host_sink"); + buf_id, dev_comp_id(comp_buffer_get_sink_component(sink)), + sink_buf_id == 0 ? "sel_sink" : "host_sink"); if (sink_buf_id == 0) kpb->sel_sink = sink; else @@ -920,6 +920,10 @@ static int kpb_prepare(struct comp_dev *dev) #endif /* CONFIG_AMS */ if (ret < 0) { +#ifndef CONFIG_AMS + notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); + notifier_unregister(dev, NULL, NOTIFIER_ID_WOV_CTRL); +#endif kpb_free_history_buffer(kpb->hd.c_hb); kpb->hd.c_hb = NULL; return -ENOMEM; @@ -975,8 +979,6 @@ static int kpb_prepare(struct comp_dev *dev) * NOTE! We assume here that channel selector component device * is connected to the KPB sinks as well as host device. */ - struct comp_buffer *sink; - comp_dev_for_each_consumer(dev, sink) { enum sof_comp_type type; @@ -1165,6 +1167,11 @@ static int kpb_reset(struct comp_dev *dev) kpb_reset_history_buffer(kpb->hd.c_hb); } +#ifndef CONFIG_AMS + /* Unregister KPB from notifications */ + notifier_unregister(dev, NULL, NOTIFIER_ID_KPB_CLIENT_EVT); + notifier_unregister(dev, NULL, NOTIFIER_ID_WOV_CTRL); +#endif /* Finally KPB is ready after reset */ kpb_change_state(kpb, KPB_STATE_PREPARING); @@ -1465,7 +1472,7 @@ static int kpb_copy(struct comp_dev *dev) struct comp_dev *wov_comp = sink ? comp_buffer_get_sink_component(sink) : NULL; if (wov_comp) { - comp_dbg(dev, "kpb_copy: produced=%u bytes, triggering wov=0x%x", + comp_dbg(dev, "kpb_copy: produced=%zu bytes, triggering wov=0x%x", copy_bytes, dev_comp_id(wov_comp)); comp_copy(wov_comp); } else { 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 bfc6d0d09320bf4a7b6ee0c96693227f6b5d817e Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:30 +0200 Subject: [PATCH 11/15] audio: ecns, wov_arbiter: set trace context only without Zephyr log With Zephyr logging the component drivers don't use the SOF trace context, matching the other modules. Set .tctx only when CONFIG_ZEPHYR_LOG is disabled. Signed-off-by: Seppo Ingalsuo --- src/audio/ecns/ecns.c | 2 ++ src/audio/wov_arbiter/wov_arbiter.c | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/audio/ecns/ecns.c b/src/audio/ecns/ecns.c index bc61d4c17f27..722b0e0eb364 100644 --- a/src/audio/ecns/ecns.c +++ b/src/audio/ecns/ecns.c @@ -1170,7 +1170,9 @@ static int ecns_get_large_config(struct comp_dev *dev, static const struct comp_driver ecns_drv = { .type = SOF_COMP_NONE, .uid = SOF_RT_UUID(ecns_uuid), +#if !CONFIG_ZEPHYR_LOG .tctx = &ecns_tr, +#endif .ops = { .create = ecns_new, .free = ecns_free, diff --git a/src/audio/wov_arbiter/wov_arbiter.c b/src/audio/wov_arbiter/wov_arbiter.c index 975421040d28..429692d3fda4 100644 --- a/src/audio/wov_arbiter/wov_arbiter.c +++ b/src/audio/wov_arbiter/wov_arbiter.c @@ -783,7 +783,9 @@ static int wov_arb_get_large_config(struct comp_dev *dev, static const struct comp_driver wov_arbiter_drv = { .type = SOF_COMP_KEYWORD_DETECT, .uid = SOF_RT_UUID(wov_arbiter_uuid), +#if !CONFIG_ZEPHYR_LOG .tctx = &wov_arbiter_tr, +#endif .ops = { .create = wov_arb_new, .free = wov_arb_free, From 29eb97ab0313fc37de1807ecf961514076550fbf Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:30 +0200 Subject: [PATCH 12/15] 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 9b9953485af70af0606eb1a8b319050f877b5503 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:30 +0200 Subject: [PATCH 13/15] 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 7765c5c46210433578313397cf9d5bc395c68bcf Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:47 +0200 Subject: [PATCH 14/15] zephyr: cmake: use CONFIG_XTENSA for the Xtensa compiler options Check the Kconfig symbol instead of the ARCH string when adding the -mlongcalls and -mtext-section-literals options, consistent with the rest of the file. Signed-off-by: Seppo Ingalsuo --- zephyr/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index a790edf262f1..4bdd98be94c7 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -674,7 +674,7 @@ if (NOT CONFIG_COMPILER_INLINE_FUNCTION_OPTION) target_compile_options(SOF INTERFACE -fno-inline-functions) endif() -if (ARCH STREQUAL "xtensa") +if (CONFIG_XTENSA) target_compile_options(SOF INTERFACE -mlongcalls) zephyr_compile_options(-mtext-section-literals) endif() From 09f208207358da7f20ca1a38e3627160776b7e12 Mon Sep 17 00:00:00 2001 From: Seppo Ingalsuo Date: Fri, 13 Nov 2026 12:18:47 +0200 Subject: [PATCH 15/15] 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)