1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2017 Intel Corporation. All rights reserved.
4  *
5  * Author: Seppo Ingalsuo <seppo.ingalsuo@linux.intel.com>
6  */
7 
8 #ifndef __SOF_MATH_FIR_HIFI2EP_H__
9 #define __SOF_MATH_FIR_HIFI2EP_H__
10 
11 #include <sof/math/fir_config.h>
12 
13 #if FIR_HIFIEP
14 
15 #include <sof/audio/audio_stream.h>
16 #include <sof/audio/buffer.h>
17 #include <user/fir.h>
18 #include <xtensa/config/defs.h>
19 #include <xtensa/tie/xt_hifi2.h>
20 #include <stdint.h>
21 
22 struct comp_buffer;
23 struct sof_eq_fir_coef_data;
24 
25 struct fir_state_32x16 {
26 	ae_p24x2f *rwp; /* Circular read and write pointer */
27 	ae_p24f *delay; /* Pointer to FIR delay line */
28 	ae_p24f *delay_end; /* Pointer to FIR delay line end */
29 	ae_p16x2s *coef; /* Pointer to FIR coefficients */
30 	int taps; /* Number of FIR taps */
31 	int length; /* Number of FIR taps plus input length (even) */
32 	int in_shift; /* Amount of right shifts at input */
33 	int out_shift; /* Amount of right shifts at output */
34 };
35 
36 void fir_reset(struct fir_state_32x16 *fir);
37 
38 int fir_delay_size(struct sof_fir_coef_data *config);
39 
40 int fir_init_coef(struct fir_state_32x16 *fir,
41 		  struct sof_fir_coef_data *config);
42 
43 void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data);
44 
45 /* Setup circular buffer for FIR input data delay */
fir_hifiep_setup_circular(struct fir_state_32x16 * fir)46 static inline void fir_hifiep_setup_circular(struct fir_state_32x16 *fir)
47 {
48 	AE_SETCBEGIN0(fir->delay);
49 	AE_SETCEND0(fir->delay_end);
50 }
51 
52 void fir_get_lrshifts(struct fir_state_32x16 *fir, int *lshift,
53 		      int *rshift);
54 
55 void fir_32x16_hifiep(struct fir_state_32x16 *fir, int32_t x, int32_t *y, int lshift, int rshift);
56 
57 void fir_32x16_2x_hifiep(struct fir_state_32x16 *fir, int32_t x0, int32_t x1,
58 			 int32_t *y0, int32_t *y1, int lshift, int rshift);
59 
60 #endif
61 #endif /* __SOF_MATH_FIR_HIFI2EP_H__ */
62