-
Notifications
You must be signed in to change notification settings - Fork 355
Audio: MFCC: Add Voice Activity Detection based on Mel spectrum #10782
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
Open
singalsu
wants to merge
3
commits into
thesofproject:main
Choose a base branch
from
singalsu:mfcc_add_vad
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // | ||
| // Copyright(c) 2026 Intel Corporation. | ||
| // | ||
| // Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com> | ||
|
|
||
| /** | ||
| * \file mfcc_ipc4.c | ||
| * \brief IPC4-specific functions for MFCC component. | ||
| * | ||
| * Provides VAD switch control notification to user space via the | ||
| * IPC4 module notification mechanism. | ||
| */ | ||
|
|
||
| #include <sof/audio/mfcc/mfcc_comp.h> | ||
| #include <sof/audio/module_adapter/module/generic.h> | ||
| #include <sof/audio/component.h> | ||
| #include <sof/ipc/msg.h> | ||
| #include <sof/trace/trace.h> | ||
| #include <ipc4/base-config.h> | ||
| #include <ipc4/header.h> | ||
| #include <ipc4/module.h> | ||
| #include <ipc4/notification.h> | ||
| #include <rtos/string.h> | ||
| #include <errno.h> | ||
| #include <stdint.h> | ||
|
|
||
| LOG_MODULE_DECLARE(mfcc, CONFIG_SOF_LOG_LEVEL); | ||
|
|
||
| /** | ||
| * \brief Initialize IPC notification message for VAD switch control. | ||
| * | ||
| * Allocates and configures the IPC message used to send VAD state | ||
| * change notifications to user space via a switch control. | ||
| */ | ||
| int mfcc_ipc_notification_init(struct processing_module *mod) | ||
| { | ||
| struct mfcc_comp_data *cd = module_get_private_data(mod); | ||
| struct ipc_msg msg_proto; | ||
| struct comp_dev *dev = mod->dev; | ||
| struct comp_ipc_config *ipc_config = &dev->ipc_config; | ||
| union ipc4_notification_header *primary = | ||
| (union ipc4_notification_header *)&msg_proto.header; | ||
| struct sof_ipc4_notify_module_data *msg_module_data; | ||
| struct sof_ipc4_control_msg_payload *msg_payload; | ||
|
|
||
| memset_s(&msg_proto, sizeof(msg_proto), 0, sizeof(msg_proto)); | ||
| primary->r.notif_type = SOF_IPC4_MODULE_NOTIFICATION; | ||
| primary->r.type = SOF_IPC4_GLB_NOTIFICATION; | ||
| primary->r.rsp = SOF_IPC4_MESSAGE_DIR_MSG_REQUEST; | ||
| primary->r.msg_tgt = SOF_IPC4_MESSAGE_TARGET_FW_GEN_MSG; | ||
| cd->msg = ipc_msg_w_ext_init(msg_proto.header, msg_proto.extension, | ||
| sizeof(struct sof_ipc4_notify_module_data) + | ||
| sizeof(struct sof_ipc4_control_msg_payload) + | ||
| sizeof(struct sof_ipc4_ctrl_value_chan)); | ||
| if (!cd->msg) { | ||
| comp_err(dev, "Failed to initialize VAD notification"); | ||
| return -ENOMEM; | ||
| } | ||
|
|
||
| msg_module_data = (struct sof_ipc4_notify_module_data *)cd->msg->tx_data; | ||
| msg_module_data->instance_id = IPC4_INST_ID(ipc_config->id); | ||
| msg_module_data->module_id = IPC4_MOD_ID(ipc_config->id); | ||
| msg_module_data->event_id = SOF_IPC4_NOTIFY_MODULE_EVENTID_ALSA_MAGIC_VAL | | ||
| SOF_IPC4_SWITCH_CONTROL_PARAM_ID; | ||
| msg_module_data->event_data_size = sizeof(struct sof_ipc4_control_msg_payload) + | ||
| sizeof(struct sof_ipc4_ctrl_value_chan); | ||
|
|
||
| msg_payload = (struct sof_ipc4_control_msg_payload *)msg_module_data->event_data; | ||
| msg_payload->id = MFCC_CTRL_INDEX_VAD; | ||
| msg_payload->num_elems = 1; | ||
| msg_payload->chanv[0].channel = 0; | ||
|
|
||
| comp_dbg(dev, "VAD notification init: instance_id = 0x%08x, module_id = 0x%08x", | ||
| msg_module_data->instance_id, msg_module_data->module_id); | ||
| return 0; | ||
| } | ||
|
|
||
| /** | ||
| * \brief Send VAD switch control notification to user space. | ||
| * \param mod Processing module. | ||
| * \param val VAD value: 1 = speech, 0 = silence. | ||
| */ | ||
| void mfcc_send_vad_notification(struct processing_module *mod, uint32_t val) | ||
| { | ||
| struct mfcc_comp_data *cd = module_get_private_data(mod); | ||
| struct sof_ipc4_notify_module_data *msg_module_data; | ||
| struct sof_ipc4_control_msg_payload *msg_payload; | ||
|
|
||
| if (!cd->msg) | ||
| return; | ||
|
|
||
| msg_module_data = (struct sof_ipc4_notify_module_data *)cd->msg->tx_data; | ||
| msg_payload = (struct sof_ipc4_control_msg_payload *)msg_module_data->event_data; | ||
| msg_payload->chanv[0].value = val; | ||
| ipc_msg_send(cd->msg, NULL, false); | ||
| } | ||
|
|
||
| int mfcc_get_config(struct processing_module *mod, | ||
| uint32_t config_id, uint32_t *data_offset_size, | ||
| uint8_t *fragment, size_t fragment_size) | ||
| { | ||
| struct sof_ipc_ctrl_data *cdata = (struct sof_ipc_ctrl_data *)fragment; | ||
| struct mfcc_comp_data *cd = module_get_private_data(mod); | ||
| struct sof_ipc4_control_msg_payload *ctl; | ||
|
|
||
| comp_info(mod->dev, "entry"); | ||
|
|
||
| switch (config_id) { | ||
| case SOF_IPC4_SWITCH_CONTROL_PARAM_ID: | ||
| ctl = (struct sof_ipc4_control_msg_payload *)fragment; | ||
| if (ctl->id == MFCC_CTRL_INDEX_VAD && ctl->num_elems == 1) { | ||
| ctl->chanv[0].value = cd->vad_prev ? 1 : 0; | ||
| *data_offset_size = sizeof(*ctl) + sizeof(ctl->chanv[0]); | ||
| return 0; | ||
| } | ||
| return -EINVAL; | ||
| default: | ||
| return comp_data_blob_get_cmd(cd->model_handler, cdata, fragment_size); | ||
| } | ||
| } | ||
|
|
||
| int mfcc_set_config(struct processing_module *mod, uint32_t config_id, | ||
| enum module_cfg_fragment_position pos, uint32_t data_offset_size, | ||
| const uint8_t *fragment, size_t fragment_size, uint8_t *response, | ||
| size_t response_size) | ||
| { | ||
| struct mfcc_comp_data *cd = module_get_private_data(mod); | ||
|
|
||
| comp_info(mod->dev, "entry"); | ||
|
|
||
| switch (config_id) { | ||
| case SOF_IPC4_SWITCH_CONTROL_PARAM_ID: | ||
| /* VAD switch is read-only, ignore set requests */ | ||
| return 0; | ||
| default: | ||
| return comp_data_blob_set(cd->model_handler, pos, data_offset_size, | ||
| fragment, fragment_size); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.