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
13 changes: 13 additions & 0 deletions .github/workflows/testbench.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions posix/include/rtos/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/audio/ecns/ecns.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 12 additions & 5 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/audio/mfcc/llext/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
6 changes: 3 additions & 3 deletions src/audio/mfcc/mfcc_agc8.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand All @@ -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)
Expand Down
12 changes: 11 additions & 1 deletion src/audio/module_adapter/module_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
2 changes: 2 additions & 0 deletions src/audio/wov_arbiter/wov_arbiter.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/include/ipc4/kpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/include/sof/audio/kpb.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/include/sof/audio/wov_arbiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/include/sof/lib/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions src/include/sof/math/pcan.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
19 changes: 17 additions & 2 deletions src/ipc/ipc-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
10 changes: 6 additions & 4 deletions src/ipc/ipc4/handler-kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
&notif_exit : &notif_enter;

notifier_event(NULL, NOTIFIER_ID_D0IX_STATE, NOTIFIER_TARGET_CORE_ALL_MASK,
&notif, sizeof(notif));
notif, sizeof(*notif));

return 0;
}
Expand Down
31 changes: 29 additions & 2 deletions src/lib/notifier.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <rtos/interrupt.h>
#include <rtos/alloc.h>
#include <rtos/cache.h>
#include <rtos/kernel.h>
#include <sof/lib/cpu.h>
#include <sof/lib/memory.h>
#include <sof/lib/notifier.h>
Expand All @@ -18,6 +19,7 @@
#include <rtos/sof.h>
#include <rtos/symbol.h>
#include <ipc/topology.h>
#include <errno.h>
#include <stdint.h>

LOG_MODULE_REGISTER(notifier, CONFIG_SOF_LOG_LEVEL);
Expand All @@ -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;
Expand Down Expand Up @@ -155,13 +158,16 @@ 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,
void *data, uint32_t data_size)
{
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 */
Expand All @@ -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(&notify_data_lock);
if (notify_data->pending) {
k_spin_unlock(&notify_data_lock, key);
tr_err(&nt_tr, "core %d busy, event %d dropped", i, type);
continue;
}
notify_data->pending = true;
k_spin_unlock(&notify_data_lock, key);

notify_data->caller = caller;
notify_data->type = type;

Expand All @@ -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(&notify_msg, IDC_BLOCKING);
ret = idc_send_msg(&notify_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;
}
}
}
}
Expand All @@ -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(&notify_data_lock);
sof->notify_data = notify_data_shared;
}
}

void free_system_notify(void)
Expand Down
1 change: 1 addition & 0 deletions src/math/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Loading