|
16 | 16 | #include <sof/audio/sink_api.h> |
17 | 17 | #include <sof/audio/source_api.h> |
18 | 18 | #include <sof/audio/sink_source_utils.h> |
| 19 | +#include <sof/lib/fast-get.h> |
19 | 20 | #include <rtos/panic.h> |
20 | 21 | #include <sof/ipc/msg.h> |
21 | 22 | #include <rtos/alloc.h> |
@@ -592,6 +593,53 @@ int src_param_set(struct comp_dev *dev, struct comp_data *cd) |
592 | 593 | return 0; |
593 | 594 | } |
594 | 595 |
|
| 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 | + |
595 | 643 | bool src_is_ready_to_process(struct processing_module *mod, |
596 | 644 | struct sof_source **sources, int num_of_sources, |
597 | 645 | struct sof_sink **sinks, int num_of_sinks) |
@@ -652,7 +700,13 @@ __cold int src_free(struct processing_module *mod) |
652 | 700 |
|
653 | 701 | /* Free dynamically reserved buffers for SRC algorithm */ |
654 | 702 | 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 |
656 | 710 | rfree(cd); |
657 | 711 | return 0; |
658 | 712 | } |
0 commit comments