Repository navigation
Key phrase detected: async notifications #1042
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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) | ||
| { | ||
| 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); | ||
| } | ||
|
|
||
| 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); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #include <stdint.h> | ||
|
|
||
| struct kp_data { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 */ | ||
| }; | ||
| 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 */ | ||
| }; |
| 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 */ | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
|
||
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.