Skip to content

Commit

Permalink
comp: ctc: add ctc switch control.
Browse files Browse the repository at this point in the history
Add enablement switch controls of Google CTC component.

Signed-off-by: Eddy Hsu <eddyhsu@google.com>
  • Loading branch information
Eddy Hsu authored and lgirdwood committed Sep 10, 2024
1 parent 175a97e commit 7789531
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 10 deletions.
30 changes: 30 additions & 0 deletions src/audio/google/google_ctc_audio_processing.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ static inline float convert_int32_to_float(int32_t data)
static const int kChunkFrames = 48;
static const int kMaxChannels = 2;

static void ctc_passthrough(const struct audio_stream *source,
struct audio_stream *sink,
struct input_stream_buffer *input_buffers,
struct output_stream_buffer *output_buffers,
uint32_t frames)
{
int n_ch = audio_stream_get_channels(source);
int samples = frames * n_ch;

audio_stream_copy(source, 0, sink, 0, samples);
module_update_buffer_position(&input_buffers[0], &output_buffers[0], frames);
}

#if CONFIG_FORMAT_S16LE
static void ctc_s16_default(struct google_ctc_audio_processing_comp_data *cd,
const struct audio_stream *source,
Expand All @@ -79,6 +92,11 @@ static void ctc_s16_default(struct google_ctc_audio_processing_comp_data *cd,
int samples_to_written = MIN(samples, audio_stream_samples_without_wrap_s16(sink, dest));
int written_samples = 0;

if (!cd->enabled) {
ctc_passthrough(source, sink, input_buffers, output_buffers, frames);
return;
}

// writes previous processed samples to the output.
while (cd->next_avail_output_samples < cd->chunk_frames * n_ch &&
written_samples < samples_to_written) {
Expand Down Expand Up @@ -129,6 +147,11 @@ static void ctc_s24_default(struct google_ctc_audio_processing_comp_data *cd,
int samples_to_written = MIN(samples, audio_stream_samples_without_wrap_s24(sink, dest));
int written_samples = 0;

if (!cd->enabled) {
ctc_passthrough(source, sink, input_buffers, output_buffers, frames);
return;
}

// writes previous processed samples to the output.
while (cd->next_avail_output_samples < cd->chunk_frames * n_ch &&
written_samples < samples_to_written) {
Expand Down Expand Up @@ -179,6 +202,11 @@ static void ctc_s32_default(struct google_ctc_audio_processing_comp_data *cd,
int samples_to_written = MIN(samples, audio_stream_samples_without_wrap_s32(sink, dest));
int written_samples = 0;

if (!cd->enabled) {
ctc_passthrough(source, sink, input_buffers, output_buffers, frames);
return;
}

// writes previous processed samples to the output.
while (cd->next_avail_output_samples < cd->chunk_frames * n_ch &&
written_samples < samples_to_written) {
Expand Down Expand Up @@ -267,6 +295,8 @@ static int ctc_init(struct processing_module *mod)
return -ENOMEM;
}

cd->enabled = true;

comp_dbg(dev, "ctc_init(): Ready");

return 0;
Expand Down
17 changes: 15 additions & 2 deletions src/audio/google/google_ctc_audio_processing_ipc3.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,20 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
cd->reconfigure = true;
}
return 0;
case SOF_CTRL_CMD_SWITCH:
if (cdata->num_elems == 1) {
cd->enabled = cdata->chanv[0].value;
comp_info(dev, "ctc_set_config(), enabled = %d",
cd->enabled);
return 0;
}
comp_err(mod->dev,
"ctc_set_config(): Illegal num_elems = %d",
cdata->num_elems);
return -EINVAL;
default:
comp_err(mod->dev,
"google_ctc_audio_processing_ctrl_set_data(): Only binary controls supported %d",
"ctc_set_config(): Only binary and switch controls supported %d",
cdata->cmd);
return -EINVAL;
}
Expand All @@ -68,11 +79,13 @@ int ctc_get_config(struct processing_module *mod,
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);

comp_info(mod->dev, "google_ctc_audio_processing_ctrl_get_data(): %u", cdata->cmd);
comp_info(mod->dev, "ctc_get_config(): %u", cdata->cmd);

switch (cdata->cmd) {
case SOF_CTRL_CMD_BINARY:
return comp_data_blob_get_cmd(cd->tuning_handler, cdata, fragment_size);
case SOF_CTRL_CMD_SWITCH:
return comp_data_blob_get_cmd(cd->tuning_handler, cdata, fragment_size);
default:
return -EINVAL;
}
Expand Down
19 changes: 16 additions & 3 deletions src/audio/google/google_ctc_audio_processing_ipc4.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
size_t fragment_size, uint8_t *response,
size_t response_size)
{
struct sof_ipc4_control_msg_payload *ctl = (struct sof_ipc4_control_msg_payload *)fragment;
struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod);
int ret;
struct google_ctc_config *config;
Expand All @@ -34,9 +35,17 @@ int ctc_set_config(struct processing_module *mod, uint32_t param_id,
case 0:
break;
case SOF_IPC4_SWITCH_CONTROL_PARAM_ID:
if (ctl->id == 0 && ctl->num_elems == 1) {
cd->enabled = ctl->chanv[0].value;
comp_info(mod->dev, "ctc_set_config(): enabled = %d", cd->enabled);
return 0;
}
comp_err(mod->dev, "ctc_set_config(): Illegal control id = %d, num_elems = %d",
ctl->id, ctl->num_elems);
return -EINVAL;
case SOF_IPC4_ENUM_CONTROL_PARAM_ID:
default:
comp_err(mod->dev, "google_ctc_audio_processing_set_data(): Only binary controls supported");
comp_err(mod->dev, "ctc_set_config(): Only binary and switch controls supported");
return -EINVAL;
}

Expand Down Expand Up @@ -69,6 +78,10 @@ int ctc_get_config(struct processing_module *mod,
uint32_t param_id, uint32_t *data_offset_size,
uint8_t *fragment, size_t fragment_size)
{
comp_err(mod->dev, "ctc_get_config(): Not supported");
return -EINVAL;
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);

comp_info(mod->dev, "ctc_get_config(): %u", cdata->cmd);

return comp_data_blob_get_cmd(cd->tuning_handler, cdata, fragment_size);
}
12 changes: 9 additions & 3 deletions tools/topology/topology2/cavs-mixin-mixout-ctc-ssp.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,15 @@ Object.Pipeline {
}
}
Object.Widget.ctc.1 {
Object.Control.bytes."1" {
name 'CTC.0'
}
Object.Control {
mixer."1" {
name 'CTC Switch'
}
bytes."1" {
name 'CTC.0'
max 4160
}
}
}
}
]
Expand Down
20 changes: 18 additions & 2 deletions tools/topology/topology2/include/components/ctc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,24 @@ Class.Widget."ctc" {
unique "instance"
}

Object.Control.bytes."1" {
max 4124
#
# ctc widget switch control
#
Object.Control {
mixer."1" {
Object.Base.channel.1 {
name "fc"
shift 0
}
Object.Base.ops.1 {
name "ctl"
info "volsw"
#259 binds the mixer control to switch get/put handlers
get 259
put 259
}
max 1
}
}

# Default attribute values for CTC widget
Expand Down

0 comments on commit 7789531

Please sign in to comment.