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_HIFI3_H__
9 #define __SOF_MATH_FIR_HIFI3_H__
10
11 #include <sof/math/fir_config.h>
12
13 #if FIR_HIFI3
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_hifi3.h>
20
21 struct sof_eq_fir_coef_data;
22
23 struct fir_state_32x16 {
24 ae_int32 *rwp; /* Circular read and write pointer */
25 ae_int32 *delay; /* Pointer to FIR delay line */
26 ae_int32 *delay_end; /* Pointer to FIR delay line end */
27 ae_f16x4 *coef; /* Pointer to FIR coefficients */
28 int taps; /* Number of FIR taps */
29 int length; /* Number of FIR taps plus input length (even) */
30 int in_shift; /* Amount of right shifts at input */
31 int out_shift; /* Amount of right shifts at output */
32 };
33
34 void fir_reset(struct fir_state_32x16 *fir);
35
36 int fir_delay_size(struct sof_fir_coef_data *config);
37
38 int fir_init_coef(struct fir_state_32x16 *fir,
39 struct sof_fir_coef_data *config);
40
41 void fir_init_delay(struct fir_state_32x16 *fir, int32_t **data);
42
43 /* Setup circular buffer for FIR input data delay */
fir_core_setup_circular(struct fir_state_32x16 * fir)44 static inline void fir_core_setup_circular(struct fir_state_32x16 *fir)
45 {
46 AE_SETCBEGIN0(fir->delay);
47 AE_SETCEND0(fir->delay_end);
48 }
49
50 /* Setup circular for component buffer */
fir_comp_setup_circular(const struct audio_stream * buffer)51 static inline void fir_comp_setup_circular(const struct audio_stream *buffer)
52 {
53 AE_SETCBEGIN0(buffer->addr);
54 AE_SETCEND0(buffer->end_addr);
55 }
56
57 void fir_get_lrshifts(struct fir_state_32x16 *fir, int *lshift,
58 int *rshift);
59
60 void fir_32x16_hifi3(struct fir_state_32x16 *fir, ae_int32 x, ae_int32 *y,
61 int shift);
62
63 void fir_32x16_2x_hifi3(struct fir_state_32x16 *fir, ae_int32 x0, ae_int32 x1,
64 ae_int32 *y0, ae_int32 *y1, int shift);
65
66 #endif
67 #endif /* __SOF_MATH_FIR_HIFI3_H__ */
68