mirror of https://github.com/thesofproject/sof.git
comp: ctc: add ctc binary control.
Add binary controls of Google CTC component to load different configs. Signed-off-by: Eddy Hsu <eddyhsu@google.com>
This commit is contained in:
parent
01c9ce9eda
commit
175a97ec6b
|
@ -15,7 +15,6 @@
|
|||
#include <rtos/init.h>
|
||||
|
||||
#include <google_ctc_audio_processing.h>
|
||||
#include <google_ctc_audio_processing_sof_message_reader.h>
|
||||
|
||||
#include "google_ctc_audio_processing.h"
|
||||
|
||||
|
@ -298,31 +297,15 @@ static int google_ctc_audio_processing_reconfigure(struct processing_module *mod
|
|||
config, size);
|
||||
|
||||
cd->reconfigure = false;
|
||||
|
||||
uint8_t *processing_config;
|
||||
size_t processing_config_size;
|
||||
bool processing_config_present;
|
||||
|
||||
GoogleCtcAudioProcessingParseSofConfigMessage(config, size,
|
||||
&processing_config,
|
||||
&processing_config_size,
|
||||
&processing_config_present);
|
||||
|
||||
if (processing_config_present) {
|
||||
comp_info(dev,
|
||||
"google_ctc_audio_processing_reconfigure(): Applying config of size %zu bytes",
|
||||
processing_config_size);
|
||||
|
||||
ret = GoogleCtcAudioProcessingReconfigure(cd->state,
|
||||
processing_config,
|
||||
processing_config_size);
|
||||
if (ret) {
|
||||
comp_err(dev, "GoogleCtcAudioProcessingReconfigure failed: %d",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
comp_info(dev,
|
||||
"google_ctc_audio_processing_reconfigure(): Applying config of size %zu bytes",
|
||||
size);
|
||||
ret = GoogleCtcAudioProcessingReconfigure(cd->state, config, size);
|
||||
if (ret) {
|
||||
comp_err(dev, "GoogleCtcAudioProcessingReconfigure failed: %d",
|
||||
ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -335,6 +318,8 @@ static int ctc_prepare(struct processing_module *mod,
|
|||
struct comp_buffer *source;
|
||||
enum sof_ipc_frame fmt;
|
||||
int num_channels;
|
||||
uint8_t *config;
|
||||
int config_size;
|
||||
|
||||
comp_info(mod->dev, "ctc_prepare()");
|
||||
|
||||
|
@ -367,10 +352,21 @@ static int ctc_prepare(struct processing_module *mod,
|
|||
}
|
||||
cd->next_avail_output_samples = cd->chunk_frames * num_channels;
|
||||
|
||||
config = comp_get_data_blob(cd->tuning_handler, &config_size, NULL);
|
||||
|
||||
if (config_size != CTC_BLOB_CONFIG_SIZE) {
|
||||
comp_info(mod->dev, "ctc_prepare(): config_size not expected: %d", config_size);
|
||||
config = NULL;
|
||||
config_size = 0;
|
||||
}
|
||||
cd->state = GoogleCtcAudioProcessingCreateWithConfig(cd->chunk_frames,
|
||||
audio_stream_get_rate(&source->stream),
|
||||
/*config=*/NULL,
|
||||
/*config_size=*/0);
|
||||
config,
|
||||
config_size);
|
||||
if (!cd->state) {
|
||||
comp_err(mod->dev, "ctc_prepare(), failed to create CTC");
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -37,10 +37,24 @@ struct google_ctc_audio_processing_comp_data {
|
|||
uint32_t chunk_frames;
|
||||
GoogleCtcAudioProcessingState *state;
|
||||
struct comp_data_blob_handler *tuning_handler;
|
||||
bool enabled;
|
||||
bool reconfigure;
|
||||
ctc_func ctc_func;
|
||||
};
|
||||
|
||||
struct google_ctc_config {
|
||||
/* size of the whole ctc config */
|
||||
uint32_t size;
|
||||
|
||||
/* reserved */
|
||||
uint32_t reserved[4];
|
||||
|
||||
uint32_t data[];
|
||||
} __packed;
|
||||
|
||||
#define CTC_BLOB_DATA_SIZE 4100
|
||||
#define CTC_BLOB_CONFIG_SIZE (sizeof(struct google_ctc_config) + CTC_BLOB_DATA_SIZE)
|
||||
|
||||
int ctc_set_config(struct processing_module *mod, uint32_t param_id,
|
||||
enum module_cfg_fragment_position pos,
|
||||
uint32_t data_offset_size,
|
||||
|
|
|
@ -28,6 +28,8 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
|
|||
struct sof_ipc_ctrl_data *cdata = (struct sof_ipc_ctrl_data *)fragment;
|
||||
struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod);
|
||||
int ret;
|
||||
struct google_ctc_config *config;
|
||||
int size;
|
||||
|
||||
switch (cdata->cmd) {
|
||||
case SOF_CTRL_CMD_BINARY:
|
||||
|
@ -35,7 +37,19 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
|
|||
if (ret)
|
||||
return ret;
|
||||
if (comp_is_new_data_blob_available(cd->tuning_handler)) {
|
||||
comp_get_data_blob(cd->tuning_handler, NULL, NULL);
|
||||
config = comp_get_data_blob(cd->tuning_handler, &size, NULL);
|
||||
if (size != CTC_BLOB_CONFIG_SIZE) {
|
||||
comp_err(mod->dev,
|
||||
"ctc_set_config(): Invalid config size = %d",
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (config->size != CTC_BLOB_CONFIG_SIZE) {
|
||||
comp_err(mod->dev,
|
||||
"ctc_set_config(): Invalid config->size = %d",
|
||||
config->size);
|
||||
return -EINVAL;
|
||||
}
|
||||
cd->reconfigure = true;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -27,6 +27,8 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
|
|||
{
|
||||
struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod);
|
||||
int ret;
|
||||
struct google_ctc_config *config;
|
||||
int size;
|
||||
|
||||
switch (param_id) {
|
||||
case 0:
|
||||
|
@ -44,7 +46,19 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
|
|||
return ret;
|
||||
|
||||
if (comp_is_new_data_blob_available(cd->tuning_handler)) {
|
||||
comp_get_data_blob(cd->tuning_handler, NULL, NULL);
|
||||
config = comp_get_data_blob(cd->tuning_handler, &size, NULL);
|
||||
if (size != CTC_BLOB_CONFIG_SIZE) {
|
||||
comp_err(mod->dev,
|
||||
"ctc_set_config(): Invalid config size = %d",
|
||||
size);
|
||||
return -EINVAL;
|
||||
}
|
||||
if (config->size != CTC_BLOB_CONFIG_SIZE) {
|
||||
comp_err(mod->dev,
|
||||
"ctc_set_config(): Invalid config->size = %d",
|
||||
config->size);
|
||||
return -EINVAL;
|
||||
}
|
||||
cd->reconfigure = true;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,17 +52,6 @@ void GoogleCtcAudioProcessingProcess(GoogleCtcAudioProcessingState *state,
|
|||
src, sizeof(float) * num_frames * num_channels);
|
||||
}
|
||||
|
||||
void GoogleCtcAudioProcessingParseSofConfigMessage(uint8_t *message,
|
||||
size_t message_size,
|
||||
uint8_t **config,
|
||||
size_t *config_size,
|
||||
bool *config_present)
|
||||
{
|
||||
*config = NULL;
|
||||
*config_size = 0;
|
||||
*config_present = false;
|
||||
}
|
||||
|
||||
int GoogleCtcAudioProcessingReconfigure(GoogleCtcAudioProcessingState *state,
|
||||
const uint8_t *config, int config_size)
|
||||
{
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
/* SPDX-License-Identifier: BSD-3-Clause */
|
||||
/*
|
||||
* Copyright(c) 2024 Google LLC.
|
||||
*
|
||||
* Author: Eddy Hsu <eddyhsu@google.com>
|
||||
*/
|
||||
#ifndef GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_
|
||||
#define GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
// Parses the fields from a SOF config message `message` of size `message_size`
|
||||
// intended for the GoogleCtcAudioProcessing component and the corresponding
|
||||
// outputs parameters based on the content. Any previous content in the output
|
||||
// parameters is overwritten regardless of the content in `message`.
|
||||
void GoogleCtcAudioProcessingParseSofConfigMessage(uint8_t *message,
|
||||
size_t message_size,
|
||||
uint8_t **config,
|
||||
size_t *config_size,
|
||||
bool *config_present);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_
|
Loading…
Reference in New Issue