diff --git a/src/audio/src/src.c b/src/audio/src/src.c index 7d4315ad896b..c6fc1b812613 100644 --- a/src/audio/src/src.c +++ b/src/audio/src/src.c @@ -41,10 +41,7 @@ #include "src.h" #include "src_config.h" -#ifdef SRC_LITE -#include "coef/src_lite_ipc4_int32_define.h" -#include "coef/src_lite_ipc4_int32_table.h" -#elif SRC_SHORT || CONFIG_COMP_SRC_TINY +#if SRC_SHORT || CONFIG_COMP_SRC_TINY #include "coef/src_tiny_int16_define.h" #include "coef/src_tiny_int16_table.h" #elif CONFIG_COMP_SRC_SMALL @@ -89,18 +86,9 @@ static int src_buffer_lengths(struct comp_dev *dev, struct comp_data *cd, int nc } a->nch = nch; - a->idx_in = src_find_fs(src_in_fs, NUM_IN_FS, fs_in); - a->idx_out = src_find_fs(src_out_fs, NUM_OUT_FS, fs_out); - /* Check that both in and out rates are supported */ - if (a->idx_in < 0 || a->idx_out < 0) { - comp_err(dev, "src_buffer_lengths(): rates not supported, fs_in: %u, fs_out: %u", - fs_in, fs_out); - return -EINVAL; - } - - stage1 = src_table1[a->idx_out][a->idx_in]; - stage2 = src_table2[a->idx_out][a->idx_in]; + stage1 = a->stage1; + stage2 = a->stage2; /* Check from stage1 parameter for a deleted in/out rate combination.*/ if (stage1->filter_length < 1) { @@ -227,8 +215,8 @@ static int src_polyphase_init(struct polyphase_src *src, struct src_param *p, return -EINVAL; /* Get setup for 2 stage conversion */ - stage1 = src_table1[p->idx_out][p->idx_in]; - stage2 = src_table2[p->idx_out][p->idx_in]; + stage1 = p->stage1; + stage2 = p->stage2; ret = init_stages(stage1, stage2, src, p, 2, delay_lines_start); if (ret < 0) return -EINVAL; @@ -529,8 +517,6 @@ int src_params_general(struct processing_module *mod, return err; } - src_get_source_sink_params(dev, source, sink); - comp_info(dev, "src_params(), source_rate = %u, sink_rate = %u", cd->source_rate, cd->sink_rate); comp_dbg(dev, "src_params(), sample_container_bytes = %d, channels = %u, dev->frames = %u", @@ -607,10 +593,31 @@ int src_params_general(struct processing_module *mod, return 0; } -int src_prepare(struct processing_module *mod, - struct sof_source **sources, int num_of_sources, - struct sof_sink **sinks, int num_of_sinks) +int src_param_set(struct comp_dev *dev, struct comp_data *cd) +{ + struct src_param *a = &cd->param; + int fs_in = cd->source_rate; + int fs_out = cd->sink_rate; + + a->idx_in = src_find_fs(a->in_fs, NUM_IN_FS, fs_in); + a->idx_out = src_find_fs(a->out_fs, NUM_OUT_FS, fs_out); + + /* Check that both in and out rates are supported */ + if (a->idx_in < 0 || a->idx_out < 0) { + comp_err(dev, "src_buffer_lengths(): rates not supported, fs_in: %u, fs_out: %u", + fs_in, fs_out); + return -EINVAL; + } + + return 0; +} + +static int src_prepare(struct processing_module *mod, + struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks) { + struct comp_data *cd = module_get_private_data(mod); + struct src_param *a = &cd->param; int ret; comp_info(mod->dev, "src_prepare()"); @@ -618,6 +625,18 @@ int src_prepare(struct processing_module *mod, if (num_of_sources != 1 || num_of_sinks != 1) return -EINVAL; + a->in_fs = src_in_fs; + a->out_fs = src_out_fs; + + src_get_source_sink_params(mod->dev, sources[0], sinks[0]); + + ret = src_param_set(mod->dev, cd); + if (ret < 0) + return ret; + + a->stage1 = src_table1[a->idx_out][a->idx_in]; + a->stage2 = src_table2[a->idx_out][a->idx_in]; + ret = src_params_general(mod, sources[0], sinks[0]); if (ret < 0) return ret; diff --git a/src/audio/src/src.h b/src/audio/src/src.h index 8216523a3bda..278e3f8406ac 100644 --- a/src/audio/src/src.h +++ b/src/audio/src/src.h @@ -16,6 +16,19 @@ #include #include +struct src_stage { + const int idm; + const int odm; + const int num_of_subfilters; + const int subfilter_length; + const int filter_length; + const int blk_in; + const int blk_out; + const int halfband; + const int shift; + const void *coefs; /* Can be int16_t or int32_t depending on config */ +}; + struct src_param { int fir_s1; int fir_s2; @@ -31,19 +44,10 @@ struct src_param { int idx_in; int idx_out; int nch; -}; - -struct src_stage { - const int idm; - const int odm; - const int num_of_subfilters; - const int subfilter_length; - const int filter_length; - const int blk_in; - const int blk_out; - const int halfband; - const int shift; - const void *coefs; /* Can be int16_t or int32_t depending on config */ + const struct src_stage *stage1; + const struct src_stage *stage2; + const int *in_fs; + const int *out_fs; }; struct src_state { @@ -231,9 +235,7 @@ int src_copy_sxx(struct comp_data *cd, struct sof_source *source, int src_params_general(struct processing_module *mod, struct sof_source *source, struct sof_sink *sink); -int src_prepare(struct processing_module *mod, - struct sof_source **sources, int num_of_sources, - struct sof_sink **sinks, int num_of_sinks); +int src_param_set(struct comp_dev *dev, struct comp_data *cd); bool src_is_ready_to_process(struct processing_module *mod, struct sof_source **sources, int num_of_sources, diff --git a/src/audio/src/src_lite.c b/src/audio/src/src_lite.c index 5b6bf40f832a..4c02e13303e4 100644 --- a/src/audio/src/src_lite.c +++ b/src/audio/src/src_lite.c @@ -5,16 +5,53 @@ // Author: Fabiola Jasinska #include + #include "src.h" #include "src_config.h" -#define SRC_LITE 1 +#include "coef/src_lite_ipc4_int32_define.h" +#include "coef/src_lite_ipc4_int32_table.h" LOG_MODULE_REGISTER(src_lite, CONFIG_SOF_LOG_LEVEL); +/* + * This function is 100% identical to src_prepare(), but it's + * assigning different coefficient arrays because it's including + * different headers. + */ +static int src_lite_prepare(struct processing_module *mod, + struct sof_source **sources, int num_of_sources, + struct sof_sink **sinks, int num_of_sinks) +{ + struct comp_data *cd = module_get_private_data(mod); + struct src_param *a = &cd->param; + int ret; + + comp_info(mod->dev, "src_prepare()"); + + if (num_of_sources != 1 || num_of_sinks != 1) + return -EINVAL; + + a->in_fs = src_in_fs; + a->out_fs = src_out_fs; + + ret = src_param_set(mod->dev, cd); + if (ret < 0) + return ret; + + a->stage1 = src_table1[a->idx_out][a->idx_in]; + a->stage2 = src_table2[a->idx_out][a->idx_in]; + + ret = src_params_general(mod, sources[0], sinks[0]); + if (ret < 0) + return ret; + + return src_prepare_general(mod, sources[0], sinks[0]); +} + static const struct module_interface src_lite_interface = { .init = src_init, - .prepare = src_prepare, + .prepare = src_lite_prepare, .process = src_process, .is_ready_to_process = src_is_ready_to_process, .set_configuration = src_set_config,