diff --git a/src/audio/CMakeLists.txt b/src/audio/CMakeLists.txt index 425756f7e4d5..c25acf188ae6 100644 --- a/src/audio/CMakeLists.txt +++ b/src/audio/CMakeLists.txt @@ -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) diff --git a/src/audio/eq_fir/CMakeLists.txt b/src/audio/eq_fir/CMakeLists.txt index 2d6e0b5eb834..250ca910658c 100644 --- a/src/audio/eq_fir/CMakeLists.txt +++ b/src/audio/eq_fir/CMakeLists.txt @@ -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() + diff --git a/src/audio/eq_fir/eq_fir.c b/src/audio/eq_fir/eq_fir.c index cd7157b4c4b8..ae684f851406 100644 --- a/src/audio/eq_fir/eq_fir.c +++ b/src/audio/eq_fir/eq_fir.c @@ -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); diff --git a/src/audio/eq_fir/eq_fir.h b/src/audio/eq_fir/eq_fir.h index b02af9743e35..fafca0e485f7 100644 --- a/src/audio/eq_fir/eq_fir.h +++ b/src/audio/eq_fir/eq_fir.h @@ -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 diff --git a/src/audio/eq_fir/eq_fir_ipc3.c b/src/audio/eq_fir/eq_fir_ipc3.c new file mode 100644 index 000000000000..cd4599454c76 --- /dev/null +++ b/src/audio/eq_fir/eq_fir_ipc3.c @@ -0,0 +1,77 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2017 Intel Corporation. All rights reserved. +// +// Author: Seppo Ingalsuo +// Liam Girdwood +// Keyon Jie + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} + diff --git a/src/audio/eq_fir/eq_fir_ipc4.c b/src/audio/eq_fir/eq_fir_ipc4.c new file mode 100644 index 000000000000..00ddbf1b18ba --- /dev/null +++ b/src/audio/eq_fir/eq_fir_ipc4.c @@ -0,0 +1,102 @@ +// SPDX-License-Identifier: BSD-3-Clause +// +// Copyright(c) 2017 Intel Corporation. All rights reserved. +// +// Author: Seppo Ingalsuo +// Liam Girdwood +// Keyon Jie + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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; +} diff --git a/src/audio/eq_iir/CMakeLists.txt b/src/audio/eq_iir/CMakeLists.txt index 0c9853540ad5..218d64e88ec8 100644 --- a/src/audio/eq_iir/CMakeLists.txt +++ b/src/audio/eq_iir/CMakeLists.txt @@ -5,4 +5,4 @@ if(CONFIG_IPC_MAJOR_3) add_local_sources(sof eq_iir_ipc3.c) elseif(CONFIG_IPC_MAJOR_4) add_local_sources(sof eq_iir_ipc4.c) -endif() +endif() \ No newline at end of file diff --git a/test/cmocka/src/audio/eq_fir/CMakeLists.txt b/test/cmocka/src/audio/eq_fir/CMakeLists.txt index 3369f2b97b06..547cb7be9642 100644 --- a/test/cmocka/src/audio/eq_fir/CMakeLists.txt +++ b/test/cmocka/src/audio/eq_fir/CMakeLists.txt @@ -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 diff --git a/zephyr/CMakeLists.txt b/zephyr/CMakeLists.txt index 892c1b994f7e..ac96dc31447d 100644 --- a/zephyr/CMakeLists.txt +++ b/zephyr/CMakeLists.txt @@ -427,12 +427,34 @@ 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_hifi3.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_hifi2ep.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_generic.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_ipc3.c + ${SOF_MATH_PATH}/fir_generic.c + ${SOF_MATH_PATH}/fir_hifi2ep.c + ${SOF_MATH_PATH}/fir_hifi3.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_hifi3.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_hifi2ep.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_generic.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir.c + ${SOF_AUDIO_PATH}/eq_fir/eq_fir_ipc4.c + ${SOF_MATH_PATH}/fir_generic.c + ${SOF_MATH_PATH}/fir_hifi2ep.c + ${SOF_MATH_PATH}/fir_hifi3.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