Skip to content
Closed
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
2 changes: 2 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ if(NOT BUILD_HOST)
pipeline_static.c
component.c
buffer.c
kpb.c
kp_detector.c
)
if(CONFIG_COMP_VOLUME)
add_local_sources(sof
Expand Down
28 changes: 28 additions & 0 deletions src/audio/kp_detector.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include <sof/audio/kp_detector.h>
#include <sof/audio/component.h>

void kp_dummy_func(void);
struct comp_data dummy_cd;

/* copy and process stream data from source to sink buffers */
static int kp_detector_copy(struct comp_dev *dev)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to be a dummy test code, a final version should be part of kp-detector commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I was thinking about merging this code with kp_detector once its PR is accepted.

{
struct comp_data *cd = &dummy_cd;

/*...*/
/* key phrase detected */
cd->notify_data.id = NOTIFIER_ID_KEY_PHRASE_DETECTED;
cd->notify_data.data_size = sizeof(struct kp_data);
cd->notify_data.data = &cd->data;
/*...*/
/* triger async notification */
notifier_event(&cd->notify_data);

return 0;
}

void kp_dummy_func(void)
{
kp_detector_copy(NULL);
}

43 changes: 43 additions & 0 deletions src/audio/kpb.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <sof/audio/kpb.h>
#include <sof/audio/component.h>

static struct comp_dev *kpb_new(struct sof_ipc_comp *comp);
static void kpb_set_draining_params(int message, void *cb_data,
void *event_data);
void kpb_dummy_func(void);
struct comp_data dummy_cd;
struct comp_dev dummy_dev;

static struct comp_dev *kpb_new(struct sof_ipc_comp *comp)
{
struct comp_dev *dev = &dummy_dev;
struct comp_data *cd = &dummy_cd;

/* prepare async notifier for key phrase detection */
cd->kpb_notifier.id = NOTIFIER_ID_KEY_PHRASE_DETECTED;
cd->kpb_notifier.cb_data = cd;
cd->kpb_notifier.cb = kpb_set_draining_params;

/* register KPB for async notification */
notifier_register(&cd->kpb_notifier);

return dev;
}

static void kpb_set_draining_params(int message, void *cb_data,
void *event_data)
{
(void)message; /* not used */
struct comp_data *cd = (struct comp_data *)cb_data;
struct kp_data *data = (struct kp_data *)event_data;

/* update sink data */
cd->data.kp_begin = data->kp_begin;
cd->data.kp_end = data->kp_end;
}

void kpb_dummy_func(void)
{
kpb_new(NULL);
kpb_set_draining_params(0, NULL, NULL);
}
6 changes: 6 additions & 0 deletions src/include/sof/audio/kp_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <stdint.h>

struct kp_data {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anything that is part of kpbuf public interface (internal to other fw components/units) may go to kpb.h or kpb_public.h (the latter follows current organization where the .h headers declare rather private data).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kp_common.h, or kpb_public.h as you suggested has the same intention - provide a public/common data structure to be shared by key phrase related components.

uint32_t kp_begin; /**< start sample of key word */
uint32_t kp_end; /**< end sample of key word */
};
8 changes: 8 additions & 0 deletions src/include/sof/audio/kp_detector.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <sof/audio/kp_common.h>
#include <sof/notifier.h>

/*! Key word detector runtime data */
struct comp_data {
struct notify_data notify_data; /**< async notification data */
struct kp_data data; /**< start,end sample of key word */
};
8 changes: 8 additions & 0 deletions src/include/sof/audio/kpb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <sof/notifier.h>
#include <sof/audio/kp_common.h>

/*! Key phrase buffer runtime data */
struct comp_data {
struct notifier kpb_notifier; /**< async notification data */
struct kp_data data; /**< start,end sample of key phrase */
};
14 changes: 8 additions & 6 deletions src/include/sof/notifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,31 @@

struct sof;

/* notifier general IDs */
#define NOTIFIER_ID_CPU_FREQ 0
#define NOTIFIER_ID_SSP_FREQ 1

/* notifier target core masks */
#define NOTIFIER_TARGET_CORE_MASK(x) (1 << x)
#define NOTIFIER_TARGET_CORE_ALL_MASK 0xFFFFFFFF

enum notify_id {
NOTIFIER_ID_CPU_FREQ = 0,
NOTIFIER_ID_SSP_FREQ,
NOTIFIER_ID_KEY_PHRASE_DETECTED,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pls replace with some more generic name for all events sent by KPB clients, e.g. `NOTIFIER_ID_KPB_CLIENT_EVT'

};

struct notify {
spinlock_t lock; /* notifier lock */
struct list_item list; /* list of notifiers */
};

struct notify_data {
uint32_t id;
enum notify_id id;
uint32_t message;
uint32_t target_core_mask;
uint32_t data_size;
void *data;
};

struct notifier {
uint32_t id;
enum notify_id id;
struct list_item list;
void *cb_data;
void (*cb)(int message, void *cb_data, void *event_data);
Expand Down