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 /*    Includes                                                                      */
21 /*                                                                                  */
22 /************************************************************************************/
23 
24 #include "LVEQNB.h"
25 #include "LVEQNB_Coeffs.h"
26 #include "LVEQNB_Tables.h"
27 
28 /************************************************************************************/
29 /*                                                                                  */
30 /*    Sample rate table                                                             */
31 /*                                                                                  */
32 /************************************************************************************/
33 
34 /*
35  * Sample rate table for converting between the enumerated type and the actual
36  * frequency
37  */
38 const LVM_UINT32    LVEQNB_SampleRateTab[] = {8000,                    /* 8kS/s  */
39                                               11025,
40                                               12000,
41                                               16000,
42                                               22050,
43                                               24000,
44                                               32000,
45                                               44100,
46                                               48000,
47                                               88200,
48                                               96000,
49                                               176400,
50                                               192000
51 };
52 
53 /************************************************************************************/
54 /*                                                                                  */
55 /*    Coefficient calculation tables                                                */
56 /*                                                                                  */
57 /************************************************************************************/
58 
59 /*
60  * Table for 2 * Pi / Fs
61  */
62 const LVM_FLOAT     LVEQNB_TwoPiOnFsTable[] = {LVEQNB_2PiOn_8000,      /* 8kS/s */
63                                                LVEQNB_2PiOn_11025,
64                                                LVEQNB_2PiOn_12000,
65                                                LVEQNB_2PiOn_16000,
66                                                LVEQNB_2PiOn_22050,
67                                                LVEQNB_2PiOn_24000,
68                                                LVEQNB_2PiOn_32000,
69                                                LVEQNB_2PiOn_44100,
70                                                LVEQNB_2PiOn_48000
71                                               ,LVEQNB_2PiOn_88200
72                                               ,LVEQNB_2PiOn_96000
73                                               ,LVEQNB_2PiOn_176400
74                                               ,LVEQNB_2PiOn_192000
75                                                };
76 
77 /*
78  * Gain table
79  */
80 const LVM_FLOAT     LVEQNB_GainTable[] = {LVEQNB_Gain_Neg15_dB,        /* -15dB gain */
81                                           LVEQNB_Gain_Neg14_dB,
82                                           LVEQNB_Gain_Neg13_dB,
83                                           LVEQNB_Gain_Neg12_dB,
84                                           LVEQNB_Gain_Neg11_dB,
85                                           LVEQNB_Gain_Neg10_dB,
86                                           LVEQNB_Gain_Neg9_dB,
87                                           LVEQNB_Gain_Neg8_dB,
88                                           LVEQNB_Gain_Neg7_dB,
89                                           LVEQNB_Gain_Neg6_dB,
90                                           LVEQNB_Gain_Neg5_dB,
91                                           LVEQNB_Gain_Neg4_dB,
92                                           LVEQNB_Gain_Neg3_dB,
93                                           LVEQNB_Gain_Neg2_dB,
94                                           LVEQNB_Gain_Neg1_dB,
95                                           LVEQNB_Gain_0_dB,            /* 0dB gain */
96                                           LVEQNB_Gain_1_dB,
97                                           LVEQNB_Gain_2_dB,
98                                           LVEQNB_Gain_3_dB,
99                                           LVEQNB_Gain_4_dB,
100                                           LVEQNB_Gain_5_dB,
101                                           LVEQNB_Gain_6_dB,
102                                           LVEQNB_Gain_7_dB,
103                                           LVEQNB_Gain_8_dB,
104                                           LVEQNB_Gain_9_dB,
105                                           LVEQNB_Gain_10_dB,
106                                           LVEQNB_Gain_11_dB,
107                                           LVEQNB_Gain_12_dB,
108                                           LVEQNB_Gain_13_dB,
109                                           LVEQNB_Gain_14_dB,
110                                           LVEQNB_Gain_15_dB};          /* +15dB gain */
111 /*
112  * D table for 100 / (Gain + 1)
113  */
114 const LVM_FLOAT    LVEQNB_DTable[] = {LVEQNB_100D_Neg15_dB,            /* -15dB gain */
115                                       LVEQNB_100D_Neg14_dB,
116                                       LVEQNB_100D_Neg13_dB,
117                                       LVEQNB_100D_Neg12_dB,
118                                       LVEQNB_100D_Neg11_dB,
119                                       LVEQNB_100D_Neg10_dB,
120                                       LVEQNB_100D_Neg9_dB,
121                                       LVEQNB_100D_Neg8_dB,
122                                       LVEQNB_100D_Neg7_dB,
123                                       LVEQNB_100D_Neg6_dB,
124                                       LVEQNB_100D_Neg5_dB,
125                                       LVEQNB_100D_Neg4_dB,
126                                       LVEQNB_100D_Neg3_dB,
127                                       LVEQNB_100D_Neg2_dB,
128                                       LVEQNB_100D_Neg1_dB,
129                                       LVEQNB_100D_0_dB};               /* 0dB gain */
130 /************************************************************************************/
131 /*                                                                                  */
132 /*    Filter polynomial coefficients                                                */
133 /*                                                                                  */
134 /************************************************************************************/
135 
136 /*
137  * Coefficients for calculating the cosine with the equation:
138  *
139  *  Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5)
140  *
141  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
142  * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range
143  * +1.0 to -1.0
144  */
145 const LVM_INT16     LVEQNB_CosCoef[] = {3,                             /* Shifts */
146                                         4096,                          /* a0 */
147                                         -36,                           /* a1 */
148                                         -19725,                        /* a2 */
149                                         -2671,                         /* a3 */
150                                         23730,                         /* a4 */
151                                         -9490};                        /* a5 */
152 
153 /*
154  * Coefficients for calculating the cosine error with the equation:
155  *
156  *  CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3)
157  *
158  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
159  * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range
160  * 0.0 to 0.0078852986
161  *
162  * This is used to give a double precision cosine over the range 0 to Pi/25 using the
163  * the equation:
164  *
165  * Cos(x) = 1.0 - CosErr(x)
166  */
167 const LVM_INT16     LVEQNB_DPCosCoef[] = {1,                           /* Shifts */
168                                           0,                           /* a0 */
169                                           -6,                          /* a1 */
170                                           16586,                       /* a2 */
171                                           -44};                        /* a3 */
172 
173