diff --git a/src/audio/google/google_ctc_audio_processing.c b/src/audio/google/google_ctc_audio_processing.c index 47205cdb3a99..ed6631082f4c 100644 --- a/src/audio/google/google_ctc_audio_processing.c +++ b/src/audio/google/google_ctc_audio_processing.c @@ -15,7 +15,6 @@ #include #include -#include #include "google_ctc_audio_processing.h" @@ -80,6 +79,12 @@ 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) { + audio_stream_copy(source, 0, sink, 0, samples); + module_update_buffer_position(&input_buffers[0], &output_buffers[0], 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) { @@ -130,6 +135,12 @@ 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) { + audio_stream_copy(source, 0, sink, 0, samples); + module_update_buffer_position(&input_buffers[0], &output_buffers[0], 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) { @@ -180,6 +191,12 @@ 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) { + audio_stream_copy(source, 0, sink, 0, samples); + module_update_buffer_position(&input_buffers[0], &output_buffers[0], 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) { @@ -216,6 +233,8 @@ static int ctc_free(struct processing_module *mod) { struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod); + comp_info(mod->dev, "ctc_free()"); + if (cd) { rfree(cd->input); rfree(cd->output); @@ -268,6 +287,8 @@ static int ctc_init(struct processing_module *mod) return -ENOMEM; } + cd->enabled = true; + comp_dbg(dev, "ctc_init(): Ready"); return 0; @@ -279,7 +300,7 @@ static int google_ctc_audio_processing_reconfigure(struct processing_module *mod struct comp_dev *dev = mod->dev; uint8_t *config; size_t size; - int ret; + int ret = 0; comp_dbg(dev, "google_ctc_audio_processing_reconfigure()"); @@ -295,32 +316,21 @@ 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->config, size); - cd->reconfigure = false; + cd->config = (struct google_ctc_config *)config; + if (cd->config) + cd->enabled = cd->config->params.enabled; - 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; @@ -371,18 +381,31 @@ static int ctc_prepare(struct processing_module *mod, audio_stream_get_rate(&source->stream), /*config=*/NULL, /*config_size=*/0); + if (!cd->state) { + comp_err(mod->dev, "ctc_prepare(), failed to create CTC"); + return -ENOMEM; + } + cd->config = comp_get_data_blob(cd->tuning_handler, NULL, NULL); + if (cd->config) + cd->enabled = cd->config->params.enabled; return 0; } static int ctc_reset(struct processing_module *mod) { struct google_ctc_audio_processing_comp_data *cd = module_get_private_data(mod); + size_t buf_size = cd->chunk_frames * sizeof(cd->input[0]) * kMaxChannels; comp_info(mod->dev, "ctc_reset()"); GoogleCtcAudioProcessingFree(cd->state); + cd->state = NULL; cd->ctc_func = NULL; + cd->input_samples = 0; + cd->next_avail_output_samples = 0; + memset(cd->input, 0 , buf_size); + memset(cd->output, 0 , buf_size); return 0; } @@ -408,6 +431,7 @@ static int ctc_process(struct processing_module *mod, } cd->ctc_func(cd, source, sink, &input_buffers[0], &output_buffers[0], frames); + return 0; } diff --git a/src/audio/google/google_ctc_audio_processing.h b/src/audio/google/google_ctc_audio_processing.h index 8fb00d9a5c7d..e4af85d58cbf 100644 --- a/src/audio/google/google_ctc_audio_processing.h +++ b/src/audio/google/google_ctc_audio_processing.h @@ -37,10 +37,26 @@ 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 enabled; bool reconfigure; ctc_func ctc_func; }; +struct google_ctc_params { + /* 1 to enable CTC, 0 to disable it */; + int32_t enabled; +} __attribute__((packed)); + +struct google_ctc_config { + uint32_t size; + + /* reserved */ + uint32_t reserved[4]; + + struct google_ctc_params params; +} __attribute__((packed)); + int ctc_set_config(struct processing_module *mod, uint32_t param_id, enum module_cfg_fragment_position pos, uint32_t data_offset_size, diff --git a/src/audio/google/google_ctc_audio_processing_ipc4.c b/src/audio/google/google_ctc_audio_processing_ipc4.c index f02f749d3689..5e30cc35c427 100644 --- a/src/audio/google/google_ctc_audio_processing_ipc4.c +++ b/src/audio/google/google_ctc_audio_processing_ipc4.c @@ -44,7 +44,9 @@ 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, NULL, NULL); + if (cd->config) + cd->enabled = cd->config->params.enabled; cd->reconfigure = true; } diff --git a/src/audio/google/google_ctc_audio_processing_mock.c b/src/audio/google/google_ctc_audio_processing_mock.c index fe5c8fa79a5c..3828ce5b271a 100644 --- a/src/audio/google/google_ctc_audio_processing_mock.c +++ b/src/audio/google/google_ctc_audio_processing_mock.c @@ -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) { diff --git a/third_party/include/google_ctc_audio_processing_sof_message_reader.h b/third_party/include/google_ctc_audio_processing_sof_message_reader.h deleted file mode 100644 index 0066c5ff5117..000000000000 --- a/third_party/include/google_ctc_audio_processing_sof_message_reader.h +++ /dev/null @@ -1,32 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause */ -/* - * Copyright(c) 2024 Google LLC. - * - * Author: Eddy Hsu - */ -#ifndef GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_ -#define GOOGLE_CTC_AUDIO_PROCESSING_SOF_MESSAGE_READER_H_ - -#include -#include -#include - -#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_