Skip to content

Commit

Permalink
comp: ctc: add ctc binary control.
Browse files Browse the repository at this point in the history
Add binary controls of Google CTC component to load different configs.

Signed-off-by: Eddy Hsu <eddyhsu@google.com>
  • Loading branch information
Eddy Hsu committed Sep 3, 2024
1 parent 371245b commit 79e9a4b
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 70 deletions.
36 changes: 11 additions & 25 deletions src/audio/google/google_ctc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -297,32 +296,18 @@ static int google_ctc_audio_processing_reconfigure(struct processing_module *mod
comp_info(dev, "google_ctc_audio_processing_reconfigure(): New tuning config %p (%zu bytes)",
config, size);

cd->reconfigure = false;
cd->config = (struct google_ctc_config *)config;

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;
}
cd->reconfigure = false;
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;
}

Expand Down Expand Up @@ -372,6 +357,7 @@ static int ctc_prepare(struct processing_module *mod,
/*config=*/NULL,
/*config_size=*/0);

cd->config = comp_get_data_blob(cd->tuning_handler, NULL, NULL);
return 0;
}

Expand Down
14 changes: 14 additions & 0 deletions src/audio/google/google_ctc_audio_processing.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,24 @@ struct google_ctc_audio_processing_comp_data {
uint32_t chunk_frames;
GoogleCtcAudioProcessingState *state;
struct comp_data_blob_handler *tuning_handler;
struct google_ctc_config *config;
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,
Expand Down
15 changes: 14 additions & 1 deletion src/audio/google/google_ctc_audio_processing_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,27 @@ 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;
int size;

switch (cdata->cmd) {
case SOF_CTRL_CMD_BINARY:
ret = comp_data_blob_set_cmd(cd->tuning_handler, cdata);
if (ret)
return ret;
if (comp_is_new_data_blob_available(cd->tuning_handler)) {
comp_get_data_blob(cd->tuning_handler, NULL, NULL);
cd->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 (cd->config->size != CTC_BLOB_CONFIG_SIZE) {
comp_err(mod->dev,
"ctc_set_config(): Invalid config->size = %d",
cd->config->size);
return -EINVAL;
}
cd->reconfigure = true;
}
return 0;
Expand Down
15 changes: 14 additions & 1 deletion src/audio/google/google_ctc_audio_processing_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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;
int size;

switch (param_id) {
case 0:
Expand All @@ -44,7 +45,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);
cd->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 (cd->config->size != CTC_BLOB_CONFIG_SIZE) {
comp_err(mod->dev,
"ctc_set_config(): Invalid config->size = %d",
cd->config->size);
return -EINVAL;
}
cd->reconfigure = true;
}

Expand Down
11 changes: 0 additions & 11 deletions src/audio/google/google_ctc_audio_processing_mock.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

This file was deleted.

0 comments on commit 79e9a4b

Please sign in to comment.