Audio: eq_fir: move out eq_fir ipc3 and ipc4 specific code

Move out ipc3 and ipc4 specific code to corresponding source file.
Also, move some common functions to header file.

Signed-off-by: Baofeng Tian <baofeng.tian@intel.com>
This commit is contained in:
Baofeng Tian 2023-11-03 14:46:10 +08:00 committed by Kai Vehmanen
parent df00e71416
commit 5e40ac7c90
8 changed files with 216 additions and 158 deletions

View File

@ -176,10 +176,12 @@ if(CONFIG_IPC_MAJOR_3)
set(volume_sources volume/volume.c volume/volume_generic.c volume/volume_ipc3.c)
set(src_sources src/src.c src/src_ipc3.c src/src_generic.c)
set(eq-iir_sources eq_iir/eq_iir_ipc3.c eq_iir/eq_iir_generic.c)
set(eq-fir_sources eq_fir/eq_fir_ipc3.c)
elseif(CONFIG_IPC_MAJOR_4)
set(volume_sources volume/volume.c volume/volume_generic.c volume/volume_ipc4.c)
set(src_sources src/src.c src/src_ipc4.c src/src_generic.c)
set(eq-iir_sources eq_iir/eq_iir_ipc4.c eq_iir/eq_iir_generic.c)
set(eq-fir_sources eq_fir/eq_fir_ipc4.c)
endif()
set(mixer_sources ${mixer_src})
set(asrc_sources asrc/asrc.c asrc/asrc_farrow.c asrc/asrc_farrow_generic.c)

View File

@ -1,3 +1,9 @@
# SPDX-License-Identifier: BSD-3-Clause
add_local_sources(sof eq_fir.c eq_fir_generic.c eq_fir_hifi2ep.c eq_fir_hifi3.c)
if(CONFIG_IPC_MAJOR_3)
add_local_sources(sof eq_fir_ipc3.c)
elseif(CONFIG_IPC_MAJOR_4)
add_local_sources(sof eq_fir_ipc4.c)
endif()

View File

@ -46,162 +46,6 @@ DECLARE_SOF_RT_UUID("eq-fir", eq_fir_uuid, 0x43a90ce7, 0xf3a5, 0x41df,
DECLARE_TR_CTX(eq_fir_tr, SOF_UUID(eq_fir_uuid), LOG_LEVEL_INFO);
/* src component private data */
struct comp_data {
struct fir_state_32x16 fir[PLATFORM_MAX_CHANNELS]; /**< filters state */
struct comp_data_blob_handler *model_handler;
struct sof_eq_fir_config *config;
int32_t *fir_delay; /**< pointer to allocated RAM */
size_t fir_delay_size; /**< allocated size */
void (*eq_fir_func)(struct fir_state_32x16 fir[],
struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink,
int frames);
int nch;
};
/*
* The optimized FIR functions variants need to be updated into function
* set_fir_func.
*/
#if FIR_HIFI3 || FIR_HIFIEP
#if CONFIG_FORMAT_S16LE
static inline void set_s16_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s16;
}
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
static inline void set_s24_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s24;
}
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
static inline void set_s32_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s32;
}
#endif /* CONFIG_FORMAT_S32LE */
#else
/* FIR_GENERIC */
#if CONFIG_FORMAT_S16LE
static inline void set_s16_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s16;
}
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
static inline void set_s24_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s24;
}
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
static inline void set_s32_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s32;
}
#endif /* CONFIG_FORMAT_S32LE */
#endif
#if CONFIG_IPC_MAJOR_3
static inline int set_fir_func(struct processing_module *mod, enum sof_ipc_frame fmt)
{
struct comp_data *cd = module_get_private_data(mod);
switch (fmt) {
#if CONFIG_FORMAT_S16LE
case SOF_IPC_FRAME_S16_LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S16_LE");
set_s16_fir(cd);
break;
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
case SOF_IPC_FRAME_S24_4LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S24_4LE");
set_s24_fir(cd);
break;
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
case SOF_IPC_FRAME_S32_LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S32_LE");
set_s32_fir(cd);
break;
#endif /* CONFIG_FORMAT_S32LE */
default:
comp_err(mod->dev, "set_fir_func(), invalid frame_fmt");
return -EINVAL;
}
return 0;
}
#endif /* CONFIG_IPC_MAJOR_3 */
#if CONFIG_IPC_MAJOR_4
static inline int set_fir_func(struct processing_module *mod, enum sof_ipc_frame fmt)
{
struct comp_data *cd = module_get_private_data(mod);
unsigned int valid_bit_depth = mod->priv.cfg.base_cfg.audio_fmt.valid_bit_depth;
comp_dbg(mod->dev, "set_fir_func(): valid_bit_depth %d", valid_bit_depth);
switch (valid_bit_depth) {
#if CONFIG_FORMAT_S16LE
case IPC4_DEPTH_16BIT:
set_s16_fir(cd);
break;
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
case IPC4_DEPTH_24BIT:
set_s24_fir(cd);
break;
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
case IPC4_DEPTH_32BIT:
set_s32_fir(cd);
break;
#endif /* CONFIG_FORMAT_S32LE */
default:
comp_err(mod->dev, "set_fir_func(), invalid valid_bith_depth");
return -EINVAL;
}
return 0;
}
static int eq_fir_params(struct processing_module *mod)
{
struct sof_ipc_stream_params *params = mod->stream_params;
struct sof_ipc_stream_params comp_params;
struct comp_dev *dev = mod->dev;
struct comp_buffer *sinkb;
enum sof_ipc_frame valid_fmt, frame_fmt;
int i, ret;
comp_dbg(dev, "eq_fir_params()");
comp_params = *params;
comp_params.channels = mod->priv.cfg.base_cfg.audio_fmt.channels_count;
comp_params.rate = mod->priv.cfg.base_cfg.audio_fmt.sampling_frequency;
comp_params.buffer_fmt = mod->priv.cfg.base_cfg.audio_fmt.interleaving_style;
audio_stream_fmt_conversion(mod->priv.cfg.base_cfg.audio_fmt.depth,
mod->priv.cfg.base_cfg.audio_fmt.valid_bit_depth,
&frame_fmt, &valid_fmt,
mod->priv.cfg.base_cfg.audio_fmt.s_type);
comp_params.frame_fmt = valid_fmt;
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
comp_params.chmap[i] = (mod->priv.cfg.base_cfg.audio_fmt.ch_map >> i * 4) & 0xf;
component_set_nearest_period_frames(dev, comp_params.rate);
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
ret = buffer_set_params(sinkb, &comp_params, true);
return ret;
}
#endif /* CONFIG_IPC_MAJOR_4 */
/* Pass-through functions to replace FIR core while not configured for
* response.
*/
@ -575,13 +419,11 @@ static int eq_fir_prepare(struct processing_module *mod,
comp_dbg(dev, "eq_fir_prepare()");
#if CONFIG_IPC_MAJOR_4
ret = eq_fir_params(mod);
if (ret < 0) {
comp_set_state(dev, COMP_TRIGGER_RESET);
return ret;
}
#endif
/* EQ component will only ever have 1 source and 1 sink buffer. */
sourceb = list_first_item(&dev->bsource_list, struct comp_buffer, sink_list);

View File

@ -28,6 +28,20 @@
#define EQ_FIR_BYTES_TO_S16_SAMPLES(b) ((b) >> 1)
#define EQ_FIR_BYTES_TO_S32_SAMPLES(b) ((b) >> 2)
/* fir component private data */
struct comp_data {
struct fir_state_32x16 fir[PLATFORM_MAX_CHANNELS]; /**< filters state */
struct comp_data_blob_handler *model_handler;
struct sof_eq_fir_config *config;
int32_t *fir_delay; /**< pointer to allocated RAM */
size_t fir_delay_size; /**< allocated size */
void (*eq_fir_func)(struct fir_state_32x16 fir[],
struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink,
int frames);
int nch;
};
#if CONFIG_FORMAT_S16LE
void eq_fir_s16(struct fir_state_32x16 *fir, struct input_stream_buffer *bsource,
struct output_stream_buffer *bsink, int frames);
@ -52,6 +66,57 @@ void eq_fir_2x_s32(struct fir_state_32x16 *fir, struct input_stream_buffer *bsou
struct output_stream_buffer *bsink, int frames);
#endif /* CONFIG_FORMAT_S32LE */
int set_fir_func(struct processing_module *mod, enum sof_ipc_frame fmt);
int eq_fir_params(struct processing_module *mod);
/*
* The optimized FIR functions variants need to be updated into function
* set_fir_func.
*/
#if FIR_HIFI3 || FIR_HIFIEP
#if CONFIG_FORMAT_S16LE
static inline void set_s16_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s16;
}
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
static inline void set_s24_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s24;
}
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
static inline void set_s32_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_2x_s32;
}
#endif /* CONFIG_FORMAT_S32LE */
#else
/* FIR_GENERIC */
#if CONFIG_FORMAT_S16LE
static inline void set_s16_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s16;
}
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
static inline void set_s24_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s24;
}
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
static inline void set_s32_fir(struct comp_data *cd)
{
cd->eq_fir_func = eq_fir_s32;
}
#endif /* CONFIG_FORMAT_S32LE */
#endif
#ifdef UNIT_TEST
void sys_comp_module_eq_fir_interface_init(void);
#endif

View File

@ -0,0 +1,53 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2017 Intel Corporation. All rights reserved.
//
// Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
// Liam Girdwood <liam.r.girdwood@linux.intel.com>
// Keyon Jie <yang.jie@linux.intel.com>
#include <sof/audio/module_adapter/module/generic.h>
#include <ipc/stream.h>
#include <sof/audio/component.h>
#include <sof/trace/trace.h>
#include <errno.h>
#include "eq_fir.h"
LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
int set_fir_func(struct processing_module *mod, enum sof_ipc_frame fmt)
{
struct comp_data *cd = module_get_private_data(mod);
switch (fmt) {
#if CONFIG_FORMAT_S16LE
case SOF_IPC_FRAME_S16_LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S16_LE");
set_s16_fir(cd);
break;
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
case SOF_IPC_FRAME_S24_4LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S24_4LE");
set_s24_fir(cd);
break;
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
case SOF_IPC_FRAME_S32_LE:
comp_dbg(mod->dev, "set_fir_func(), SOF_IPC_FRAME_S32_LE");
set_s32_fir(cd);
break;
#endif /* CONFIG_FORMAT_S32LE */
default:
comp_err(mod->dev, "set_fir_func(), invalid frame_fmt");
return -EINVAL;
}
return 0;
}
int eq_fir_params(struct processing_module *mod)
{
return 0;
}

View File

@ -0,0 +1,81 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2017 Intel Corporation. All rights reserved.
//
// Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
// Liam Girdwood <liam.r.girdwood@linux.intel.com>
// Keyon Jie <yang.jie@linux.intel.com>
#include <sof/audio/module_adapter/module/generic.h>
#include <ipc/stream.h>
#include <sof/audio/component.h>
#include <sof/audio/buffer.h>
#include <sof/audio/audio_stream.h>
#include <sof/list.h>
#include <sof/trace/trace.h>
#include <errno.h>
#include "eq_fir.h"
LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
int set_fir_func(struct processing_module *mod, enum sof_ipc_frame fmt)
{
struct comp_data *cd = module_get_private_data(mod);
unsigned int valid_bit_depth = mod->priv.cfg.base_cfg.audio_fmt.valid_bit_depth;
comp_dbg(mod->dev, "set_fir_func(): valid_bit_depth %d", valid_bit_depth);
switch (valid_bit_depth) {
#if CONFIG_FORMAT_S16LE
case IPC4_DEPTH_16BIT:
set_s16_fir(cd);
break;
#endif /* CONFIG_FORMAT_S16LE */
#if CONFIG_FORMAT_S24LE
case IPC4_DEPTH_24BIT:
set_s24_fir(cd);
break;
#endif /* CONFIG_FORMAT_S24LE */
#if CONFIG_FORMAT_S32LE
case IPC4_DEPTH_32BIT:
set_s32_fir(cd);
break;
#endif /* CONFIG_FORMAT_S32LE */
default:
comp_err(mod->dev, "set_fir_func(), invalid valid_bith_depth");
return -EINVAL;
}
return 0;
}
int eq_fir_params(struct processing_module *mod)
{
struct sof_ipc_stream_params *params = mod->stream_params;
struct sof_ipc_stream_params comp_params;
struct comp_dev *dev = mod->dev;
struct comp_buffer *sinkb;
enum sof_ipc_frame valid_fmt, frame_fmt;
int i, ret;
comp_dbg(dev, "eq_fir_params()");
comp_params = *params;
comp_params.channels = mod->priv.cfg.base_cfg.audio_fmt.channels_count;
comp_params.rate = mod->priv.cfg.base_cfg.audio_fmt.sampling_frequency;
comp_params.buffer_fmt = mod->priv.cfg.base_cfg.audio_fmt.interleaving_style;
audio_stream_fmt_conversion(mod->priv.cfg.base_cfg.audio_fmt.depth,
mod->priv.cfg.base_cfg.audio_fmt.valid_bit_depth,
&frame_fmt, &valid_fmt,
mod->priv.cfg.base_cfg.audio_fmt.s_type);
comp_params.frame_fmt = valid_fmt;
for (i = 0; i < SOF_IPC_MAX_CHANNELS; i++)
comp_params.chmap[i] = (mod->priv.cfg.base_cfg.audio_fmt.ch_map >> i * 4) & 0xf;
component_set_nearest_period_frames(dev, comp_params.rate);
sinkb = list_first_item(&dev->bsink_list, struct comp_buffer, source_list);
ret = buffer_set_params(sinkb, &comp_params, true);
return ret;
}

View File

@ -13,6 +13,7 @@ add_compile_options(-DUNIT_TEST)
add_library(audio_for_eq_fir STATIC
${PROJECT_SOURCE_DIR}/src/audio/eq_fir/eq_fir.c
${PROJECT_SOURCE_DIR}/src/audio/eq_fir/eq_fir_ipc3.c
${PROJECT_SOURCE_DIR}/src/audio/eq_fir/eq_fir_generic.c
${PROJECT_SOURCE_DIR}/src/audio/eq_fir/eq_fir_hifi2ep.c
${PROJECT_SOURCE_DIR}/src/audio/eq_fir/eq_fir_hifi3.c

View File

@ -447,12 +447,20 @@ zephyr_library_sources_ifdef(CONFIG_COMP_FIR
)
if(CONFIG_IPC_MAJOR_3)
zephyr_library_sources_ifdef(CONFIG_COMP_FIR
${SOF_AUDIO_PATH}/eq_fir/eq_fir_ipc3.c
)
zephyr_library_sources_ifdef(CONFIG_COMP_IIR
${SOF_AUDIO_PATH}/eq_iir/eq_iir.c
${SOF_AUDIO_PATH}/eq_iir/eq_iir_ipc3.c
${SOF_AUDIO_PATH}/eq_iir/eq_iir_generic.c
)
elseif(CONFIG_IPC_MAJOR_4)
zephyr_library_sources_ifdef(CONFIG_COMP_FIR
${SOF_AUDIO_PATH}/eq_fir/eq_fir_ipc4.c
)
zephyr_library_sources_ifdef(CONFIG_COMP_IIR
${SOF_AUDIO_PATH}/eq_iir/eq_iir.c
${SOF_AUDIO_PATH}/eq_iir/eq_iir_ipc4.c