Skip to content

Commit 3776df6

Browse files
committed
audio: tflm: integrate keyword detection with KPB for WoV trigger
1 parent 411ed5e commit 3776df6

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

src/audio/tensorflow/tflm-classify.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
#include <ipc4/header.h>
3737
#include <ipc4/module.h>
3838
#include <ipc4/notification.h>
39+
#include <sof/audio/kpb.h>
40+
#include <sof/lib/notifier.h>
3941

4042
#include "speech.h"
4143

@@ -50,8 +52,28 @@ struct tflm_comp_data {
5052
struct comp_data_blob_handler *model_handler;
5153
struct tf_classify tfc;
5254
struct ipc_msg *msg;
55+
struct kpb_event_data event_data;
56+
struct kpb_client client_data;
5357
};
5458

59+
static void tflm_notify_kpb(struct processing_module *mod)
60+
{
61+
struct tflm_comp_data *cd = module_get_private_data(mod);
62+
struct comp_dev *dev = mod->dev;
63+
64+
comp_info(dev, "TFLM keyword trigger -> notifying KPB to begin draining");
65+
66+
cd->client_data.r_ptr = NULL;
67+
cd->client_data.sink = NULL;
68+
cd->client_data.id = 0;
69+
cd->event_data.event_id = KPB_EVENT_BEGIN_DRAINING;
70+
cd->event_data.client_data = &cd->client_data;
71+
72+
notifier_event(dev, NOTIFIER_ID_KPB_CLIENT_EVT,
73+
NOTIFIER_TARGET_CORE_ALL_MASK, &cd->event_data,
74+
sizeof(cd->event_data));
75+
}
76+
5577
static int tflm_ipc_notification_init(struct processing_module *mod)
5678
{
5779
struct tflm_comp_data *cd = module_get_private_data(mod);
@@ -298,6 +320,7 @@ static int tflm_process(struct processing_module *mod,
298320
comp_info(dev, "TFLM keyword detected: %s (confidence %1.3f)",
299321
prediction[max_idx], (double)max_score);
300322
tflm_send_keyword_notification(mod, max_idx);
323+
tflm_notify_kpb(mod);
301324
}
302325

303326
/* advance by one 20ms stride (40 int8_t features) */

tools/topology/topology2/sof-hda-tflm.conf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<route.conf>
3333
<common_definitions.conf>
3434
<module-copier.conf>
35+
<kpb.conf>
3536
<tflm.conf>
3637
<mfcc.conf>
3738
<src.conf>
@@ -41,7 +42,7 @@ Define {
4142
HDA_CONFIG "none"
4243
PLATFORM "none"
4344
ANALOG_PLAYBACK_PCM 'Analog Playback'
44-
ANALOG_CAPTURE_PCM 'HDA Mic TFLM Capture'
45+
ANALOG_CAPTURE_PCM 'HDA Mic TFLM WoV Capture'
4546
HDA_ANALOG_DAI_NAME 'Analog'
4647
HDA_ANALOG_CAPTURE_RATE 48000
4748
HDA_ANALOG_PLAYBACK_RATE 48000
@@ -133,6 +134,25 @@ Object.Pipeline {
133134
}
134135
}
135136

137+
Object.Widget.kpb.1 {
138+
num_input_audio_formats 1
139+
num_output_audio_formats 1
140+
Object.Base.input_audio_format [
141+
{
142+
in_rate $HDA_ANALOG_CAPTURE_RATE
143+
in_bit_depth 32
144+
in_valid_bit_depth 32
145+
}
146+
]
147+
Object.Base.output_audio_format [
148+
{
149+
out_rate $HDA_ANALOG_CAPTURE_RATE
150+
out_bit_depth 32
151+
out_valid_bit_depth 32
152+
}
153+
]
154+
}
155+
136156
Object.Widget.module-copier.2 {
137157
stream_name $HDA_ANALOG_DAI_NAME
138158
num_input_audio_formats 1
@@ -163,6 +183,10 @@ Object.Base.route [
163183
}
164184
{
165185
source "gain.$HDA_TFLM_DAI_PIPELINE_ID.1"
186+
sink "kpb.$HDA_TFLM_DAI_PIPELINE_ID.1"
187+
}
188+
{
189+
source "kpb.$HDA_TFLM_DAI_PIPELINE_ID.1"
166190
sink "module-copier.$HDA_TFLM_DAI_PIPELINE_ID.2"
167191
}
168192
{

0 commit comments

Comments
 (0)