Skip to content

Commit b17866e

Browse files
committed
src: fix src_lite
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 <guennadi.liakhovetski@linux.intel.com>
1 parent 0b86d94 commit b17866e

3 files changed

Lines changed: 98 additions & 40 deletions

File tree

src/audio/src/src.c

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@
4141
#include "src.h"
4242
#include "src_config.h"
4343

44-
#ifdef SRC_LITE
45-
#include "coef/src_lite_ipc4_int32_define.h"
46-
#include "coef/src_lite_ipc4_int32_table.h"
47-
#elif SRC_SHORT || CONFIG_COMP_SRC_TINY
44+
#if SRC_SHORT || CONFIG_COMP_SRC_TINY
4845
#include "coef/src_tiny_int16_define.h"
4946
#include "coef/src_tiny_int16_table.h"
5047
#elif CONFIG_COMP_SRC_SMALL
@@ -89,18 +86,9 @@ static int src_buffer_lengths(struct comp_dev *dev, struct comp_data *cd, int nc
8986
}
9087

9188
a->nch = nch;
92-
a->idx_in = src_find_fs(src_in_fs, NUM_IN_FS, fs_in);
93-
a->idx_out = src_find_fs(src_out_fs, NUM_OUT_FS, fs_out);
9489

95-
/* Check that both in and out rates are supported */
96-
if (a->idx_in < 0 || a->idx_out < 0) {
97-
comp_err(dev, "src_buffer_lengths(): rates not supported, fs_in: %u, fs_out: %u",
98-
fs_in, fs_out);
99-
return -EINVAL;
100-
}
101-
102-
stage1 = src_table1[a->idx_out][a->idx_in];
103-
stage2 = src_table2[a->idx_out][a->idx_in];
90+
stage1 = a->stage1;
91+
stage2 = a->stage2;
10492

10593
/* Check from stage1 parameter for a deleted in/out rate combination.*/
10694
if (stage1->filter_length < 1) {
@@ -227,8 +215,8 @@ static int src_polyphase_init(struct polyphase_src *src, struct src_param *p,
227215
return -EINVAL;
228216

229217
/* Get setup for 2 stage conversion */
230-
stage1 = src_table1[p->idx_out][p->idx_in];
231-
stage2 = src_table2[p->idx_out][p->idx_in];
218+
stage1 = p->stage1;
219+
stage2 = p->stage2;
232220
ret = init_stages(stage1, stage2, src, p, 2, delay_lines_start);
233221
if (ret < 0)
234222
return -EINVAL;
@@ -529,8 +517,6 @@ int src_params_general(struct processing_module *mod,
529517
return err;
530518
}
531519

532-
src_get_source_sink_params(dev, source, sink);
533-
534520
comp_info(dev, "src_params(), source_rate = %u, sink_rate = %u",
535521
cd->source_rate, cd->sink_rate);
536522
comp_dbg(dev, "src_params(), sample_container_bytes = %d, channels = %u, dev->frames = %u",
@@ -607,17 +593,50 @@ int src_params_general(struct processing_module *mod,
607593
return 0;
608594
}
609595

610-
int src_prepare(struct processing_module *mod,
611-
struct sof_source **sources, int num_of_sources,
612-
struct sof_sink **sinks, int num_of_sinks)
596+
int src_param_set(struct comp_dev *dev, struct comp_data *cd)
597+
{
598+
struct src_param *a = &cd->param;
599+
int fs_in = cd->source_rate;
600+
int fs_out = cd->sink_rate;
601+
602+
a->idx_in = src_find_fs(a->in_fs, NUM_IN_FS, fs_in);
603+
a->idx_out = src_find_fs(a->out_fs, NUM_OUT_FS, fs_out);
604+
605+
/* Check that both in and out rates are supported */
606+
if (a->idx_in < 0 || a->idx_out < 0) {
607+
comp_err(dev, "src_buffer_lengths(): rates not supported, fs_in: %u, fs_out: %u",
608+
fs_in, fs_out);
609+
return -EINVAL;
610+
}
611+
612+
return 0;
613+
}
614+
615+
static int src_prepare(struct processing_module *mod,
616+
struct sof_source **sources, int num_of_sources,
617+
struct sof_sink **sinks, int num_of_sinks)
613618
{
619+
struct comp_data *cd = module_get_private_data(mod);
620+
struct src_param *a = &cd->param;
614621
int ret;
615622

616623
comp_info(mod->dev, "src_prepare()");
617624

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

628+
a->in_fs = src_in_fs;
629+
a->out_fs = src_out_fs;
630+
631+
src_get_source_sink_params(mod->dev, sources[0], sinks[0]);
632+
633+
ret = src_param_set(mod->dev, cd);
634+
if (ret < 0)
635+
return ret;
636+
637+
a->stage1 = src_table1[a->idx_out][a->idx_in];
638+
a->stage2 = src_table2[a->idx_out][a->idx_in];
639+
621640
ret = src_params_general(mod, sources[0], sinks[0]);
622641
if (ret < 0)
623642
return ret;

src/audio/src/src.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616
#include <sof/audio/component.h>
1717
#include <sof/audio/module_adapter/module/generic.h>
1818

19+
struct src_stage {
20+
const int idm;
21+
const int odm;
22+
const int num_of_subfilters;
23+
const int subfilter_length;
24+
const int filter_length;
25+
const int blk_in;
26+
const int blk_out;
27+
const int halfband;
28+
const int shift;
29+
const void *coefs; /* Can be int16_t or int32_t depending on config */
30+
};
31+
1932
struct src_param {
2033
int fir_s1;
2134
int fir_s2;
@@ -31,19 +44,10 @@ struct src_param {
3144
int idx_in;
3245
int idx_out;
3346
int nch;
34-
};
35-
36-
struct src_stage {
37-
const int idm;
38-
const int odm;
39-
const int num_of_subfilters;
40-
const int subfilter_length;
41-
const int filter_length;
42-
const int blk_in;
43-
const int blk_out;
44-
const int halfband;
45-
const int shift;
46-
const void *coefs; /* Can be int16_t or int32_t depending on config */
47+
const struct src_stage *stage1;
48+
const struct src_stage *stage2;
49+
const int *in_fs;
50+
const int *out_fs;
4751
};
4852

4953
struct src_state {
@@ -231,9 +235,7 @@ int src_copy_sxx(struct comp_data *cd, struct sof_source *source,
231235
int src_params_general(struct processing_module *mod,
232236
struct sof_source *source,
233237
struct sof_sink *sink);
234-
int src_prepare(struct processing_module *mod,
235-
struct sof_source **sources, int num_of_sources,
236-
struct sof_sink **sinks, int num_of_sinks);
238+
int src_param_set(struct comp_dev *dev, struct comp_data *cd);
237239

238240
bool src_is_ready_to_process(struct processing_module *mod,
239241
struct sof_source **sources, int num_of_sources,

src/audio/src/src_lite.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,53 @@
55
// Author: Fabiola Jasinska <fabiola.jasinska@intel.com>
66

77
#include <rtos/init.h>
8+
89
#include "src.h"
910
#include "src_config.h"
1011

11-
#define SRC_LITE 1
12+
#include "coef/src_lite_ipc4_int32_define.h"
13+
#include "coef/src_lite_ipc4_int32_table.h"
1214

1315
LOG_MODULE_REGISTER(src_lite, CONFIG_SOF_LOG_LEVEL);
1416

17+
/*
18+
* This function is 100% identical to src_prepare(), but it's
19+
* assigning different coefficient arrays because it's including
20+
* different headers.
21+
*/
22+
static int src_lite_prepare(struct processing_module *mod,
23+
struct sof_source **sources, int num_of_sources,
24+
struct sof_sink **sinks, int num_of_sinks)
25+
{
26+
struct comp_data *cd = module_get_private_data(mod);
27+
struct src_param *a = &cd->param;
28+
int ret;
29+
30+
comp_info(mod->dev, "src_prepare()");
31+
32+
if (num_of_sources != 1 || num_of_sinks != 1)
33+
return -EINVAL;
34+
35+
a->in_fs = src_in_fs;
36+
a->out_fs = src_out_fs;
37+
38+
ret = src_param_set(mod->dev, cd);
39+
if (ret < 0)
40+
return ret;
41+
42+
a->stage1 = src_table1[a->idx_out][a->idx_in];
43+
a->stage2 = src_table2[a->idx_out][a->idx_in];
44+
45+
ret = src_params_general(mod, sources[0], sinks[0]);
46+
if (ret < 0)
47+
return ret;
48+
49+
return src_prepare_general(mod, sources[0], sinks[0]);
50+
}
51+
1552
static const struct module_interface src_lite_interface = {
1653
.init = src_init,
17-
.prepare = src_prepare,
54+
.prepare = src_lite_prepare,
1855
.process = src_process,
1956
.is_ready_to_process = src_is_ready_to_process,
2057
.set_configuration = src_set_config,

0 commit comments

Comments
 (0)