Skip to content

Commit

Permalink
Audio: eq_fir: move out eq_fir ipc3 and ipc4 specific code
Browse files Browse the repository at this point in the history
Move out ipc3 and ipc4 specific code to corresponding source file.
Also, move some common functions to header file.

Signed-off-by: Baofeng Tian <[email protected]>
  • Loading branch information
btian1 committed Nov 3, 2023
1 parent d4d9277 commit 70f7193
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 159 deletions.
2 changes: 2 additions & 0 deletions src/audio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/audio/eq_fir/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()

158 changes: 0 additions & 158 deletions src/audio/eq_fir/eq_fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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);
Expand Down
65 changes: 65 additions & 0 deletions src/audio/eq_fir/eq_fir.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down
77 changes: 77 additions & 0 deletions src/audio/eq_fir/eq_fir_ipc3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// SPDX-License-Identifier: BSD-3-Clause
//
// Copyright(c) 2017 Intel Corporation. All rights reserved.
//
// Author: Seppo Ingalsuo <[email protected]>
// Liam Girdwood <[email protected]>
// Keyon Jie <[email protected]>

#include <sof/audio/buffer.h>
#include <sof/audio/component.h>
#include <sof/audio/data_blob.h>
#include <sof/audio/pipeline.h>
#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/ipc-config.h>
#include <sof/common.h>
#include <rtos/panic.h>
#include <sof/ipc/msg.h>
#include <rtos/alloc.h>
#include <rtos/init.h>
#include <sof/lib/memory.h>
#include <sof/lib/uuid.h>
#include <sof/list.h>
#include <sof/math/fir_config.h>
#include <sof/platform.h>
#include <rtos/string.h>
#include <sof/ut.h>
#include <sof/trace/trace.h>
#include <ipc/control.h>
#include <ipc/stream.h>
#include <ipc/topology.h>
#include <kernel/abi.h>
#include <user/eq.h>
#include <user/fir.h>
#include <user/trace.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.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;
}

Loading

0 comments on commit 70f7193

Please sign in to comment.