1 /*
2  * Copyright (C) 2004-2010 NXP Software
3  * Copyright (C) 2010 The Android Open Source Project
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef _BIQUAD_H_
19 #define _BIQUAD_H_
20 
21 #include "LVM_Types.h"
22 /**********************************************************************************
23    INSTANCE MEMORY TYPE DEFINITION
24 ***********************************************************************************/
25 typedef struct
26 {
27 #ifdef SUPPORT_MC
28     /* The memory region created by this structure instance is typecast
29      * into another structure containing a pointer and an array of filter
30      * coefficients. In one case this memory region is used for storing
31      * DC component of channels
32      */
33     LVM_FLOAT *pStorage;
34     LVM_FLOAT Storage[LVM_MAX_CHANNELS];
35 #else
36     LVM_FLOAT Storage[6];
37 #endif
38 } Biquad_FLOAT_Instance_t;
39 /**********************************************************************************
40    COEFFICIENT TYPE DEFINITIONS
41 ***********************************************************************************/
42 
43 /*** Biquad coefficients **********************************************************/
44 typedef struct
45 {
46     LVM_FLOAT  A2;   /*  a2  */
47     LVM_FLOAT  A1;   /*  a1  */
48     LVM_FLOAT  A0;   /*  a0  */
49     LVM_FLOAT  B2;   /* -b2! */
50     LVM_FLOAT  B1;   /* -b1! */
51 } BQ_FLOAT_Coefs_t;
52 
53 /*** First order coefficients *****************************************************/
54 typedef struct
55 {
56     LVM_FLOAT A1;   /*  a1  */
57     LVM_FLOAT A0;   /*  a0  */
58     LVM_FLOAT B1;   /* -b1! */
59 } FO_FLOAT_Coefs_t;
60 
61 /*** First order coefficients with Shift*****************************************************/
62 typedef struct
63 {
64     LVM_FLOAT A1;    /*  a1  */
65     LVM_FLOAT A0;    /*  a0  */
66     LVM_FLOAT B1;    /* -b1! */
67 } FO_FLOAT_LShx_Coefs_t;
68 /*** Band pass coefficients *******************************************************/
69 typedef struct
70 {
71     LVM_FLOAT  A0;   /*  a0  */
72     LVM_FLOAT  B2;   /* -b2! */
73     LVM_FLOAT  B1;   /* -b1! */
74 } BP_FLOAT_Coefs_t;
75 
76 /*** Peaking coefficients *********************************************************/
77 typedef struct
78 {
79     LVM_FLOAT A0;   /*  a0  */
80     LVM_FLOAT B2;   /* -b2! */
81     LVM_FLOAT B1;   /* -b1! */
82     LVM_FLOAT  G;   /* Gain */
83 } PK_FLOAT_Coefs_t;
84 
85 /**********************************************************************************
86    TAPS TYPE DEFINITIONS
87 ***********************************************************************************/
88 
89 /*** Types used for first order and shelving filter *******************************/
90 typedef struct
91 {
92     LVM_FLOAT Storage[ (1 * 2) ];  /* One channel, two taps of size LVM_INT32 */
93 } Biquad_1I_Order1_FLOAT_Taps_t;
94 
95 typedef struct
96 {
97 #ifdef SUPPORT_MC
98     /* LVM_MAX_CHANNELS channels, two taps of size LVM_FLOAT */
99     LVM_FLOAT Storage[ (LVM_MAX_CHANNELS * 2) ];
100 #else
101     LVM_FLOAT Storage[ (2 * 2) ];  /* Two channels, two taps of size LVM_FLOAT */
102 #endif
103 } Biquad_2I_Order1_FLOAT_Taps_t;
104 
105 /*** Types used for biquad, band pass and peaking filter **************************/
106 typedef struct
107 {
108     LVM_FLOAT Storage[ (1 * 4) ];  /* One channel, four taps of size LVM_FLOAT */
109 } Biquad_1I_Order2_FLOAT_Taps_t;
110 
111 typedef struct
112 {
113 #ifdef SUPPORT_MC
114     /* LVM_MAX_CHANNELS, four taps of size LVM_FLOAT */
115     LVM_FLOAT Storage[ (LVM_MAX_CHANNELS * 4) ];
116 #else
117     LVM_FLOAT Storage[ (2 * 4) ];  /* Two channels, four taps of size LVM_FLOAT */
118 #endif
119 } Biquad_2I_Order2_FLOAT_Taps_t;
120 /* The names of the functions are changed to satisfy QAC rules: Name should be Unique withing 16 characters*/
121 #define BQ_2I_D32F32Cll_TRC_WRA_01_Init  Init_BQ_2I_D32F32Cll_TRC_WRA_01
122 #define BP_1I_D32F32C30_TRC_WRA_02       TWO_BP_1I_D32F32C30_TRC_WRA_02
123 
124 /**********************************************************************************
125    FUNCTION PROTOTYPES: BIQUAD FILTERS
126 ***********************************************************************************/
127 
128 /*** 16 bit data path *************************************************************/
129 
130 void BQ_2I_D16F32Css_TRC_WRA_01_Init (   Biquad_FLOAT_Instance_t         *pInstance,
131                                          Biquad_2I_Order2_FLOAT_Taps_t   *pTaps,
132                                          BQ_FLOAT_Coefs_t            *pCoef);
133 
134 void BQ_2I_D16F32C15_TRC_WRA_01 (           Biquad_FLOAT_Instance_t       *pInstance,
135                                             LVM_FLOAT                    *pDataIn,
136                                             LVM_FLOAT                    *pDataOut,
137                                             LVM_INT16                    NrSamples);
138 
139 void BQ_2I_D16F32C14_TRC_WRA_01 (           Biquad_FLOAT_Instance_t       *pInstance,
140                                             LVM_FLOAT                    *pDataIn,
141                                             LVM_FLOAT                    *pDataOut,
142                                             LVM_INT16                    NrSamples);
143 
144 void BQ_2I_D16F32C13_TRC_WRA_01 (           Biquad_FLOAT_Instance_t       *pInstance,
145                                             LVM_FLOAT                    *pDataIn,
146                                             LVM_FLOAT                    *pDataOut,
147                                             LVM_INT16                    NrSamples);
148 
149 void BQ_2I_D16F16Css_TRC_WRA_01_Init (   Biquad_FLOAT_Instance_t         *pInstance,
150                                          Biquad_2I_Order2_FLOAT_Taps_t   *pTaps,
151                                          BQ_FLOAT_Coefs_t            *pCoef);
152 
153 void BQ_2I_D16F16C15_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
154                                  LVM_FLOAT               *pDataIn,
155                                  LVM_FLOAT               *pDataOut,
156                                  LVM_INT16               NrSamples);
157 
158 void BQ_2I_D16F16C14_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
159                                  LVM_FLOAT               *pDataIn,
160                                  LVM_FLOAT               *pDataOut,
161                                  LVM_INT16               NrSamples);
162 
163 void BQ_1I_D16F16Css_TRC_WRA_01_Init (   Biquad_FLOAT_Instance_t         *pInstance,
164                                          Biquad_1I_Order2_FLOAT_Taps_t   *pTaps,
165                                          BQ_FLOAT_Coefs_t            *pCoef);
166 
167 void BQ_1I_D16F16C15_TRC_WRA_01 ( Biquad_FLOAT_Instance_t       *pInstance,
168                                   LVM_FLOAT               *pDataIn,
169                                   LVM_FLOAT               *pDataOut,
170                                   LVM_INT16               NrSamples);
171 
172 void BQ_1I_D16F32Css_TRC_WRA_01_Init (   Biquad_FLOAT_Instance_t         *pInstance,
173                                          Biquad_1I_Order2_FLOAT_Taps_t   *pTaps,
174                                          BQ_FLOAT_Coefs_t            *pCoef);
175 
176 void BQ_1I_D16F32C14_TRC_WRA_01 ( Biquad_FLOAT_Instance_t       *pInstance,
177                                   LVM_FLOAT              *pDataIn,
178                                   LVM_FLOAT               *pDataOut,
179                                   LVM_INT16               NrSamples);
180 /*** 32 bit data path *************************************************************/
181 void BQ_2I_D32F32Cll_TRC_WRA_01_Init (      Biquad_FLOAT_Instance_t       *pInstance,
182                                             Biquad_2I_Order2_FLOAT_Taps_t *pTaps,
183                                             BQ_FLOAT_Coefs_t          *pCoef);
184 void BQ_2I_D32F32C30_TRC_WRA_01 (           Biquad_FLOAT_Instance_t  *pInstance,
185                                             LVM_FLOAT                    *pDataIn,
186                                             LVM_FLOAT                    *pDataOut,
187                                             LVM_INT16                 NrSamples);
188 #ifdef SUPPORT_MC
189 void BQ_MC_D32F32C30_TRC_WRA_01 (           Biquad_FLOAT_Instance_t      *pInstance,
190                                             LVM_FLOAT                    *pDataIn,
191                                             LVM_FLOAT                    *pDataOut,
192                                             LVM_INT16                    NrFrames,
193                                             LVM_INT16                    NrChannels);
194 #endif
195 
196 /**********************************************************************************
197    FUNCTION PROTOTYPES: FIRST ORDER FILTERS
198 ***********************************************************************************/
199 
200 /*** 16 bit data path *************************************************************/
201 void FO_1I_D16F16Css_TRC_WRA_01_Init(    Biquad_FLOAT_Instance_t         *pInstance,
202                                          Biquad_1I_Order1_FLOAT_Taps_t   *pTaps,
203                                          FO_FLOAT_Coefs_t            *pCoef);
204 
205 void FO_1I_D16F16C15_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
206                                  LVM_FLOAT               *pDataIn,
207                                  LVM_FLOAT               *pDataOut,
208                                  LVM_INT16               NrSamples);
209 
210 void FO_2I_D16F32Css_LShx_TRC_WRA_01_Init(Biquad_FLOAT_Instance_t       *pInstance,
211                                           Biquad_2I_Order1_FLOAT_Taps_t *pTaps,
212                                           FO_FLOAT_LShx_Coefs_t     *pCoef);
213 
214 void FO_2I_D16F32C15_LShx_TRC_WRA_01(Biquad_FLOAT_Instance_t       *pInstance,
215                                      LVM_FLOAT               *pDataIn,
216                                      LVM_FLOAT               *pDataOut,
217                                      LVM_INT16               NrSamples);
218 /*** 32 bit data path *************************************************************/
219 void FO_1I_D32F32Cll_TRC_WRA_01_Init( Biquad_FLOAT_Instance_t       *pInstance,
220                                       Biquad_1I_Order1_FLOAT_Taps_t *pTaps,
221                                       FO_FLOAT_Coefs_t          *pCoef);
222 void FO_1I_D32F32C31_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
223                                  LVM_FLOAT                     *pDataIn,
224                                  LVM_FLOAT                     *pDataOut,
225                                  LVM_INT16                     NrSamples);
226 #ifdef SUPPORT_MC
227 void FO_Mc_D16F32C15_LShx_TRC_WRA_01(Biquad_FLOAT_Instance_t  *pInstance,
228                                      LVM_FLOAT                *pDataIn,
229                                      LVM_FLOAT                *pDataOut,
230                                      LVM_INT16                NrFrames,
231                                      LVM_INT16                NrChannels);
232 #endif
233 /**********************************************************************************
234    FUNCTION PROTOTYPES: BAND PASS FILTERS
235 ***********************************************************************************/
236 
237 /*** 16 bit data path *************************************************************/
238 void BP_1I_D16F16Css_TRC_WRA_01_Init( Biquad_FLOAT_Instance_t       *pInstance,
239                                       Biquad_1I_Order2_FLOAT_Taps_t *pTaps,
240                                       BP_FLOAT_Coefs_t              *pCoef);
241 void BP_1I_D16F16C14_TRC_WRA_01 (     Biquad_FLOAT_Instance_t       *pInstance,
242                                       LVM_FLOAT                     *pDataIn,
243                                       LVM_FLOAT                     *pDataOut,
244                                       LVM_INT16                     NrSamples);
245 void BP_1I_D16F32Cll_TRC_WRA_01_Init (Biquad_FLOAT_Instance_t       *pInstance,
246                                       Biquad_1I_Order2_FLOAT_Taps_t *pTaps,
247                                       BP_FLOAT_Coefs_t              *pCoef);
248 void BP_1I_D16F32C30_TRC_WRA_01 (           Biquad_FLOAT_Instance_t       *pInstance,
249                                             LVM_FLOAT                    *pDataIn,
250                                             LVM_FLOAT                    *pDataOut,
251                                             LVM_INT16                    NrSamples);
252 /*** 32 bit data path *************************************************************/
253 void BP_1I_D32F32Cll_TRC_WRA_02_Init (      Biquad_FLOAT_Instance_t       *pInstance,
254                                             Biquad_1I_Order2_FLOAT_Taps_t *pTaps,
255                                             BP_FLOAT_Coefs_t          *pCoef);
256 void BP_1I_D32F32C30_TRC_WRA_02(            Biquad_FLOAT_Instance_t       *pInstance,
257                                             LVM_FLOAT                    *pDataIn,
258                                             LVM_FLOAT                    *pDataOut,
259                                             LVM_INT16                    NrSamples);
260 
261 /*** 32 bit data path STEREO ******************************************************/
262 void PK_2I_D32F32CssGss_TRC_WRA_01_Init (   Biquad_FLOAT_Instance_t       *pInstance,
263                                             Biquad_2I_Order2_FLOAT_Taps_t *pTaps,
264                                             PK_FLOAT_Coefs_t          *pCoef);
265 void PK_2I_D32F32C14G11_TRC_WRA_01( Biquad_FLOAT_Instance_t       *pInstance,
266                                     LVM_FLOAT               *pDataIn,
267                                     LVM_FLOAT               *pDataOut,
268                                     LVM_INT16               NrSamples);
269 #ifdef SUPPORT_MC
270 void PK_Mc_D32F32C14G11_TRC_WRA_01(Biquad_FLOAT_Instance_t       *pInstance,
271                                    LVM_FLOAT               *pDataIn,
272                                    LVM_FLOAT               *pDataOut,
273                                    LVM_INT16               NrFrames,
274                                    LVM_INT16               NrChannels);
275 #endif
276 
277 /**********************************************************************************
278    FUNCTION PROTOTYPES: DC REMOVAL FILTERS
279 ***********************************************************************************/
280 
281 /*** 16 bit data path STEREO ******************************************************/
282 #ifdef SUPPORT_MC
283 void DC_Mc_D16_TRC_WRA_01_Init     (        Biquad_FLOAT_Instance_t       *pInstance);
284 
285 void DC_Mc_D16_TRC_WRA_01          (        Biquad_FLOAT_Instance_t       *pInstance,
286                                             LVM_FLOAT               *pDataIn,
287                                             LVM_FLOAT               *pDataOut,
288                                             LVM_INT16               NrFrames,
289                                             LVM_INT16               NrChannels);
290 #else
291 void DC_2I_D16_TRC_WRA_01_Init     (        Biquad_FLOAT_Instance_t       *pInstance);
292 
293 void DC_2I_D16_TRC_WRA_01          (        Biquad_FLOAT_Instance_t       *pInstance,
294                                             LVM_FLOAT               *pDataIn,
295                                             LVM_FLOAT               *pDataOut,
296                                             LVM_INT16               NrSamples);
297 #endif
298 
299 /**********************************************************************************/
300 
301 #endif  /** _BIQUAD_H_ **/
302 
303