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 const LVM_UINT16    LVEQNB_SampleRateTab[] = {8000,                    /* 8kS/s  */
40                                               11025,
41                                               12000,
42                                               16000,
43                                               22050,
44                                               24000,
45                                               32000,
46                                               44100,
47                                               48000};                  /* 48kS/s */
48 
49 
50 /************************************************************************************/
51 /*                                                                                  */
52 /*    Coefficient calculation tables                                                */
53 /*                                                                                  */
54 /************************************************************************************/
55 
56 /*
57  * Table for 2 * Pi / Fs
58  */
59 const LVM_INT16     LVEQNB_TwoPiOnFsTable[] = {LVEQNB_2PiOn_8000,      /* 8kS/s */
60                                                LVEQNB_2PiOn_11025,
61                                                LVEQNB_2PiOn_12000,
62                                                LVEQNB_2PiOn_16000,
63                                                LVEQNB_2PiOn_22050,
64                                                LVEQNB_2PiOn_24000,
65                                                LVEQNB_2PiOn_32000,
66                                                LVEQNB_2PiOn_44100,
67                                                LVEQNB_2PiOn_48000};    /* 48kS/s */
68 
69 /*
70  * Gain table
71  */
72 const LVM_INT16     LVEQNB_GainTable[] = {LVEQNB_Gain_Neg15_dB,        /* -15dB gain */
73                                           LVEQNB_Gain_Neg14_dB,
74                                           LVEQNB_Gain_Neg13_dB,
75                                           LVEQNB_Gain_Neg12_dB,
76                                           LVEQNB_Gain_Neg11_dB,
77                                           LVEQNB_Gain_Neg10_dB,
78                                           LVEQNB_Gain_Neg9_dB,
79                                           LVEQNB_Gain_Neg8_dB,
80                                           LVEQNB_Gain_Neg7_dB,
81                                           LVEQNB_Gain_Neg6_dB,
82                                           LVEQNB_Gain_Neg5_dB,
83                                           LVEQNB_Gain_Neg4_dB,
84                                           LVEQNB_Gain_Neg3_dB,
85                                           LVEQNB_Gain_Neg2_dB,
86                                           LVEQNB_Gain_Neg1_dB,
87                                           LVEQNB_Gain_0_dB,            /* 0dB gain */
88                                           LVEQNB_Gain_1_dB,
89                                           LVEQNB_Gain_2_dB,
90                                           LVEQNB_Gain_3_dB,
91                                           LVEQNB_Gain_4_dB,
92                                           LVEQNB_Gain_5_dB,
93                                           LVEQNB_Gain_6_dB,
94                                           LVEQNB_Gain_7_dB,
95                                           LVEQNB_Gain_8_dB,
96                                           LVEQNB_Gain_9_dB,
97                                           LVEQNB_Gain_10_dB,
98                                           LVEQNB_Gain_11_dB,
99                                           LVEQNB_Gain_12_dB,
100                                           LVEQNB_Gain_13_dB,
101                                           LVEQNB_Gain_14_dB,
102                                           LVEQNB_Gain_15_dB};          /* +15dB gain */
103 
104 
105 /*
106  * D table for 100 / (Gain + 1)
107  */
108 const LVM_INT16    LVEQNB_DTable[] = {LVEQNB_100D_Neg15_dB,            /* -15dB gain */
109                                       LVEQNB_100D_Neg14_dB,
110                                       LVEQNB_100D_Neg13_dB,
111                                       LVEQNB_100D_Neg12_dB,
112                                       LVEQNB_100D_Neg11_dB,
113                                       LVEQNB_100D_Neg10_dB,
114                                       LVEQNB_100D_Neg9_dB,
115                                       LVEQNB_100D_Neg8_dB,
116                                       LVEQNB_100D_Neg7_dB,
117                                       LVEQNB_100D_Neg6_dB,
118                                       LVEQNB_100D_Neg5_dB,
119                                       LVEQNB_100D_Neg4_dB,
120                                       LVEQNB_100D_Neg3_dB,
121                                       LVEQNB_100D_Neg2_dB,
122                                       LVEQNB_100D_Neg1_dB,
123                                       LVEQNB_100D_0_dB};               /* 0dB gain */
124 
125 
126 /************************************************************************************/
127 /*                                                                                  */
128 /*    Filter polynomial coefficients                                                */
129 /*                                                                                  */
130 /************************************************************************************/
131 
132 /*
133  * Coefficients for calculating the cosine with the equation:
134  *
135  *  Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5)
136  *
137  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
138  * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range
139  * +1.0 to -1.0
140  */
141 const LVM_INT16     LVEQNB_CosCoef[] = {3,                             /* Shifts */
142                                         4096,                          /* a0 */
143                                         -36,                           /* a1 */
144                                         -19725,                        /* a2 */
145                                         -2671,                         /* a3 */
146                                         23730,                         /* a4 */
147                                         -9490};                        /* a5 */
148 
149 /*
150  * Coefficients for calculating the cosine error with the equation:
151  *
152  *  CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3)
153  *
154  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
155  * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range
156  * 0.0 to 0.0078852986
157  *
158  * This is used to give a double precision cosine over the range 0 to Pi/25 using the
159  * the equation:
160  *
161  * Cos(x) = 1.0 - CosErr(x)
162  */
163 const LVM_INT16     LVEQNB_DPCosCoef[] = {1,                           /* Shifts */
164                                           0,                           /* a0 */
165                                           -6,                          /* a1 */
166                                           16586,                       /* a2 */
167                                           -44};                        /* a3 */
168 
169 /************************************************************************************/
170 /*                                                                                  */
171 /*  Bypass mixer time constants (100ms)                                             */
172 /*                                                                                  */
173 /************************************************************************************/
174 
175 #define LVEQNB_MIX_TC_Fs8000    32580         /* Floating point value 0.994262695 */
176 #define LVEQNB_MIX_TC_Fs11025   32632         /* Floating point value 0.995849609 */
177 #define LVEQNB_MIX_TC_Fs12000   32643         /* Floating point value 0.996185303 */
178 #define LVEQNB_MIX_TC_Fs16000   32674         /* Floating point value 0.997131348 */
179 #define LVEQNB_MIX_TC_Fs22050   32700         /* Floating point value 0.997924805 */
180 #define LVEQNB_MIX_TC_Fs24000   32705         /* Floating point value 0.998077393 */
181 #define LVEQNB_MIX_TC_Fs32000   32721         /* Floating point value 0.998565674 */
182 #define LVEQNB_MIX_TC_Fs44100   32734         /* Floating point value 0.998962402 */
183 #define LVEQNB_MIX_TC_Fs48000   32737         /* Floating point value 0.999053955 */
184 
185 
186 const LVM_INT16 LVEQNB_MixerTCTable[] = {
187     LVEQNB_MIX_TC_Fs8000,
188     LVEQNB_MIX_TC_Fs11025,
189     LVEQNB_MIX_TC_Fs12000,
190     LVEQNB_MIX_TC_Fs16000,
191     LVEQNB_MIX_TC_Fs22050,
192     LVEQNB_MIX_TC_Fs24000,
193     LVEQNB_MIX_TC_Fs32000,
194     LVEQNB_MIX_TC_Fs44100,
195     LVEQNB_MIX_TC_Fs48000};
196