1 /* SPDX-License-Identifier: BSD-3-Clause
2  *
3  * Copyright(c) 2020 Google LLC. All rights reserved.
4  *
5  * Author: Sebastiano Carlucci <scarlucci@google.com>
6  */
7 
8 #ifndef __SOF_AUDIO_DCBLOCK_DCBLOCK_H__
9 #define __SOF_AUDIO_DCBLOCK_DCBLOCK_H__
10 
11 #include <stdint.h>
12 #include <sof/platform.h>
13 #include <ipc/stream.h>
14 
15 struct audio_stream;
16 struct comp_dev;
17 
18 struct dcblock_state {
19 	int32_t x_prev; /**< state variable referring to x[n-1] */
20 	int32_t y_prev; /**< state variable referring to y[n-1] */
21 };
22 
23 /**
24  * \brief Type definition for the processing function for the
25  * DC Blocking Filter.
26  */
27 typedef void (*dcblock_func)(const struct comp_dev *dev,
28 			     const struct audio_stream *source,
29 			     const struct audio_stream *sink,
30 			     uint32_t frames);
31 
32 /* DC Blocking Filter component private data */
33 struct comp_data {
34 	/**< filters state */
35 	struct dcblock_state state[PLATFORM_MAX_CHANNELS];
36 
37 	/** coefficients for the processing function */
38 	int32_t R_coeffs[PLATFORM_MAX_CHANNELS];
39 
40 	enum sof_ipc_frame source_format;
41 	enum sof_ipc_frame sink_format;
42 	dcblock_func dcblock_func; /**< processing function */
43 };
44 
45 /** \brief DC Blocking Filter processing functions map item. */
46 struct dcblock_func_map {
47 	enum sof_ipc_frame src_fmt; /**< source frame format */
48 	dcblock_func func; /**< processing function */
49 };
50 
51 /** \brief Map of formats with dedicated processing functions. */
52 extern const struct dcblock_func_map dcblock_fnmap[];
53 
54 /** \brief Number of processing functions. */
55 extern const size_t dcblock_fncount;
56 
57 /**
58  * \brief Retrieves a DC Blocking processing function matching
59  *	  the source buffer's frame format.
60  * \param src_fmt the frames' format of the source buffer
61  */
dcblock_find_func(enum sof_ipc_frame src_fmt)62 static inline dcblock_func dcblock_find_func(enum sof_ipc_frame src_fmt)
63 {
64 	int i;
65 
66 	/* Find suitable processing function from map */
67 	for (i = 0; i < dcblock_fncount; i++) {
68 		if (src_fmt == dcblock_fnmap[i].src_fmt)
69 			return dcblock_fnmap[i].func;
70 	}
71 
72 	return NULL;
73 }
74 
75 #endif /* __SOF_AUDIO_DCBLOCK_DCBLOCK_H__ */
76