Skip to content

Commit 2d03968

Browse files
Jyri Sarhalyakh
authored andcommitted
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 ff46f79 commit 2d03968

File tree

4 files changed

+77
-14
lines changed

4 files changed

+77
-14
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,53 @@ 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_dst;
602+
size_t coef_size[2];
603+
#if SRC_SHORT
604+
size_t tap_size = sizeof(int16_t);
605+
#else
606+
size_t tap_size = sizeof(int32_t);
607+
#endif
608+
609+
stage_dst = rmalloc(SOF_MEM_ZONE_RUNTIME, 0, SOF_MEM_CAPS_RAM,
610+
2 * sizeof(*stage_dst));
611+
if (!stage_dst) {
612+
comp_err(dev, "failed to allocate stages");
613+
return -ENOMEM;
614+
}
615+
616+
/* Make local copies of the src_stages */
617+
stage_dst[0] = *stage_src1;
618+
stage_dst[1] = *stage_src2;
619+
620+
coef_size[0] = tap_size * stage_src1->filter_length;
621+
coef_size[1] = tap_size * stage_src2->filter_length;
622+
623+
stage_dst[0].coefs = fast_get(stage_src1->coefs, coef_size[0]);
624+
stage_dst[1].coefs = fast_get(stage_src2->coefs, coef_size[1]);
625+
626+
if (!stage_dst[0].coefs || !stage_dst[1].coefs) {
627+
comp_err(dev, "failed to allocate coefficients");
628+
fast_put(stage_dst[0].coefs);
629+
rfree(stage_dst);
630+
return -ENOMEM;
631+
}
632+
633+
prm->stage1 = stage_dst;
634+
prm->stage2 = stage_dst + 1;
635+
#else
636+
prm->stage1 = stage_src1;
637+
prm->stage2 = stage_src2;
638+
#endif
639+
640+
return 0;
641+
}
642+
595643
bool src_is_ready_to_process(struct processing_module *mod,
596644
struct sof_source **sources, int num_of_sources,
597645
struct sof_sink **sinks, int num_of_sinks)
@@ -652,7 +700,13 @@ __cold int src_free(struct processing_module *mod)
652700

653701
/* Free dynamically reserved buffers for SRC algorithm */
654702
rfree(cd->delay_lines);
655-
703+
#if CONFIG_FAST_GET
704+
if (cd->param.stage1) {
705+
fast_put(cd->param.stage1->coefs);
706+
fast_put(cd->param.stage2->coefs);
707+
}
708+
rfree((void *)cd->param.stage1);
709+
#endif
656710
rfree(cd);
657711
return 0;
658712
}

src/audio/src/src_common.h

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
#include "src_ipc.h"
1919

2020
struct src_stage {
21-
const int idm;
22-
const int odm;
23-
const int num_of_subfilters;
24-
const int subfilter_length;
25-
const int filter_length;
26-
const int blk_in;
27-
const int blk_out;
28-
const int halfband;
29-
const int shift;
21+
int idm;
22+
int odm;
23+
int num_of_subfilters;
24+
int subfilter_length;
25+
int filter_length;
26+
int blk_in;
27+
int blk_out;
28+
int halfband;
29+
int shift;
3030
const void *coefs; /* Can be int16_t or int32_t depending on config */
3131
};
3232

@@ -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)