Skip to content

Commit

Permalink
src: fix src_lite
Browse files Browse the repository at this point in the history
src_lite is currently broken: its definition of the SRC_LITE macro at
the top of the file has no effect and its coefficients are never
used. Fix it by moving coefficient evaluation into a separate
function and calling it from both src.c and src_lite.c.

Signed-off-by: Guennadi Liakhovetski <[email protected]>
  • Loading branch information
lyakh authored and kv2019i committed Jun 13, 2024
1 parent 8795e0f commit 7ee322f
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 40 deletions.
63 changes: 41 additions & 22 deletions src/audio/src/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -607,17 +593,50 @@ 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()");

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;
Expand Down
34 changes: 18 additions & 16 deletions src/audio/src/src.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
#include <sof/audio/component.h>
#include <sof/audio/module_adapter/module/generic.h>

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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down
41 changes: 39 additions & 2 deletions src/audio/src/src_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,53 @@
// Author: Fabiola Jasinska <[email protected]>

#include <rtos/init.h>

#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,
Expand Down

0 comments on commit 7ee322f

Please sign in to comment.