From b2fc3b8b0999152ed9b2f974ad48d72d8b13c1d2 Mon Sep 17 00:00:00 2001 From: Baofeng Tian Date: Wed, 20 Dec 2023 11:13:17 +0800 Subject: [PATCH] Audio: crossover: create share header file for crossover and multiband DRC Multiband DRC requires crossover functionality to cover crossover specific process, previously, these information defined in crossover specific directory, now, create a new shared header file for common information shared both in crossover and multiband DRC. Signed-off-by: Baofeng Tian --- src/audio/crossover/crossover.c | 28 +------ src/audio/multiband_drc/multiband_drc.c | 2 +- src/audio/multiband_drc/multiband_drc.h | 2 +- src/audio/multiband_drc/user/multiband_drc.h | 2 +- src/include/kernel/abi.h | 2 +- src/include/sof/audio/crossover/crossover.h | 37 +------- .../sof/audio/crossover/crossover_algorithm.h | 24 ------ src/include/sof/math/crossover_common.h | 84 +++++++++++++++++++ src/include/user/crossover.h | 4 +- 9 files changed, 91 insertions(+), 94 deletions(-) delete mode 100644 src/include/sof/audio/crossover/crossover_algorithm.h create mode 100644 src/include/sof/math/crossover_common.h diff --git a/src/audio/crossover/crossover.c b/src/audio/crossover/crossover.c index 4e89a9d05042..84af2d08ec81 100644 --- a/src/audio/crossover/crossover.c +++ b/src/audio/crossover/crossover.c @@ -11,8 +11,8 @@ #include #include #include +#include #include -#include #include #include #include @@ -51,32 +51,6 @@ static inline void crossover_free_config(struct sof_crossover_config **config) *config = NULL; } -/** - * \brief Reset the state of an LR4 filter. - */ -static inline void crossover_reset_state_lr4(struct iir_state_df2t *lr4) -{ - rfree(lr4->coef); - rfree(lr4->delay); - - lr4->coef = NULL; - lr4->delay = NULL; -} - -/** - * \brief Reset the state (coefficients and delay) of the crossover filter - * of a single channel. - */ -inline void crossover_reset_state_ch(struct crossover_state *ch_state) -{ - int i; - - for (i = 0; i < CROSSOVER_MAX_LR4; i++) { - crossover_reset_state_lr4(&ch_state->lowpass[i]); - crossover_reset_state_lr4(&ch_state->highpass[i]); - } -} - /** * \brief Reset the state (coefficients and delay) of the crossover filter * across all channels diff --git a/src/audio/multiband_drc/multiband_drc.c b/src/audio/multiband_drc/multiband_drc.c index 17e68a46cb40..15f83e63671b 100644 --- a/src/audio/multiband_drc/multiband_drc.c +++ b/src/audio/multiband_drc/multiband_drc.c @@ -5,7 +5,6 @@ // Author: Pin-chih Lin #include -#include #include #include #include @@ -14,6 +13,7 @@ #include #include #include +#include #include #include #include diff --git a/src/audio/multiband_drc/multiband_drc.h b/src/audio/multiband_drc/multiband_drc.h index 45e7e6b3e8ff..dbb56d7b89a6 100644 --- a/src/audio/multiband_drc/multiband_drc.h +++ b/src/audio/multiband_drc/multiband_drc.h @@ -8,7 +8,7 @@ #define __SOF_AUDIO_MULTIBAND_DRC_MULTIBAND_DRC_H__ #include -#include +#include #include #include #include diff --git a/src/audio/multiband_drc/user/multiband_drc.h b/src/audio/multiband_drc/user/multiband_drc.h index 2422e6304fd5..ee8d7ae14f54 100644 --- a/src/audio/multiband_drc/user/multiband_drc.h +++ b/src/audio/multiband_drc/user/multiband_drc.h @@ -9,8 +9,8 @@ #define __USER_MULTIBAND_DRC_H__ #include -#include #include +#include #include "../../drc/drc_user.h" diff --git a/src/include/kernel/abi.h b/src/include/kernel/abi.h index 929f7cbba2df..75ce94a6d468 100644 --- a/src/include/kernel/abi.h +++ b/src/include/kernel/abi.h @@ -29,7 +29,7 @@ /** \brief SOF ABI version major, minor and patch numbers */ #define SOF_ABI_MAJOR 3 -#define SOF_ABI_MINOR 29 +#define SOF_ABI_MINOR 30 #define SOF_ABI_PATCH 0 /** \brief SOF ABI version number. Format within 32bit word is MMmmmppp */ diff --git a/src/include/sof/audio/crossover/crossover.h b/src/include/sof/audio/crossover/crossover.h index cefe7de9271e..ce1da1d73654 100644 --- a/src/include/sof/audio/crossover/crossover.h +++ b/src/include/sof/audio/crossover/crossover.h @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -16,18 +17,6 @@ struct comp_buffer; struct comp_dev; -/* Maximum number of LR4 highpass OR lowpass filters */ -#define CROSSOVER_MAX_LR4 3 -/* Number of delay slots allocated for LR4 Filters */ -#define CROSSOVER_NUM_DELAYS_LR4 4 - -/* Number of sinks for a 2 way crossover filter */ -#define CROSSOVER_2WAY_NUM_SINKS 2 -/* Number of sinks for a 3 way crossover filter */ -#define CROSSOVER_3WAY_NUM_SINKS 3 -/* Number of sinks for a 4 way crossover filter */ -#define CROSSOVER_4WAY_NUM_SINKS 4 - /** * The Crossover filter will have from 2 to 4 outputs. * Diagram of a 4-way Crossover filter (6 LR4 Filters). @@ -58,15 +47,6 @@ struct comp_dev; * */ -/** - * Stores the state of one channel of the Crossover filter - */ -struct crossover_state { - /* Store the state for each LR4 filter. */ - struct iir_state_df2t lowpass[CROSSOVER_MAX_LR4]; - struct iir_state_df2t highpass[CROSSOVER_MAX_LR4]; -}; - struct comp_data; typedef void (*crossover_process)(struct comp_data *cd, @@ -75,9 +55,6 @@ typedef void (*crossover_process)(struct comp_data *cd, int32_t num_sinks, uint32_t frames); -typedef void (*crossover_split)(int32_t in, int32_t out[], - struct crossover_state *state); - /* Crossover component private data */ struct comp_data { /**< filter state */ @@ -137,18 +114,6 @@ static inline crossover_process extern const crossover_split crossover_split_fnmap[]; extern const size_t crossover_split_fncount; -/** - * \brief Returns Crossover split function. - */ -static inline crossover_split crossover_find_split_func(int32_t num_sinks) -{ - if (num_sinks < CROSSOVER_2WAY_NUM_SINKS || - num_sinks > CROSSOVER_4WAY_NUM_SINKS) - return NULL; - // The functions in the map are offset by 2 indices. - return crossover_split_fnmap[num_sinks - CROSSOVER_2WAY_NUM_SINKS]; -} - /* * \brief Runs input in through the LR4 filter and returns it's output. */ diff --git a/src/include/sof/audio/crossover/crossover_algorithm.h b/src/include/sof/audio/crossover/crossover_algorithm.h deleted file mode 100644 index ab7bcf96e4e2..000000000000 --- a/src/include/sof/audio/crossover/crossover_algorithm.h +++ /dev/null @@ -1,24 +0,0 @@ -/* SPDX-License-Identifier: BSD-3-Clause - * - * Copyright(c) 2020 Google LLC. All rights reserved. - * - * Author: Pin-chih Lin - */ -#ifndef __SOF_AUDIO_CROSSOVER_CROSSOVER_ALGORITHM_H__ -#define __SOF_AUDIO_CROSSOVER_CROSSOVER_ALGORITHM_H__ - -#include -#include -#include -#include -#include - -/* crossover reset function */ -void crossover_reset_state_ch(struct crossover_state *ch_state); - -/* crossover init function */ -int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef, - struct crossover_state *ch_state, - int32_t num_sinks); - -#endif // __SOF_AUDIO_CROSSOVER_CROSSOVER_ALGORITHM_H__ diff --git a/src/include/sof/math/crossover_common.h b/src/include/sof/math/crossover_common.h new file mode 100644 index 000000000000..8d5628d4b7ec --- /dev/null +++ b/src/include/sof/math/crossover_common.h @@ -0,0 +1,84 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * + * Copyright(c) 2023 Intel Corporation. All rights reserved. + * + * Author: Baofeng Tian + */ + +#ifndef __SOF_CROSSOVER_COMMON_H__ +#define __SOF_CROSSOVER_COMMON_H__ + +#include +#include + +/* Number of sinks for a 2 way crossover filter */ +#define CROSSOVER_2WAY_NUM_SINKS 2 +/* Number of sinks for a 3 way crossover filter */ +#define CROSSOVER_3WAY_NUM_SINKS 3 +/* Number of sinks for a 4 way crossover filter */ +#define CROSSOVER_4WAY_NUM_SINKS 4 +/* Number of delay slots allocated for LR4 Filters */ +#define CROSSOVER_NUM_DELAYS_LR4 4 +/* Maximum number of LR4 highpass OR lowpass filters */ +#define CROSSOVER_MAX_LR4 3 +/* Maximum Number of sinks allowed in config */ +#define SOF_CROSSOVER_MAX_STREAMS 4 + +/** + * Stores the state of one channel of the Crossover filter + */ +struct crossover_state { + /* Store the state for each LR4 filter. */ + struct iir_state_df2t lowpass[CROSSOVER_MAX_LR4]; + struct iir_state_df2t highpass[CROSSOVER_MAX_LR4]; +}; + +typedef void (*crossover_split)(int32_t in, int32_t out[], + struct crossover_state *state); + +extern const crossover_split crossover_split_fnmap[]; + +/* crossover init function */ +int crossover_init_coef_ch(struct sof_eq_iir_biquad *coef, + struct crossover_state *ch_state, + int32_t num_sinks); + +/** + * \brief Reset the state of an LR4 filter. + */ +static inline void crossover_reset_state_lr4(struct iir_state_df2t *lr4) +{ + rfree(lr4->coef); + rfree(lr4->delay); + + lr4->coef = NULL; + lr4->delay = NULL; +} + +/** + * \brief Reset the state (coefficients and delay) of the crossover filter + * of a single channel. + */ +static inline void crossover_reset_state_ch(struct crossover_state *ch_state) +{ + int i; + + for (i = 0; i < CROSSOVER_MAX_LR4; i++) { + crossover_reset_state_lr4(&ch_state->lowpass[i]); + crossover_reset_state_lr4(&ch_state->highpass[i]); + } +} + +/** + * \brief Returns Crossover split function. + */ +static inline crossover_split crossover_find_split_func(int32_t num_sinks) +{ + if (num_sinks < CROSSOVER_2WAY_NUM_SINKS || + num_sinks > CROSSOVER_4WAY_NUM_SINKS) + return NULL; + // The functions in the map are offset by 2 indices. + return crossover_split_fnmap[num_sinks - CROSSOVER_2WAY_NUM_SINKS]; +} + +#endif /* __SOF_CROSSOVER_COMMON_H__ */ diff --git a/src/include/user/crossover.h b/src/include/user/crossover.h index 445e48acfed2..72bbfac1ba0f 100644 --- a/src/include/user/crossover.h +++ b/src/include/user/crossover.h @@ -10,9 +10,7 @@ #include #include - -/* Maximum Number of sinks allowed in config */ -#define SOF_CROSSOVER_MAX_STREAMS 4 +#include /* Maximum number allowed in configuration blob */ #define SOF_CROSSOVER_MAX_SIZE 1024