Skip to content

Commit

Permalink
Audio: SRC: Coefficients in prepare() to fast SRAM with fast_get()
Browse files Browse the repository at this point in the history
The SRC coefficients are loaded to DRAM and commit copies the
coefficients to SRAM when they are needed. The copying is done using
fast_get() and the copy is released with fast_put() when its not
needed anymore.

Signed-off-by: Jyri Sarha <[email protected]>
  • Loading branch information
Jyri Sarha committed Jan 7, 2025
1 parent 763c50e commit 1c74172
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 5 deletions.
7 changes: 5 additions & 2 deletions src/audio/src/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ static int src_prepare(struct processing_module *mod,
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_allocate_copy_stages(mod->dev, a,
src_table1[a->idx_out][a->idx_in],
src_table2[a->idx_out][a->idx_in]);
if (ret < 0)
return ret;

ret = src_params_general(mod, sources[0], sinks[0]);
if (ret < 0)
Expand Down
59 changes: 58 additions & 1 deletion src/audio/src/src_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <sof/audio/sink_api.h>
#include <sof/audio/source_api.h>
#include <sof/audio/sink_source_utils.h>
#include <sof/lib/fast-get.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
#include <rtos/alloc.h>
Expand Down Expand Up @@ -593,6 +594,60 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd)
return 0;
}

static void debug_print(struct comp_dev *dev, const char *name, const struct src_stage *s)
{
comp_info(dev, "%s: %d, %d, %d, %d, %d, %d, %d, %d, %d, %p", name,
s->idm, s->odm, s->num_of_subfilters, s->subfilter_length,
s->filter_length, s->blk_in, s->blk_out, s->halfband, s->shift,
s->coefs);
}

int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
const struct src_stage *stage_src1,
const struct src_stage *stage_src2)
{
struct src_stage *stage_dst1;
struct src_stage *stage_dst2;
size_t coef_size1;
size_t coef_size2;
char *coef_dst;
const char *coef_src;
#if SRC_SHORT
size_t tap_size = sizeof(int16_t);
#else
size_t tap_size = sizeof(int32_t);
#endif
int ret;

stage_dst1 = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
2 * sizeof(*stage_dst1));
if (!stage_dst1) {
comp_err(dev, "src_allocate_copy_stages(): failed allocate stages");
return -ENOMEM;
}

/* Make local copies of the src_stages */
stage_dst2 = stage_dst1 + 1;
ret = memcpy_s(stage_dst1, sizeof(*stage_dst1), stage_src1, sizeof(*stage_src1));
ret = memcpy_s(stage_dst2, sizeof(*stage_dst2), stage_src2, sizeof(*stage_src2));

coef_size1 = tap_size * stage_src1->filter_length;
coef_size2 = tap_size * stage_src2->filter_length;

stage_dst1->coefs = fast_get(stage_src1->coefs, coef_size1);
stage_dst2->coefs = fast_get(stage_src2->coefs, coef_size2);

if (!stage_dst1->coefs || !stage_dst2->coefs) {
comp_err(dev, "src_allocate_copy_stages(): failed allocate coefficients");
return -ENOMEM;
}

prm->stage1 = stage_dst1;
prm->stage2 = stage_dst2;

return 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 @@ -653,7 +708,9 @@ __cold int src_free(struct processing_module *mod)

/* Free dynamically reserved buffers for SRC algorithm */
rfree(cd->delay_lines);

fast_put((void *)cd->param.stage1->coefs);
fast_put((void *)cd->param.stage2->coefs);
rfree((void *)cd->param.stage1);
rfree(cd);
return 0;
}
3 changes: 3 additions & 0 deletions src/audio/src/src_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,9 @@ static inline int src_fallback(struct comp_data *cd,
return 0;
}

int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
const struct src_stage *stage_src1,
const struct src_stage *stage_src2);
int src_rate_check(const void *spec);
int src_set_params(struct processing_module *mod, struct sof_sink *sink);

Expand Down
7 changes: 5 additions & 2 deletions src/audio/src/src_lite.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@ static int src_lite_prepare(struct processing_module *mod,
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_allocate_copy_stages(mod->dev, a,
src_table1[a->idx_out][a->idx_in],
src_table2[a->idx_out][a->idx_in]);
if (ret < 0)
return ret;

ret = src_params_general(mod, sources[0], sinks[0]);
if (ret < 0)
Expand Down

0 comments on commit 1c74172

Please sign in to comment.