Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EQ FIR code re-organize #8436

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()

161 changes: 2 additions & 159 deletions src/audio/eq_fir/eq_fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// Liam Girdwood <[email protected]>
// Keyon Jie <[email protected]>

#include <sof/audio/eq_fir/eq_fir.h>
#include <sof/audio/buffer.h>
#include <sof/audio/component.h>
#include <sof/audio/data_blob.h>
Expand Down Expand Up @@ -37,6 +36,8 @@
#include <stddef.h>
#include <stdint.h>

#include "eq_fir.h"

LOG_MODULE_REGISTER(eq_fir, CONFIG_SOF_LOG_LEVEL);

/* 43a90ce7-f3a5-41df-ac06-ba98651ae6a3 */
Expand All @@ -45,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 @@ -574,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
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
3 changes: 2 additions & 1 deletion src/audio/eq_fir/eq_fir_generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
#if FIR_GENERIC

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/eq_fir/eq_fir.h>
#include <sof/math/fir_generic.h>
#include <errno.h>
#include <stddef.h>
#include <stdint.h>

#include "eq_fir.h"

LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);

#if CONFIG_FORMAT_S16LE
Expand Down
3 changes: 2 additions & 1 deletion src/audio/eq_fir/eq_fir_hifi2ep.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#if FIR_HIFIEP

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/eq_fir/eq_fir.h>
#include <sof/audio/buffer.h>
#include <sof/audio/format.h>
#include <sof/math/fir_hifi2ep.h>
Expand All @@ -19,6 +18,8 @@
#include <stddef.h>
#include <stdint.h>

#include "eq_fir.h"

LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);

#if CONFIG_FORMAT_S32LE
Expand Down
3 changes: 2 additions & 1 deletion src/audio/eq_fir/eq_fir_hifi3.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#if FIR_HIFI3

#include <sof/audio/module_adapter/module/generic.h>
#include <sof/audio/eq_fir/eq_fir.h>
#include <sof/math/fir_hifi3.h>
#include <user/fir.h>
#include <xtensa/config/defs.h>
Expand All @@ -18,6 +17,8 @@
#include <stddef.h>
#include <stdint.h>

#include "eq_fir.h"

LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);

#if CONFIG_FORMAT_S32LE
Expand Down
53 changes: 53 additions & 0 deletions src/audio/eq_fir/eq_fir_ipc3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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/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"
btian1 marked this conversation as resolved.
Show resolved Hide resolved

LOG_MODULE_DECLARE(eq_fir, CONFIG_SOF_LOG_LEVEL);
btian1 marked this conversation as resolved.
Show resolved Hide resolved

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;
btian1 marked this conversation as resolved.
Show resolved Hide resolved
}
return 0;
}

int eq_fir_params(struct processing_module *mod)
{
return 0;
}

Loading