Skip to content

Commit

Permalink
src: create separate file for normal src
Browse files Browse the repository at this point in the history
Defines for normal src and src_lite were not separated correctly. Added new
variables so those values can be different depending on the type of src
being used. Those are assigned in prepare function in a new src.c file,
similarly to src_lite.c

Signed-off-by: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>
  • Loading branch information
tobonex committed Aug 16, 2024
1 parent 8496524 commit ac220c4
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/audio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: BSD-3-Clause

add_local_sources(sof src_generic.c src_hifi2ep.c src_hifi3.c src_hifi4.c src_common.c)
add_local_sources(sof src_generic.c src_hifi2ep.c src_hifi3.c src_hifi4.c src_common.c src.c)

if(CONFIG_IPC_MAJOR_3)
add_local_sources(sof src_ipc3.c)
Expand Down
83 changes: 83 additions & 0 deletions src/audio/src/src.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2024 Intel Corporation. All rights reserved.
//
// Author: Tobiasz Dryjanski <tobiaszx.dryjanski@intel.com>

/*
* This file has been extracted from src_common.c (formerly src.c)
* to create separation between defines in different src types.
*/

#include <rtos/init.h>

#include "src_common.h"
#include "src_config.h"

#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
#include "coef/src_small_int32_define.h"
#include "coef/src_small_int32_table.h"
#elif CONFIG_COMP_SRC_STD
#include "coef/src_std_int32_define.h"
#include "coef/src_std_int32_table.h"
#elif CONFIG_COMP_SRC_IPC4_FULL_MATRIX
#include "coef/src_ipc4_int32_define.h"
#include "coef/src_ipc4_int32_table.h"
#else
#error "No valid configuration selected for SRC"
#endif

LOG_MODULE_DECLARE(src, CONFIG_SOF_LOG_LEVEL);

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()");

if (num_of_sources != 1 || num_of_sinks != 1)
return -EINVAL;

a->in_fs = src_in_fs;
a->out_fs = src_out_fs;
a->num_in_fs = NUM_IN_FS;
a->num_out_fs = NUM_OUT_FS;
a->max_fir_delay_size_xnch = (PLATFORM_MAX_CHANNELS * MAX_FIR_DELAY_SIZE);
a->max_out_delay_size_xnch = (PLATFORM_MAX_CHANNELS * MAX_OUT_DELAY_SIZE);

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;

return src_prepare_general(mod, sources[0], sinks[0]);
}

static const struct module_interface src_interface = {
.init = src_init,
.prepare = src_prepare,
.process = src_process,
.is_ready_to_process = src_is_ready_to_process,
.set_configuration = src_set_config,
.get_configuration = src_get_config,
.reset = src_reset,
.free = src_free,
};

DECLARE_MODULE_ADAPTER(src_interface, SRC_UUID, src_tr);
SOF_MODULE_INIT(src, sys_comp_module_src_interface_init);
79 changes: 6 additions & 73 deletions src/audio/src/src_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,6 @@
#include "src_common.h"
#include "src_config.h"

#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
#include "coef/src_small_int32_define.h"
#include "coef/src_small_int32_table.h"
#elif CONFIG_COMP_SRC_STD
#include "coef/src_std_int32_define.h"
#include "coef/src_std_int32_table.h"
#elif CONFIG_COMP_SRC_IPC4_FULL_MATRIX
#include "coef/src_ipc4_int32_define.h"
#include "coef/src_ipc4_int32_table.h"
#else
#error "No valid configuration selected for SRC"
#endif

/* The FIR maximum lengths are per channel so need to multiply them */
#define MAX_FIR_DELAY_SIZE_XNCH (PLATFORM_MAX_CHANNELS * MAX_FIR_DELAY_SIZE)
#define MAX_OUT_DELAY_SIZE_XNCH (PLATFORM_MAX_CHANNELS * MAX_OUT_DELAY_SIZE)

LOG_MODULE_REGISTER(src, CONFIG_SOF_LOG_LEVEL);

/* Calculates buffers to allocate for a SRC mode */
Expand Down Expand Up @@ -189,10 +169,10 @@ static int init_stages(const struct src_stage *stage1, const struct src_stage *s
}

/* Check the sizes are less than MAX */
if (src->state1.fir_delay_size > MAX_FIR_DELAY_SIZE_XNCH ||
src->state1.out_delay_size > MAX_OUT_DELAY_SIZE_XNCH ||
src->state2.fir_delay_size > MAX_FIR_DELAY_SIZE_XNCH ||
src->state2.out_delay_size > MAX_OUT_DELAY_SIZE_XNCH) {
if (src->state1.fir_delay_size > p->max_fir_delay_size_xnch ||
src->state1.out_delay_size > p->max_out_delay_size_xnch ||
src->state2.fir_delay_size > p->max_fir_delay_size_xnch ||
src->state2.out_delay_size > p->max_out_delay_size_xnch) {
src->state1.fir_delay = NULL;
src->state1.out_delay = NULL;
src->state2.fir_delay = NULL;
Expand Down Expand Up @@ -600,8 +580,8 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd)
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);
a->idx_in = src_find_fs(a->in_fs, a->num_in_fs, fs_in);
a->idx_out = src_find_fs(a->out_fs, a->num_out_fs, fs_out);

/* Check that both in and out rates are supported */
if (a->idx_in < 0 || a->idx_out < 0) {
Expand All @@ -613,39 +593,6 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd)
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()");

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;

return src_prepare_general(mod, sources[0], sinks[0]);
}


bool src_is_ready_to_process(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
Expand Down Expand Up @@ -710,17 +657,3 @@ int src_free(struct processing_module *mod)
rfree(cd);
return 0;
}

static const struct module_interface src_interface = {
.init = src_init,
.prepare = src_prepare,
.process = src_process,
.is_ready_to_process = src_is_ready_to_process,
.set_configuration = src_set_config,
.get_configuration = src_get_config,
.reset = src_reset,
.free = src_free,
};

DECLARE_MODULE_ADAPTER(src_interface, SRC_UUID, src_tr);
SOF_MODULE_INIT(src, sys_comp_module_src_interface_init);
4 changes: 4 additions & 0 deletions src/audio/src/src_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ struct src_param {
int stage2_times;
int idx_in;
int idx_out;
int num_in_fs;
int num_out_fs;
int max_fir_delay_size_xnch;
int max_out_delay_size_xnch;
int nch;
const struct src_stage *stage1;
const struct src_stage *stage2;
Expand Down
4 changes: 4 additions & 0 deletions src/audio/src/src_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ static int src_lite_prepare(struct processing_module *mod,

a->in_fs = src_in_fs;
a->out_fs = src_out_fs;
a->num_in_fs = NUM_IN_FS;
a->num_out_fs = NUM_OUT_FS;
a->max_fir_delay_size_xnch = (PLATFORM_MAX_CHANNELS * MAX_FIR_DELAY_SIZE);
a->max_out_delay_size_xnch = (PLATFORM_MAX_CHANNELS * MAX_OUT_DELAY_SIZE);

ret = src_param_set(mod->dev, cd);
if (ret < 0)
Expand Down
1 change: 1 addition & 0 deletions zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,7 @@ zephyr_library_sources_ifdef(CONFIG_COMP_SRC
${SOF_AUDIO_PATH}/src/src_hifi3.c
${SOF_AUDIO_PATH}/src/src_hifi4.c
${SOF_AUDIO_PATH}/src/src_common.c
${SOF_AUDIO_PATH}/src/src.c
${SOF_AUDIO_PATH}/src/src_${ipc_suffix}.c
)

Expand Down

0 comments on commit ac220c4

Please sign in to comment.