Skip to content

Commit d7f2279

Browse files
author
Jyri Sarha
committed
Audio: SRC: Coefficients in prepare() to fast SRAM with fast_get()
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 <jyri.sarha@linux.intel.com>
1 parent 1199bf3 commit d7f2279

File tree

4 files changed

+68
-5
lines changed

4 files changed

+68
-5
lines changed

src/audio/src/src.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ static int src_prepare(struct processing_module *mod,
5959
if (ret < 0)
6060
return ret;
6161

62-
a->stage1 = src_table1[a->idx_out][a->idx_in];
63-
a->stage2 = src_table2[a->idx_out][a->idx_in];
62+
ret = src_allocate_copy_stages(mod->dev, a,
63+
src_table1[a->idx_out][a->idx_in],
64+
src_table2[a->idx_out][a->idx_in]);
65+
if (ret < 0)
66+
return ret;
6467

6568
ret = src_params_general(mod, sources[0], sinks[0]);
6669
if (ret < 0)

src/audio/src/src_common.c

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <sof/audio/sink_api.h>
1717
#include <sof/audio/source_api.h>
1818
#include <sof/audio/sink_source_utils.h>
19+
#include <sof/lib/fast-get.h>
1920
#include <rtos/panic.h>
2021
#include <sof/ipc/msg.h>
2122
#include <rtos/alloc.h>
@@ -592,6 +593,57 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd)
592593
return 0;
593594
}
594595

596+
int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
597+
const struct src_stage *stage_src1,
598+
const struct src_stage *stage_src2)
599+
{
600+
#if CONFIG_FAST_GET
601+
struct src_stage *stage_dst1;
602+
struct src_stage *stage_dst2;
603+
size_t coef_size1;
604+
size_t coef_size2;
605+
char *coef_dst;
606+
const char *coef_src;
607+
#if SRC_SHORT
608+
size_t tap_size = sizeof(int16_t);
609+
#else
610+
size_t tap_size = sizeof(int32_t);
611+
#endif
612+
int ret;
613+
614+
stage_dst1 = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
615+
2 * sizeof(*stage_dst1));
616+
if (!stage_dst1) {
617+
comp_err(dev, "failed allocate stages");
618+
return -ENOMEM;
619+
}
620+
621+
/* Make local copies of the src_stages */
622+
stage_dst2 = stage_dst1 + 1;
623+
ret = memcpy_s(stage_dst1, sizeof(*stage_dst1), stage_src1, sizeof(*stage_src1));
624+
ret = memcpy_s(stage_dst2, sizeof(*stage_dst2), stage_src2, sizeof(*stage_src2));
625+
626+
coef_size1 = tap_size * stage_src1->filter_length;
627+
coef_size2 = tap_size * stage_src2->filter_length;
628+
629+
stage_dst1->coefs = fast_get(stage_src1->coefs, coef_size1);
630+
stage_dst2->coefs = fast_get(stage_src2->coefs, coef_size2);
631+
632+
if (!stage_dst1->coefs || !stage_dst2->coefs) {
633+
comp_err(dev, "failed allocate coefficients");
634+
return -ENOMEM;
635+
}
636+
637+
prm->stage1 = stage_dst1;
638+
prm->stage2 = stage_dst2;
639+
#else
640+
prm->stage1 = stage_src1;
641+
prm->stage2 = stage_src2;
642+
#endif
643+
644+
return 0;
645+
}
646+
595647
bool src_is_ready_to_process(struct processing_module *mod,
596648
struct sof_source **sources, int num_of_sources,
597649
struct sof_sink **sinks, int num_of_sinks)
@@ -652,7 +704,9 @@ __cold int src_free(struct processing_module *mod)
652704

653705
/* Free dynamically reserved buffers for SRC algorithm */
654706
rfree(cd->delay_lines);
655-
707+
fast_put((void *)cd->param.stage1->coefs);
708+
fast_put((void *)cd->param.stage2->coefs);
709+
rfree((void *)cd->param.stage1);
656710
rfree(cd);
657711
return 0;
658712
}

src/audio/src/src_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,9 @@ static inline int src_fallback(struct comp_data *cd,
215215
return 0;
216216
}
217217

218+
int src_allocate_copy_stages(struct comp_dev *dev, struct src_param *prm,
219+
const struct src_stage *stage_src1,
220+
const struct src_stage *stage_src2);
218221
int src_rate_check(const void *spec);
219222
int src_set_params(struct processing_module *mod, struct sof_sink *sink);
220223

src/audio/src/src_lite.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,11 @@ static int src_lite_prepare(struct processing_module *mod,
4343
if (ret < 0)
4444
return ret;
4545

46-
a->stage1 = src_table1[a->idx_out][a->idx_in];
47-
a->stage2 = src_table2[a->idx_out][a->idx_in];
46+
ret = src_allocate_copy_stages(mod->dev, a,
47+
src_table1[a->idx_out][a->idx_in],
48+
src_table2[a->idx_out][a->idx_in]);
49+
if (ret < 0)
50+
return ret;
4851

4952
ret = src_params_general(mod, sources[0], sinks[0]);
5053
if (ret < 0)

0 commit comments

Comments
 (0)