• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "LVPSA.h"
25 #include "LVPSA_QPD.h"
26 #include "LVPSA_Tables.h"
27 /************************************************************************************/
28 /*                                                                                  */
29 /*  Sample rate table                                                               */
30 /*                                                                                  */
31 /************************************************************************************/
32 
33 /*
34  * Sample rate table for converting between the enumerated type and the actual
35  * frequency
36  */
37 const LVM_UINT32 LVPSA_SampleRateTab[] = {8000, /* 8kS/s  */
38                                           11025, 12000, 16000, 22050, 24000,  32000,
39                                           44100, 48000, 88200, 96000, 176400, 192000}; /* 192kS/s */
40 
41 /************************************************************************************/
42 /*                                                                                  */
43 /*  Sample rate inverse table                                                       */
44 /*                                                                                  */
45 /************************************************************************************/
46 
47 /*
48  * Sample rate table for converting between the enumerated type and the actual
49  * frequency
50  */
51 const LVM_UINT32 LVPSA_SampleRateInvTab[] = {
52         268435, /* 8kS/s  */
53         194783, 178957, 134218, 97391, 89478, 67109,
54         48696,  44739,  24348,  22369, 12174, 11185 /* 192kS/s */
55 };
56 
57 /************************************************************************************/
58 /*                                                                                  */
59 /*  Number of samples in 20ms                                                       */
60 /*                                                                                  */
61 /************************************************************************************/
62 
63 /*
64  * Table for converting between the enumerated type and the number of samples
65  * during 20ms
66  */
67 const LVM_UINT16 LVPSA_nSamplesBufferUpdate[] = {
68         160,                                                           /* 8kS/s  */
69         220, 240, 320, 441, 480, 640, 882, 960, 1764, 1920, 3528, 3840 /* 192kS/s */
70 };
71 /************************************************************************************/
72 /*                                                                                  */
73 /*  Down sampling factors                                                           */
74 /*                                                                                  */
75 /************************************************************************************/
76 
77 /*
78  * Table for converting between the enumerated type and the down sampling factor
79  */
80 const LVM_UINT16 LVPSA_DownSamplingFactor[] = {
81         5,  /* 8000  S/s  */
82         7,  /* 11025 S/s  */
83         8,  /* 12000 S/s  */
84         10, /* 16000 S/s  */
85         15, /* 22050 S/s  */
86         16, /* 24000 S/s  */
87         21, /* 32000 S/s  */
88         30, /* 44100 S/s  */
89         32  /* 48000 S/s  */
90         ,
91         60 /* 88200 S/s  */
92         ,
93         64 /* 96000 S/s  */
94         ,
95         120 /* 176400 S/s  */
96         ,
97         128 /*192000 S/s  */
98 };
99 
100 /************************************************************************************/
101 /*                                                                                  */
102 /*  Coefficient calculation tables                                                  */
103 /*                                                                                  */
104 /************************************************************************************/
105 
106 /*
107  * Table for 2 * Pi / Fs
108  */
109 const LVM_INT16 LVPSA_TwoPiOnFsTable[] = {
110         26354,                                                                    /* 8kS/s */
111         19123, 17569, 13177, 9561, 8785, 6588, 4781, 4392, 2390, 2196, 1195, 1098 /* 192kS/s */
112 };
113 
114 const LVM_FLOAT LVPSA_Float_TwoPiOnFsTable[] = {
115         0.8042847f, /* 8kS/s */
116         0.5836054f, 0.5361796f, 0.4021423f, 0.2917874f, 0.2681051f, 0.2010559f,
117         0.1459089f, 0.1340372f, 0.0729476f, 0.0670186f, 0.0364738f, 0.0335093f /* 192kS/s */
118 };
119 
120 /*
121  * Gain table
122  */
123 const LVM_INT16 LVPSA_GainTable[] = {364, /* -15dB gain */
124                                      408,  458,  514,  577,  647,  726,   815,  914,
125                                      1026, 1151, 1292, 1449, 1626, 1825,  2048, /* 0dB gain */
126                                      2297, 2578, 2892, 3245, 3641, 4096,  4584, 5144,
127                                      5772, 6476, 7266, 8153, 9148, 10264, 11576}; /* +15dB gain */
128 
129 const LVM_FLOAT LVPSA_Float_GainTable[] = {
130         0.177734375f, /* -15dB gain */
131         0.199218750f, 0.223632812f, 0.250976562f, 0.281738281f, 0.315917968f,
132         0.354492187f, 0.397949218f, 0.446289062f, 0.500976562f, 0.562011718f,
133         0.630859375f, 0.707519531f, 0.793945312f, 0.891113281f, 1.000000000f, /* 0dB gain */
134         1.121582031f, 1.258789062f, 1.412109375f, 1.584472656f, 1.777832031f,
135         2.000000000f, 2.238281250f, 2.511718750f, 2.818359375f, 3.162109375f,
136         3.547851562f, 3.980957031f, 4.466796875f, 5.011718750f, 5.652343750f}; /* +15dB gain */
137 /************************************************************************************/
138 /*                                                                                  */
139 /*  Cosone polynomial coefficients                                                  */
140 /*                                                                                  */
141 /************************************************************************************/
142 
143 /*
144  * Coefficients for calculating the cosine with the equation:
145  *
146  *  Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5)
147  *
148  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
149  * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range
150  * +1.0 to -1.0
151  */
152 const LVM_INT16 LVPSA_CosCoef[] = {3,                  /* Shifts */
153                                    4096,               /* a0 */
154                                    -36,                /* a1 */
155                                    -19725,             /* a2 */
156                                    -2671,              /* a3 */
157                                    23730,              /* a4 */
158                                    -9490};             /* a5 */
159 const LVM_FLOAT LVPSA_Float_CosCoef[] = {3,            /* Shifts */
160                                          0.1250038f,   /* a0 */
161                                          -0.0010986f,  /* a1 */
162                                          -0.6019775f,  /* a2 */
163                                          -0.0815149f,  /* a3 */
164                                          0.7242042f,   /* a4 */
165                                          -0.2896206f}; /* a5 */
166 /*
167  * Coefficients for calculating the cosine error with the equation:
168  *
169  *  CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3)
170  *
171  * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting
172  * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range
173  * 0.0 to 0.0078852986
174  *
175  * This is used to give a double precision cosine over the range 0 to Pi/25 using the
176  * the equation:
177  *
178  * Cos(x) = 1.0 - CosErr(x)
179  */
180 const LVM_INT16 LVPSA_DPCosCoef[] = {1,                   /* Shifts */
181                                      0,                   /* a0 */
182                                      -6,                  /* a1 */
183                                      16586,               /* a2 */
184                                      -44};                /* a3 */
185 const LVM_FLOAT LVPSA_Float_DPCosCoef[] = {1.0f,          /* Shifts */
186                                            0.0f,          /* a0 */
187                                            -0.00008311f,  /* a1 */
188                                            0.50617999f,   /* a2 */
189                                            -0.00134281f}; /* a3 */
190 /************************************************************************************/
191 /*                                                                                  */
192 /*  Quasi peak filter coefficients table                                            */
193 /*                                                                                  */
194 /************************************************************************************/
195 const QPD_C32_Coefs LVPSA_QPD_Coefs[] = {
196         /* 8kS/s  */ /* LVPSA_SPEED_LOW   */
197         {(LVM_INT32)0x80CEFD2B, 0x00CB9B17},
198         {(LVM_INT32)0x80D242E7, 0x00CED11D},
199         {(LVM_INT32)0x80DCBAF5, 0x00D91679},
200         {(LVM_INT32)0x80CEFD2B, 0x00CB9B17},
201         {(LVM_INT32)0x80E13739, 0x00DD7CD3},
202         {(LVM_INT32)0x80DCBAF5, 0x00D91679},
203         {(LVM_INT32)0x80D94BAF, 0x00D5B7E7},
204         {(LVM_INT32)0x80E13739, 0x00DD7CD3},
205         {(LVM_INT32)0x80DCBAF5, 0x00D91679}, /* 48kS/s */
206 
207         /* 8kS/s  */ /* LVPSA_SPEED_MEDIUM */
208         {(LVM_INT32)0x8587513D, 0x055C22CF},
209         {(LVM_INT32)0x859D2967, 0x0570F007},
210         {(LVM_INT32)0x85E2EFAC, 0x05B34D79},
211         {(LVM_INT32)0x8587513D, 0x055C22CF},
212         {(LVM_INT32)0x8600C7B9, 0x05CFA6CF},
213         {(LVM_INT32)0x85E2EFAC, 0x05B34D79},
214         {(LVM_INT32)0x85CC1018, 0x059D8F69},
215         {(LVM_INT32)0x8600C7B9, 0x05CFA6CF},
216         {(LVM_INT32)0x85E2EFAC, 0x05B34D79}, /* 48kS/s */
217 
218         /* 8kS/s  */ /* LVPSA_SPEED_HIGH    */
219         {(LVM_INT32)0xA115EA7A, 0x1CDB3F5C},
220         {(LVM_INT32)0xA18475F0, 0x1D2C83A2},
221         {(LVM_INT32)0xA2E1E950, 0x1E2A532E},
222         {(LVM_INT32)0xA115EA7A, 0x1CDB3F5C},
223         {(LVM_INT32)0xA375B2C6, 0x1E943BBC},
224         {(LVM_INT32)0xA2E1E950, 0x1E2A532E},
225         {(LVM_INT32)0xA26FF6BD, 0x1DD81530},
226         {(LVM_INT32)0xA375B2C6, 0x1E943BBC},
227         {(LVM_INT32)0xA2E1E950, 0x1E2A532E}}; /* 48kS/s */
228 
229 const QPD_FLOAT_Coefs LVPSA_QPD_Float_Coefs[] = {
230 
231         /* 8kS/s  */ /* LVPSA_SPEED_LOW   */
232         {-0.9936831989325583f, 0.0062135565094650f},
233         {-0.9935833332128823f, 0.0063115493394434f},
234         {-0.9932638457976282f, 0.0066249934025109f},
235         {-0.9936831989325583f, 0.0062135565094650f},
236         {-0.9931269618682563f, 0.0067592649720609f},
237         {-0.9932638457976282f, 0.0066249934025109f},
238         {-0.9933686633594334f, 0.0065221670083702f},
239         {-0.9931269618682563f, 0.0067592649720609f},
240         /* 48kS/s */
241         {-0.9932638457976282f, 0.0066249934025109f},
242         {-0.9931269618682563f, 0.0067592649720609f},
243         {-0.9932638457976282f, 0.0066249934025109f},
244         {-0.9931269618682563f, 0.0067592649720609f},
245         {-0.9932638457976282f, 0.0066249934025109f},
246         /* 8kS/s  */ /* LVPSA_SPEED_MEDIUM      */
247         {-0.9568079425953329f, 0.0418742666952312f},
248         {-0.9561413046903908f, 0.0425090822391212f},
249         {-0.9540119562298059f, 0.0445343819446862f},
250         {-0.9568079425953329f, 0.0418742666952312f},
251         {-0.9531011912040412f, 0.0453995238058269f},
252         {-0.9540119562298059f, 0.0445343819446862f},
253         {-0.9547099955379963f, 0.0438708555884659f},
254         //{0x8600C7B9,0x05CFA6CF},
255         {-0.9531011912040412f, 0.0453995238058269f},
256         /* 48kS/s */
257         {-0.9540119562298059f, 0.0445343819446862f},
258         {-0.9531011912040412f, 0.0453995238058269f},
259         {-0.9540119562298059f, 0.0445343819446862f},
260         {-0.9531011912040412f, 0.0453995238058269f},
261         {-0.9540119562298059f, 0.0445343819446862f},
262         /* 8kS/s  */ /* LVPSA_SPEED_HIGH      */
263         {-0.7415186790749431f, 0.2254409026354551f},
264         {-0.7381451204419136f, 0.2279209652915597f},
265         {-0.7274807319045067f, 0.2356666540727019f},
266         {-0.7415186790749431f, 0.2254409026354551f},
267         {-0.7229706319049001f, 0.2388987224549055f},
268         {-0.7274807319045067f, 0.2356666540727019f},
269         {-0.7309581353329122f, 0.2331568226218224f},
270         {-0.7229706319049001f, 0.2388987224549055f},
271         /* 48kS/s */
272         {-0.7274807319045067f, 0.2356666540727019f},
273         {-0.7229706319049001f, 0.2388987224549055f},
274         {-0.7274807319045067f, 0.2356666540727019f},
275         {-0.7229706319049001f, 0.2388987224549055f},
276         {-0.7274807319045067f, 0.2356666540727019f}};
277