1 // SPDX-License-Identifier: BSD-3-Clause
2 //
3 // Copyright(c) 2022 Intel Corporation. All rights reserved.
4 //
5 // Author: Andrula Song <andrula.song@intel.com>
6 
7 #include <sof/common.h>
8 #include <sof/audio/format.h>
9 #include <sof/math/iir_df1.h>
10 #include <user/eq.h>
11 #include <errno.h>
12 #include <stddef.h>
13 #include <stdint.h>
14 
iir_delay_size_df1(struct sof_eq_iir_header * config)15 int iir_delay_size_df1(struct sof_eq_iir_header *config)
16 {
17 	int n = config->num_sections; /* One section uses two unit delays */
18 
19 	if (n > SOF_EQ_IIR_BIQUADS_MAX || n < 1)
20 		return -EINVAL;
21 
22 	return 4 * n * sizeof(int32_t);
23 }
24 
iir_init_coef_df1(struct iir_state_df1 * iir,struct sof_eq_iir_header * config)25 int iir_init_coef_df1(struct iir_state_df1 *iir,
26 		      struct sof_eq_iir_header *config)
27 {
28 	iir->biquads = config->num_sections;
29 	iir->biquads_in_series = config->num_sections_in_series;
30 	iir->coef = ASSUME_ALIGNED(&config->biquads[0], 4);
31 
32 	return 0;
33 }
34 
iir_init_delay_df1(struct iir_state_df1 * iir,int32_t ** delay)35 void iir_init_delay_df1(struct iir_state_df1 *iir, int32_t **delay)
36 {
37 	/* Set state line of this IIR */
38 	iir->delay = *delay;
39 
40 	/* Point to next IIR delay line start. */
41 	*delay += 4 * iir->biquads;
42 }
43 
iir_reset_df1(struct iir_state_df1 * iir)44 void iir_reset_df1(struct iir_state_df1 *iir)
45 {
46 	iir->biquads = 0;
47 	iir->biquads_in_series = 0;
48 	iir->coef = NULL;
49 	/* Note: May need to know the beginning of dynamic allocation after so
50 	 * omitting setting iir->delay to NULL.
51 	 */
52 }
53