Skip to content

Commit

Permalink
src_lite: add module
Browse files Browse the repository at this point in the history
Addition of SRC Lite module,
which only supports a subset of conversions
supported by the SRC module.

Purpose of SRC Lite module is memory optimization.
Code of SRC Lite is drastically reduced and requires
significantly less memory. When needed one of
defined conversions, driver can choose SRC Lite
module instead of SRC module to optimize memory utilization.

48 -> 16kHz
44.1 -> 16 kHz
32 -> 16 kHz
44.1 -> 48

Signed-off-by: Fabiola Kwasowiec <[email protected]>
  • Loading branch information
fkwasowi committed Oct 22, 2023
1 parent 1fc1d28 commit df50371
Show file tree
Hide file tree
Showing 9 changed files with 279 additions and 86 deletions.
1 change: 1 addition & 0 deletions app/boards/intel_adsp_ace15_mtpm.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ CONFIG_IPC_MAJOR_4=y

CONFIG_COMP_SRC=y
CONFIG_COMP_SRC_IPC4_FULL_MATRIX=y
CONFIG_COMP_SRC_LITE=y
CONFIG_COMP_DRC=y
CONFIG_COMP_CROSSOVER=y
CONFIG_COMP_MULTIBAND_DRC=y
Expand Down
12 changes: 12 additions & 0 deletions src/audio/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,18 @@ config COMP_SRC
help
Select for SRC component

config COMP_SRC_LITE
bool "SRC_LITE component"
default y
help
Select for SRC_LITE component
which only supports a subset of conversions
supported by the SRC module:
48 -> 16kHz
44.1 -> 16 kHz
32 -> 16 kHz
44.1 -> 48

config COMP_STUBS
bool "Build all selected third-party (3P) components with stubs"
default n
Expand Down
23 changes: 23 additions & 0 deletions src/audio/src/coef/src_lite_ipc4_int32_define.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
* Author: Fabiola Jasinska <[email protected]>
*/

#ifndef __SOF_AUDIO_COEFFICIENTS_SRC_SRC_IPC4_INT32_DEFINE_H__
#define __SOF_AUDIO_COEFFICIENTS_SRC_SRC_IPC4_INT32_DEFINE_H__

/* SRC constants */
#define MAX_FIR_DELAY_SIZE 730
#define MAX_OUT_DELAY_SIZE 900
#define MAX_BLK_IN 80
#define MAX_BLK_OUT 40
#define NUM_IN_FS 16
#define NUM_OUT_FS 10
#define STAGE1_TIMES_MAX 32
#define STAGE2_TIMES_MAX 32
#define STAGE_BUF_SIZE 672
#define NUM_ALL_COEFFICIENTS 69224

#endif /* __SOF_AUDIO_COEFFICIENTS_SRC_SRC_IPC4_INT32_DEFINE_H__ */
43 changes: 43 additions & 0 deletions src/audio/src/coef/src_lite_ipc4_int32_table.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright(c) 2023 Intel Corporation. All rights reserved.
*
*/

/** \cond GENERATED_BY_TOOLS_TUNE_SRC */

#ifndef __SOF_AUDIO_COEFFICIENTS_SRC_src_IPC4_INT32_TABLE_H__
#define __SOF_AUDIO_COEFFICIENTS_SRC_src_IPC4_INT32_TABLE_H__

/* SRC conversions */
#include "src_ipc4_int32_1_2_4535_5000.h"
#include "src_ipc4_int32_10_21_3455_5000.h"
#include "src_ipc4_int32_1_3_4535_5000.h"
#include "src_ipc4_int32_3_2_4535_5000.h"
#include "src_ipc4_int32_8_7_4535_5000.h"
#include "src_ipc4_int32_16_21_4535_5000.h"
#include "src_ipc4_int32_20_21_4167_5000.h"
#include "../src.h"
#include <stdint.h>

/* SRC table */
int32_t src_fir_one = 1073741824;
struct src_stage src_int32_1_1_0_0 = { 0, 0, 1, 1, 1, 1, 1, 0, -1, &src_fir_one };
struct src_stage src_int32_0_0_0_0 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, &src_fir_one };
int src_in_fs[3] = { 32000, 44100, 48000};
int src_out_fs[2] = {16000, 48000};

struct src_stage *src_table1[2][3] = {
{ &src_int32_1_2_4535_5000, &src_int32_10_21_3455_5000,
&src_int32_1_3_4535_5000 },
{ &src_int32_3_2_4535_5000, &src_int32_8_7_4535_5000, &src_int32_1_1_0_0 }
};

struct src_stage *src_table2[2][3] = {
{ &src_int32_1_1_0_0, &src_int32_16_21_4535_5000, &src_int32_1_1_0_0 },
{ &src_int32_1_1_0_0, &src_int32_20_21_4167_5000, &src_int32_1_1_0_0 }
};

#endif /* __SOF_AUDIO_COEFFICIENTS_SRC_src_IPC4_INT32_TABLE_H__ */

/** \endcond */
122 changes: 39 additions & 83 deletions src/audio/src/src.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@
#include "src.h"
#include "src_config.h"

#if SRC_SHORT || CONFIG_COMP_SRC_TINY
#ifdef SRC_LITE
#include "coef/src_lite_ipc4_int32_define.h"
#include "coef/src_lite_ipc4_int32_table.h"
#elif SRC_SHORT || CONFIG_COMP_SRC_TINY
#include "coef/src_tiny_int16_define.h"
#include "coef/src_tiny_int16_table.h"
#elif CONFIG_COMP_SRC_SMALL
Expand All @@ -63,34 +66,9 @@

LOG_MODULE_REGISTER(src, CONFIG_SOF_LOG_LEVEL);

/* Calculates the needed FIR delay line length */
static int src_fir_delay_length(struct src_stage *s)
{
return s->subfilter_length + (s->num_of_subfilters - 1) * s->idm
+ s->blk_in;
}

/* Calculates the FIR output delay line length */
static int src_out_delay_length(struct src_stage *s)
{
return 1 + (s->num_of_subfilters - 1) * s->odm;
}

/* Returns index of a matching sample rate */
static int src_find_fs(int fs_list[], int list_length, int fs)
{
int i;

for (i = 0; i < list_length; i++) {
if (fs_list[i] == fs)
return i;
}
return -EINVAL;
}

/* Calculates buffers to allocate for a SRC mode */
static int src_buffer_lengths(struct comp_dev *dev, struct comp_data *cd,
int nch)
int src_buffer_lengths(struct comp_dev *dev, struct comp_data *cd,
int nch)
{
struct src_stage *stage1;
struct src_stage *stage2;
Expand Down Expand Up @@ -172,15 +150,9 @@ static int src_buffer_lengths(struct comp_dev *dev, struct comp_data *cd,
return 0;
}

static void src_state_reset(struct src_state *state)
{
state->fir_delay_size = 0;
state->out_delay_size = 0;
}

static int init_stages(struct src_stage *stage1, struct src_stage *stage2,
struct polyphase_src *src, struct src_param *p,
int n, int32_t *delay_lines_start)
int init_stages(struct src_stage *stage1, struct src_stage *stage2,
struct polyphase_src *src, struct src_param *p,
int n, int32_t *delay_lines_start)
{
/* Clear FIR state */
src_state_reset(&src->state1);
Expand Down Expand Up @@ -244,15 +216,6 @@ static int init_stages(struct src_stage *stage1, struct src_stage *stage2,
return 0;
}

void src_polyphase_reset(struct polyphase_src *src)
{
src->number_of_stages = 0;
src->stage1 = NULL;
src->stage2 = NULL;
src_state_reset(&src->state1);
src_state_reset(&src->state2);
}

int src_polyphase_init(struct polyphase_src *src, struct src_param *p,
int32_t *delay_lines_start)
{
Expand Down Expand Up @@ -291,16 +254,9 @@ int src_polyphase_init(struct polyphase_src *src, struct src_param *p,
return n_stages;
}

/* Fallback function */
int src_fallback(struct comp_data *cd, struct sof_source *source,
struct sof_sink *sink)
{
return 0;
}

/* Normal 2 stage SRC */
static int src_2s(struct comp_data *cd,
struct sof_source *source, struct sof_sink *sink)
int src_2s(struct comp_data *cd,
struct sof_source *source, struct sof_sink *sink)
{
struct src_stage_prm s1;
struct src_stage_prm s2;
Expand Down Expand Up @@ -401,8 +357,8 @@ static int src_2s(struct comp_data *cd,
}

/* 1 stage SRC for simple conversions */
static int src_1s(struct comp_data *cd, struct sof_source *source,
struct sof_sink *sink)
int src_1s(struct comp_data *cd, struct sof_source *source,
struct sof_sink *sink)
{
struct src_stage_prm s1;
int ret;
Expand Down Expand Up @@ -441,8 +397,8 @@ static int src_1s(struct comp_data *cd, struct sof_source *source,
}

/* A fast copy function for same in and out rate */
static int src_copy_sxx(struct comp_data *cd, struct sof_source *source,
struct sof_sink *sink)
int src_copy_sxx(struct comp_data *cd, struct sof_source *source,
struct sof_sink *sink)
{
int frames = cd->param.blk_in;

Expand All @@ -468,7 +424,7 @@ void src_set_alignment(struct sof_source *source, struct sof_sink *sink)
sink_set_alignment_constants(sink, byte_align, frame_align_req);
}

static int src_verify_params(struct processing_module *mod)
int src_verify_params(struct processing_module *mod)
{
struct sof_ipc_stream_params *params = mod->stream_params;
struct comp_data *cd = module_get_private_data(mod);
Expand Down Expand Up @@ -505,9 +461,9 @@ static int src_verify_params(struct processing_module *mod)
return ret;
}

static bool src_get_copy_limits(struct comp_data *cd,
struct sof_source *source,
struct sof_sink *sink)
bool src_get_copy_limits(struct comp_data *cd,
struct sof_source *source,
struct sof_sink *sink)
{
struct src_param *sp;
struct src_stage *s1;
Expand Down Expand Up @@ -549,9 +505,9 @@ static bool src_get_copy_limits(struct comp_data *cd,
return true;
}

static int src_params_general(struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink)
int src_params_general(struct processing_module *mod,
struct sof_source *source,
struct sof_sink *sink)
{
struct comp_data *cd = module_get_private_data(mod);
struct comp_dev *dev = mod->dev;
Expand Down Expand Up @@ -652,9 +608,9 @@ static int src_params_general(struct processing_module *mod,
return 0;
}

static int src_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
int src_prepare(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
int ret;

Expand All @@ -671,18 +627,18 @@ static int src_prepare(struct processing_module *mod,
}


static 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)
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)
{
struct comp_data *cd = module_get_private_data(mod);

return src_get_copy_limits(cd, sources[0], sinks[0]);
}

static int src_process(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
int src_process(struct processing_module *mod,
struct sof_source **sources, int num_of_sources,
struct sof_sink **sinks, int num_of_sinks)
{
struct comp_data *cd = module_get_private_data(mod);

Expand All @@ -697,21 +653,21 @@ static int src_process(struct processing_module *mod,
return cd->src_func(cd, sources[0], sinks[0]);
}

static int src_set_config(struct processing_module *mod, uint32_t config_id,
enum module_cfg_fragment_position pos, uint32_t data_offset_size,
const uint8_t *fragment, size_t fragment_size, uint8_t *response,
size_t response_size)
int src_set_config(struct processing_module *mod, uint32_t config_id,
enum module_cfg_fragment_position pos, uint32_t data_offset_size,
const uint8_t *fragment, size_t fragment_size, uint8_t *response,
size_t response_size)
{
return -EINVAL;
}

static int src_get_config(struct processing_module *mod, uint32_t config_id,
uint32_t *data_offset_size, uint8_t *fragment, size_t fragment_size)
int src_get_config(struct processing_module *mod, uint32_t config_id,
uint32_t *data_offset_size, uint8_t *fragment, size_t fragment_size)
{
return -EINVAL;
}

static int src_reset(struct processing_module *mod)
int src_reset(struct processing_module *mod)
{
struct comp_data *cd = module_get_private_data(mod);

Expand All @@ -723,7 +679,7 @@ static int src_reset(struct processing_module *mod)
return 0;
}

static int src_free(struct processing_module *mod)
int src_free(struct processing_module *mod)
{
struct comp_data *cd = module_get_private_data(mod);

Expand Down
Loading

0 comments on commit df50371

Please sign in to comment.