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 
19 /************************************************************************************/
20 /*                                                                                  */
21 /*    Includes                                                                      */
22 /*                                                                                  */
23 /************************************************************************************/
24 
25 #include "LVEQNB.h"
26 #include "LVEQNB_Coeffs.h"
27 
28 
29 /************************************************************************************/
30 /*                                                                                  */
31 /*    Sample rate table                                                             */
32 /*                                                                                  */
33 /************************************************************************************/
34 
35 /*
36  * Sample rate table for converting between the enumerated type and the actual
37  * frequency
38  */
39 #if defined(BUILD_FLOAT) && defined(HIGHER_FS)
40 const LVM_UINT32    LVEQNB_SampleRateTab[] = {8000,                    /* 8kS/s  */
41                                               11025,
42                                               12000,
43                                               16000,
44                                               22050,
45                                               24000,
46                                               32000,
47                                               44100,
48                                               48000,
49                                               96000,
50                                               192000
51 };
52 #else
53 const LVM_UINT16    LVEQNB_SampleRateTab[] = {8000,                    /* 8kS/s  */
54                                               11025,
55                                               12000,
56                                               16000,
57                                               22050,
58                                               24000,
59                                               32000,
60                                               44100,
61                                               48000
62 };
63 #endif
64 
65 /************************************************************************************/
66 /*                                                                                  */
67 /*    Coefficient calculation tables                                                */
68 /*                                                                                  */
69 /************************************************************************************/
70 
71 /*
72  * Table for 2 * Pi / Fs
73  */
74 #ifdef BUILD_FLOAT
75 const LVM_FLOAT     LVEQNB_TwoPiOnFsTable[] = {LVEQNB_2PiOn_8000,      /* 8kS/s */
76                                                LVEQNB_2PiOn_11025,
77                                                LVEQNB_2PiOn_12000,
78                                                LVEQNB_2PiOn_16000,
79                                                LVEQNB_2PiOn_22050,
80                                                LVEQNB_2PiOn_24000,
81                                                LVEQNB_2PiOn_32000,
82                                                LVEQNB_2PiOn_44100,
83                                                LVEQNB_2PiOn_48000
84 #ifdef HIGHER_FS
85                                               ,LVEQNB_2PiOn_96000
86                                               ,LVEQNB_2PiOn_192000
87 #endif
88                                                };
89 #else
90 const LVM_INT16     LVEQNB_TwoPiOnFsTable[] = {LVEQNB_2PiOn_8000,      /* 8kS/s */
91                                                LVEQNB_2PiOn_11025,
92                                                LVEQNB_2PiOn_12000,
93                                                LVEQNB_2PiOn_16000,
94                                                LVEQNB_2PiOn_22050,
95                                                LVEQNB_2PiOn_24000,
96                                                LVEQNB_2PiOn_32000,
97                                                LVEQNB_2PiOn_44100,
98                                                LVEQNB_2PiOn_48000};    /* 48kS/s */
99 #endif
100 
101 /*
102  * Gain table
103  */
104 #ifdef BUILD_FLOAT
105 const LVM_FLOAT     LVEQNB_GainTable[] = {LVEQNB_Gain_Neg15_dB,        /* -15dB gain */
106                                           LVEQNB_Gain_Neg14_dB,
107                                           LVEQNB_Gain_Neg13_dB,
108                                           LVEQNB_Gain_Neg12_dB,
109                                           LVEQNB_Gain_Neg11_dB,
110                                           LVEQNB_Gain_Neg10_dB,
111                                           LVEQNB_Gain_Neg9_dB,
112                                           LVEQNB_Gain_Neg8_dB,
113                                           LVEQNB_Gain_Neg7_dB,
114                                           LVEQNB_Gain_Neg6_dB,
115                                           LVEQNB_Gain_Neg5_dB,
116                                           LVEQNB_Gain_Neg4_dB,
117                                           LVEQNB_Gain_Neg3_dB,
118                                           LVEQNB_Gain_Neg2_dB,
119                                           LVEQNB_Gain_Neg1_dB,
120                                           LVEQNB_Gain_0_dB,            /* 0dB gain */
121                                           LVEQNB_Gain_1_dB,
122                                           LVEQNB_Gain_2_dB,
123                                           LVEQNB_Gain_3_dB,
124                                           LVEQNB_Gain_4_dB,
125                                           LVEQNB_Gain_5_dB,
126                                           LVEQNB_Gain_6_dB,
127                                           LVEQNB_Gain_7_dB,
128                                           LVEQNB_Gain_8_dB,
129                                           LVEQNB_Gain_9_dB,
130                                           LVEQNB_Gain_10_dB,
131                                           LVEQNB_Gain_11_dB,
132                                           LVEQNB_Gain_12_dB,
133                                           LVEQNB_Gain_13_dB,
134                                           LVEQNB_Gain_14_dB,
135                                           LVEQNB_Gain_15_dB};          /* +15dB gain */
136 #else
137 const LVM_INT16     LVEQNB_GainTable[] = {LVEQNB_Gain_Neg15_dB,        /* -15dB gain */
138                                           LVEQNB_Gain_Neg14_dB,
139                                           LVEQNB_Gain_Neg13_dB,
140                                           LVEQNB_Gain_Neg12_dB,
141                                           LVEQNB_Gain_Neg11_dB,
142                                           LVEQNB_Gain_Neg10_dB,
143                                           LVEQNB_Gain_Neg9_dB,
144                                           LVEQNB_Gain_Neg8_dB,
145                                           LVEQNB_Gain_Neg7_dB,
146                                           LVEQNB_Gain_Neg6_dB,
147                                           LVEQNB_Gain_Neg5_dB,
148                                           LVEQNB_Gain_Neg4_dB,
149                                           LVEQNB_Gain_Neg3_dB,
150                                           LVEQNB_Gain_Neg2_dB,
151                                           LVEQNB_Gain_Neg1_dB,
152                                           LVEQNB_Gain_0_dB,            /* 0dB gain */
153                                           LVEQNB_Gain_1_dB,
154                                           LVEQNB_Gain_2_dB,
155                                           LVEQNB_Gain_3_dB,
156                                           LVEQNB_Gain_4_dB,
157                                           LVEQNB_Gain_5_dB,
158                                           LVEQNB_Gain_6_dB,
159                                           LVEQNB_Gain_7_dB,
160                                           LVEQNB_Gain_8_dB,
161                                           LVEQNB_Gain_9_dB,
162                                           LVEQNB_Gain_10_dB,
163                                           LVEQNB_Gain_11_dB,
164                                           LVEQNB_Gain_12_dB,
165                                           LVEQNB_Gain_13_dB,
166                                           LVEQNB_Gain_14_dB,
167                                           LVEQNB_Gain_15_dB};          /* +15dB gain */
168 
169 #endif
170 /*
171  * D table for 100 / (Gain + 1)
172  */
173 #ifdef BUILD_FLOAT
174 const LVM_FLOAT    LVEQNB_DTable[] = {LVEQNB_100D_Neg15_dB,            /* -15dB gain */
175                                       LVEQNB_100D_Neg14_dB,
176                                       LVEQNB_100D_Neg13_dB,
177                                       LVEQNB_100D_Neg12_dB,
178                                       LVEQNB_100D_Neg11_dB,
179                                       LVEQNB_100D_Neg10_dB,
180                                       LVEQNB_100D_Neg9_dB,
181                                       LVEQNB_100D_Neg8_dB,
182                                       LVEQNB_100D_Neg7_dB,
183                                       LVEQNB_100D_Neg6_dB,
184                                       LVEQNB_100D_Neg5_dB,
185                                       LVEQNB_100D_Neg4_dB,
186                                       LVEQNB_100D_Neg3_dB,
187                                       LVEQNB_100D_Neg2_dB,
188                                       LVEQNB_100D_Neg1_dB,
189                                       LVEQNB_100D_0_dB};               /* 0dB gain */
190 #else
191 const LVM_INT16    LVEQNB_DTable[] = {LVEQNB_100D_Neg15_dB,            /* -15dB gain */
192                                       LVEQNB_100D_Neg14_dB,
193                                       LVEQNB_100D_Neg13_dB,
194                                       LVEQNB_100D_Neg12_dB,
195                                       LVEQNB_100D_Neg11_dB,
196                                       LVEQNB_100D_Neg10_dB,
197                                       LVEQNB_100D_Neg9_dB,
198                                       LVEQNB_100D_Neg8_dB,
199                                       LVEQNB_100D_Neg7_dB,
200                                       LVEQNB_100D_Neg6_dB,
201                                       LVEQNB_100D_Neg5_dB,
202                                       LVEQNB_100D_Neg4_dB,
203                                       LVEQNB_100D_Neg3_dB,
204                                       LVEQNB_100D_Neg2_dB,
205                                       LVEQNB_100D_Neg1_dB,
206                                       LVEQNB_100D_0_dB};               /* 0dB gain */
207 
208 #endif
209 /************************************************************************************/
210 /*                                                                                  */
211 /*    Filter polynomial coefficients                                                */
212 /*                                                                                  */
213 /************************************************************************************/
214 
215 /*
216  * Coefficients for calculating the cosine with the equation:
217  *
218  *  Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5)
219  *
220  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
221  * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range
222  * +1.0 to -1.0
223  */
224 const LVM_INT16     LVEQNB_CosCoef[] = {3,                             /* Shifts */
225                                         4096,                          /* a0 */
226                                         -36,                           /* a1 */
227                                         -19725,                        /* a2 */
228                                         -2671,                         /* a3 */
229                                         23730,                         /* a4 */
230                                         -9490};                        /* a5 */
231 
232 /*
233  * Coefficients for calculating the cosine error with the equation:
234  *
235  *  CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3)
236  *
237  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
238  * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range
239  * 0.0 to 0.0078852986
240  *
241  * This is used to give a double precision cosine over the range 0 to Pi/25 using the
242  * the equation:
243  *
244  * Cos(x) = 1.0 - CosErr(x)
245  */
246 const LVM_INT16     LVEQNB_DPCosCoef[] = {1,                           /* Shifts */
247                                           0,                           /* a0 */
248                                           -6,                          /* a1 */
249                                           16586,                       /* a2 */
250                                           -44};                        /* a3 */
251 
252 /************************************************************************************/
253 /*                                                                                  */
254 /*  Bypass mixer time constants (100ms)                                             */
255 /*                                                                                  */
256 /************************************************************************************/
257 
258 #define LVEQNB_MIX_TC_Fs8000    32580         /* Floating point value 0.994262695 */
259 #define LVEQNB_MIX_TC_Fs11025   32632         /* Floating point value 0.995849609 */
260 #define LVEQNB_MIX_TC_Fs12000   32643         /* Floating point value 0.996185303 */
261 #define LVEQNB_MIX_TC_Fs16000   32674         /* Floating point value 0.997131348 */
262 #define LVEQNB_MIX_TC_Fs22050   32700         /* Floating point value 0.997924805 */
263 #define LVEQNB_MIX_TC_Fs24000   32705         /* Floating point value 0.998077393 */
264 #define LVEQNB_MIX_TC_Fs32000   32721         /* Floating point value 0.998565674 */
265 #define LVEQNB_MIX_TC_Fs44100   32734         /* Floating point value 0.998962402 */
266 #define LVEQNB_MIX_TC_Fs48000   32737         /* Floating point value 0.999053955 */
267 
268 
269 const LVM_INT16 LVEQNB_MixerTCTable[] = {
270     LVEQNB_MIX_TC_Fs8000,
271     LVEQNB_MIX_TC_Fs11025,
272     LVEQNB_MIX_TC_Fs12000,
273     LVEQNB_MIX_TC_Fs16000,
274     LVEQNB_MIX_TC_Fs22050,
275     LVEQNB_MIX_TC_Fs24000,
276     LVEQNB_MIX_TC_Fs32000,
277     LVEQNB_MIX_TC_Fs44100,
278     LVEQNB_MIX_TC_Fs48000};
279