Skip to content

Commit

Permalink
audio: asrc: move coefficients to DRAM
Browse files Browse the repository at this point in the history
Free SRAM by moving ASRC coefficients to DRAM and only copying the
single required array on demand.

Signed-off-by: Guennadi Liakhovetski <guennadi.liakhovetski@linux.intel.com>
  • Loading branch information
lyakh authored and lgirdwood committed Mar 4, 2025
1 parent 9938f2b commit 901aeb3
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 25 deletions.
2 changes: 2 additions & 0 deletions src/audio/asrc/asrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ static int asrc_free(struct processing_module *mod)

rfree(cd->buf);
asrc_release_buffers(cd->asrc_obj);
asrc_free_polyphase_filter(cd->asrc_obj);
rfree(cd->asrc_obj);
rfree(cd);
return 0;
Expand Down Expand Up @@ -851,6 +852,7 @@ static int asrc_reset(struct processing_module *mod)

/* Free the allocations those were done in prepare() */
asrc_release_buffers(cd->asrc_obj);
asrc_free_polyphase_filter(cd->asrc_obj);
rfree(cd->asrc_obj);
rfree(cd->buf);
cd->asrc_obj = NULL;
Expand Down
53 changes: 40 additions & 13 deletions src/audio/asrc/asrc_farrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <rtos/string.h>
#include <sof/trace/trace.h>
#include <sof/audio/format.h>
#include <sof/lib/fast-get.h>
#include <sof/lib/memory.h>
#include <user/trace.h>
#include "asrc_farrow.h"

Expand Down Expand Up @@ -506,6 +508,31 @@ enum asrc_error_code asrc_set_output_format(struct comp_dev *dev,
return ASRC_EC_OK;
}

static const int32_t *__get_polyphase_filter(const int32_t *filter, size_t size)
{
#if CONFIG_FAST_GET
return fast_get(filter, size);
#else
return filter;
#endif
}

#define get_polyphase_filter(f) __get_polyphase_filter(f, sizeof(f))

static void put_polyphase_filter(const int32_t *filter)
{
#if CONFIG_FAST_GET
fast_put(filter);
#endif
}

void asrc_free_polyphase_filter(struct asrc_farrow *src_obj)
{
if (src_obj && src_obj->polyphase_filters) {
put_polyphase_filter(src_obj->polyphase_filters);
src_obj->polyphase_filters = NULL;
}
}

/*
* FILTER FUNCTIONS
Expand Down Expand Up @@ -533,7 +560,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
/* Reset coefficients for possible exit with error. */
src_obj->filter_length = 0;
src_obj->num_filters = 0;
src_obj->polyphase_filters = NULL;
asrc_free_polyphase_filter(src_obj);

if (fs_in == 0 || fs_out == 0) {
/* Avoid possible divisions by zero. */
Expand All @@ -549,7 +576,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO48000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO48000].num_filters;
src_obj->polyphase_filters = &coeff48000to48000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to48000);
} else if (fs_in <= fs_out) {
/* All upsampling use cases can share the same set of
* filter coefficients.
Expand All @@ -558,7 +585,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_44100TO48000].filter_length;
src_obj->num_filters =
c_filter_params[CR_44100TO48000].num_filters;
src_obj->polyphase_filters = &coeff44100to48000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff44100to48000);
} else if (fs_in == 48000) {
switch (fs_out) {
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_08000)
Expand All @@ -567,7 +594,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO08000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO08000].num_filters;
src_obj->polyphase_filters = &coeff48000to08000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to08000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_11025)
Expand All @@ -576,7 +603,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO11025].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO11025].num_filters;
src_obj->polyphase_filters = &coeff48000to11025[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to11025);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_12000)
Expand All @@ -585,7 +612,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO12000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO12000].num_filters;
src_obj->polyphase_filters = &coeff48000to12000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to12000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_16000)
Expand All @@ -594,7 +621,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO16000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO16000].num_filters;
src_obj->polyphase_filters = &coeff48000to16000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to16000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_22050)
Expand All @@ -603,7 +630,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO22050].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO22050].num_filters;
src_obj->polyphase_filters = &coeff48000to22050[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to22050);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_24000)
Expand All @@ -612,7 +639,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO24000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO24000].num_filters;
src_obj->polyphase_filters = &coeff48000to24000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to24000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_32000)
Expand All @@ -621,7 +648,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO32000].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO32000].num_filters;
src_obj->polyphase_filters = &coeff48000to32000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to32000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_48000_TO_44100)
Expand All @@ -630,7 +657,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_48000TO44100].filter_length;
src_obj->num_filters =
c_filter_params[CR_48000TO44100].num_filters;
src_obj->polyphase_filters = &coeff48000to44100[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff48000to44100);
break;
#endif
default:
Expand All @@ -646,7 +673,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_24000TO08000].filter_length;
src_obj->num_filters =
c_filter_params[CR_24000TO08000].num_filters;
src_obj->polyphase_filters = &coeff24000to08000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff24000to08000);
break;
#endif
#if (CONFIG_ASRC_SUPPORT_CONVERSION_24000_TO_16000)
Expand All @@ -655,7 +682,7 @@ static enum asrc_error_code initialise_filter(struct comp_dev *dev,
c_filter_params[CR_24000TO16000].filter_length;
src_obj->num_filters =
c_filter_params[CR_24000TO16000].num_filters;
src_obj->polyphase_filters = &coeff24000to16000[0];
src_obj->polyphase_filters = get_polyphase_filter(coeff24000to16000);
break;
#endif
default:
Expand Down
7 changes: 7 additions & 0 deletions src/audio/asrc/asrc_farrow.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,13 @@ enum asrc_error_code asrc_initialise(struct comp_dev *dev,
enum asrc_control_mode control_mode,
enum asrc_operation_mode operation_mode);

/*
* @brief Free polyphase filters
*
* @param[in] src_obj Pointer to the ias_src_farrow.
*/
void asrc_free_polyphase_filter(struct asrc_farrow *src_obj);

/*
* @brief Process the sample rate converter for one frame; the frame
* consists of @p input_num_frames samples within @p num_channels
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_24000Hz_to_08000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 24000 Hz to 8000 Hz */
/* NUM_FILTERS=4, FILTER_LENGTH=128, alpha=6.200000, gamma=0.454000 */

static const int32_t coeff24000to08000[] = {
__cold_rodata static const int32_t coeff24000to08000[] = {
/* Filter #4, conversion from 24000 Hz to 8000 Hz */

CONVERT_COEFF(-10830), /* Filter:4, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_24000Hz_to_16000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 24000 Hz to 16000 Hz */
/* NUM_FILTERS=6, FILTER_LENGTH=80, alpha=6.800000, gamma=0.460000 */

static const int32_t coeff24000to16000[] = {
__cold_rodata static const int32_t coeff24000to16000[] = {
/* Filter #6, conversion from 24000 Hz to 16000 Hz */

CONVERT_COEFF(-26295), /* Filter:6, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_44100Hz_to_48000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 44100 Hz to 48000 Hz */
/* NUM_FILTERS=7, FILTER_LENGTH=64, alpha=7.800000, gamma=0.459000 */

static const int32_t coeff44100to48000[] = {
__cold_rodata static const int32_t coeff44100to48000[] = {
/* Filter #7, conversion from 44100 Hz to 48000 Hz */

CONVERT_COEFF(-36104), /* Filter:7, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_08000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 8000 Hz */
/* NUM_FILTERS=4, FILTER_LENGTH=128, alpha=5.600000, gamma=0.415500 */

static const int32_t coeff48000to08000[] = {
__cold_rodata static const int32_t coeff48000to08000[] = {
/* Filter #4, conversion from 48000 Hz to 8000 Hz */

CONVERT_COEFF(-3301), /* Filter:4, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_11025Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 11025 Hz */
/* NUM_FILTERS=4, FILTER_LENGTH=96, alpha=5.700000, gamma=0.417000 */

static const int32_t coeff48000to11025[] = {
__cold_rodata static const int32_t coeff48000to11025[] = {
/* Filter #4, conversion from 48000 Hz to 11025 Hz */

CONVERT_COEFF(-5276), /* Filter:4, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_12000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 12000 Hz */
/* NUM_FILTERS=4, FILTER_LENGTH=96, alpha=5.700000, gamma=0.424000 */

static const int32_t coeff48000to12000[] = {
__cold_rodata static const int32_t coeff48000to12000[] = {
/* Filter #4, conversion from 48000 Hz to 12000 Hz */

CONVERT_COEFF(9466), /* Filter:4, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_16000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 16000 Hz */
/* NUM_FILTERS=5, FILTER_LENGTH=96, alpha=5.700000, gamma=0.443000 */

static const int32_t coeff48000to16000[] = {
__cold_rodata static const int32_t coeff48000to16000[] = {
/* Filter #5, conversion from 48000 Hz to 16000 Hz */

CONVERT_COEFF(6003), /* Filter:5, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_22050Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 22050 Hz */
/* NUM_FILTERS=5, FILTER_LENGTH=80, alpha=6.900000, gamma=0.440000 */

static const int32_t coeff48000to22050[] = {
__cold_rodata static const int32_t coeff48000to22050[] = {
/* Filter #5, conversion from 48000 Hz to 22050 Hz */

CONVERT_COEFF(7662), /* Filter:5, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_24000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 24000 Hz */
/* NUM_FILTERS=5, FILTER_LENGTH=80, alpha=7.500000, gamma=0.440000 */

static const int32_t coeff48000to24000[] = {
__cold_rodata static const int32_t coeff48000to24000[] = {
/* Filter #5, conversion from 48000 Hz to 24000 Hz */

CONVERT_COEFF(-13838), /* Filter:5, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_32000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 32000 Hz */
/* NUM_FILTERS=6, FILTER_LENGTH=80, alpha=8.000000, gamma=0.452000 */

static const int32_t coeff48000to32000[] = {
__cold_rodata static const int32_t coeff48000to32000[] = {
/* Filter #6, conversion from 48000 Hz to 32000 Hz */

CONVERT_COEFF(-11561), /* Filter:6, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_44100Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 44100 Hz */
/* NUM_FILTERS=7, FILTER_LENGTH=64, alpha=8.150000, gamma=0.456000 */

static const int32_t coeff48000to44100[] = {
__cold_rodata static const int32_t coeff48000to44100[] = {
/* Filter #7, conversion from 48000 Hz to 44100 Hz */

CONVERT_COEFF(-34608), /* Filter:7, Coefficient: 1 */
Expand Down
2 changes: 1 addition & 1 deletion src/audio/asrc/coef/asrc_farrow_coeff_48000Hz_to_48000Hz.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* Conversion from 48000 Hz to 48000 Hz */
/* NUM_FILTERS=7, FILTER_LENGTH=48, alpha=7.150000, gamma=0.458000 */

static const int32_t coeff48000to48000[] = {
__cold_rodata static const int32_t coeff48000to48000[] = {
/* Filter #7, conversion from 48000 Hz to 48000 Hz */

CONVERT_COEFF(201584), /* Filter:7, Coefficient: 1 */
Expand Down

0 comments on commit 901aeb3

Please sign in to comment.