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 "LVPSA.h" 26 #include "LVPSA_QPD.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 #ifndef HIGHER_FS 38 const LVM_UINT16 LVPSA_SampleRateTab[] = { 8000, /* 8kS/s */ 39 11025, 40 12000, 41 16000, 42 22050, 43 24000, 44 32000, 45 44100, 46 48000}; /* 48kS/s */ 47 #else 48 const LVM_UINT32 LVPSA_SampleRateTab[] = { 8000, /* 8kS/s */ 49 11025, 50 12000, 51 16000, 52 22050, 53 24000, 54 32000, 55 44100, 56 48000, 57 88200, 58 96000, 59 176400, 60 192000}; /* 192kS/s */ 61 #endif 62 63 /************************************************************************************/ 64 /* */ 65 /* Sample rate inverse table */ 66 /* */ 67 /************************************************************************************/ 68 69 /* 70 * Sample rate table for converting between the enumerated type and the actual 71 * frequency 72 */ 73 const LVM_UINT32 LVPSA_SampleRateInvTab[] = { 268435, /* 8kS/s */ 74 194783, 75 178957, 76 134218, 77 97391, 78 89478, 79 67109, 80 48696, 81 44739 82 #ifdef HIGHER_FS 83 ,24348 84 ,22369 85 ,12174 86 ,11185 /* 192kS/s */ 87 #endif 88 }; 89 90 91 92 /************************************************************************************/ 93 /* */ 94 /* Number of samples in 20ms */ 95 /* */ 96 /************************************************************************************/ 97 98 /* 99 * Table for converting between the enumerated type and the number of samples 100 * during 20ms 101 */ 102 const LVM_UINT16 LVPSA_nSamplesBufferUpdate[] = { 160, /* 8kS/s */ 103 220, 104 240, 105 320, 106 441, 107 480, 108 640, 109 882, 110 960 111 #ifdef HIGHER_FS 112 ,1764 113 ,1920 114 ,3528 115 ,3840 /* 192kS/s */ 116 #endif 117 }; 118 /************************************************************************************/ 119 /* */ 120 /* Down sampling factors */ 121 /* */ 122 /************************************************************************************/ 123 124 /* 125 * Table for converting between the enumerated type and the down sampling factor 126 */ 127 const LVM_UINT16 LVPSA_DownSamplingFactor[] = { 5, /* 8000 S/s */ 128 7, /* 11025 S/s */ 129 8, /* 12000 S/s */ 130 10, /* 16000 S/s */ 131 15, /* 22050 S/s */ 132 16, /* 24000 S/s */ 133 21, /* 32000 S/s */ 134 30, /* 44100 S/s */ 135 32 /* 48000 S/s */ 136 #ifdef HIGHER_FS 137 ,60 /* 88200 S/s */ 138 ,64 /* 96000 S/s */ 139 ,120 /* 176400 S/s */ 140 ,128 /*192000 S/s */ 141 #endif 142 }; 143 144 145 /************************************************************************************/ 146 /* */ 147 /* Coefficient calculation tables */ 148 /* */ 149 /************************************************************************************/ 150 151 /* 152 * Table for 2 * Pi / Fs 153 */ 154 const LVM_INT16 LVPSA_TwoPiOnFsTable[] = { 26354, /* 8kS/s */ 155 19123, 156 17569, 157 13177, 158 9561, 159 8785, 160 6588, 161 4781, 162 4392 163 #ifdef HIGHER_FS 164 ,2390 165 ,2196 166 ,1195 167 ,1098 /* 192kS/s */ 168 #endif 169 }; 170 171 #ifdef BUILD_FLOAT 172 const LVM_FLOAT LVPSA_Float_TwoPiOnFsTable[] = { 0.8042847f, /* 8kS/s */ 173 0.5836054f, 174 0.5361796f, 175 0.4021423f, 176 0.2917874f, 177 0.2681051f, 178 0.2010559f, 179 0.1459089f, 180 0.1340372f 181 #ifdef HIGHER_FS 182 ,0.0729476f 183 ,0.0670186f 184 ,0.0364738f 185 ,0.0335093f /* 192kS/s */ 186 #endif 187 }; 188 189 #endif 190 /* 191 * Gain table 192 */ 193 const LVM_INT16 LVPSA_GainTable[] = { 364, /* -15dB gain */ 194 408, 195 458, 196 514, 197 577, 198 647, 199 726, 200 815, 201 914, 202 1026, 203 1151, 204 1292, 205 1449, 206 1626, 207 1825, 208 2048, /* 0dB gain */ 209 2297, 210 2578, 211 2892, 212 3245, 213 3641, 214 4096, 215 4584, 216 5144, 217 5772, 218 6476, 219 7266, 220 8153, 221 9148, 222 10264, 223 11576}; /* +15dB gain */ 224 225 #ifdef BUILD_FLOAT 226 const LVM_FLOAT LVPSA_Float_GainTable[]={ 0.177734375f, /* -15dB gain */ 227 0.199218750f, 228 0.223632812f, 229 0.250976562f, 230 0.281738281f, 231 0.315917968f, 232 0.354492187f, 233 0.397949218f, 234 0.446289062f, 235 0.500976562f, 236 0.562011718f, 237 0.630859375f, 238 0.707519531f, 239 0.793945312f, 240 0.891113281f, 241 1.000000000f, /* 0dB gain */ 242 1.121582031f, 243 1.258789062f, 244 1.412109375f, 245 1.584472656f, 246 1.777832031f, 247 2.000000000f, 248 2.238281250f, 249 2.511718750f, 250 2.818359375f, 251 3.162109375f, 252 3.547851562f, 253 3.980957031f, 254 4.466796875f, 255 5.011718750f, 256 5.652343750f}; /* +15dB gain */ 257 #endif 258 /************************************************************************************/ 259 /* */ 260 /* Cosone polynomial coefficients */ 261 /* */ 262 /************************************************************************************/ 263 264 /* 265 * Coefficients for calculating the cosine with the equation: 266 * 267 * Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5) 268 * 269 * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting 270 * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range 271 * +1.0 to -1.0 272 */ 273 const LVM_INT16 LVPSA_CosCoef[] = { 3, /* Shifts */ 274 4096, /* a0 */ 275 -36, /* a1 */ 276 -19725, /* a2 */ 277 -2671, /* a3 */ 278 23730, /* a4 */ 279 -9490}; /* a5 */ 280 #ifdef BUILD_FLOAT 281 const LVM_FLOAT LVPSA_Float_CosCoef[] = { 3, /* Shifts */ 282 0.1250038f, /* a0 */ 283 -0.0010986f, /* a1 */ 284 -0.6019775f, /* a2 */ 285 -0.0815149f, /* a3 */ 286 0.7242042f, /* a4 */ 287 -0.2896206f}; /* a5 */ 288 #endif 289 /* 290 * Coefficients for calculating the cosine error with the equation: 291 * 292 * CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3) 293 * 294 * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting 295 * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range 296 * 0.0 to 0.0078852986 297 * 298 * This is used to give a double precision cosine over the range 0 to Pi/25 using the 299 * the equation: 300 * 301 * Cos(x) = 1.0 - CosErr(x) 302 */ 303 const LVM_INT16 LVPSA_DPCosCoef[] = { 1, /* Shifts */ 304 0, /* a0 */ 305 -6, /* a1 */ 306 16586, /* a2 */ 307 -44}; /* a3 */ 308 #ifdef BUILD_FLOAT 309 const LVM_FLOAT LVPSA_Float_DPCosCoef[] = {1.0f, /* Shifts */ 310 0.0f, /* a0 */ 311 -0.00008311f, /* a1 */ 312 0.50617999f, /* a2 */ 313 -0.00134281f}; /* a3 */ 314 #endif 315 /************************************************************************************/ 316 /* */ 317 /* Quasi peak filter coefficients table */ 318 /* */ 319 /************************************************************************************/ 320 const QPD_C32_Coefs LVPSA_QPD_Coefs[] = { 321 322 {0x80CEFD2B,0x00CB9B17}, /* 8kS/s */ /* LVPSA_SPEED_LOW */ 323 {0x80D242E7,0x00CED11D}, 324 {0x80DCBAF5,0x00D91679}, 325 {0x80CEFD2B,0x00CB9B17}, 326 {0x80E13739,0x00DD7CD3}, 327 {0x80DCBAF5,0x00D91679}, 328 {0x80D94BAF,0x00D5B7E7}, 329 {0x80E13739,0x00DD7CD3}, 330 {0x80DCBAF5,0x00D91679}, /* 48kS/s */ 331 332 {0x8587513D,0x055C22CF}, /* 8kS/s */ /* LVPSA_SPEED_MEDIUM */ 333 {0x859D2967,0x0570F007}, 334 {0x85E2EFAC,0x05B34D79}, 335 {0x8587513D,0x055C22CF}, 336 {0x8600C7B9,0x05CFA6CF}, 337 {0x85E2EFAC,0x05B34D79}, 338 {0x85CC1018,0x059D8F69}, 339 {0x8600C7B9,0x05CFA6CF},//{0x8600C7B9,0x05CFA6CF}, 340 {0x85E2EFAC,0x05B34D79}, /* 48kS/s */ 341 342 {0xA115EA7A,0x1CDB3F5C}, /* 8kS/s */ /* LVPSA_SPEED_HIGH */ 343 {0xA18475F0,0x1D2C83A2}, 344 {0xA2E1E950,0x1E2A532E}, 345 {0xA115EA7A,0x1CDB3F5C}, 346 {0xA375B2C6,0x1E943BBC}, 347 {0xA2E1E950,0x1E2A532E}, 348 {0xA26FF6BD,0x1DD81530}, 349 {0xA375B2C6,0x1E943BBC}, 350 {0xA2E1E950,0x1E2A532E}}; /* 48kS/s */ 351 352 #ifdef BUILD_FLOAT 353 const QPD_FLOAT_Coefs LVPSA_QPD_Float_Coefs[] = { 354 355 /* 8kS/s */ /* LVPSA_SPEED_LOW */ 356 {-0.9936831989325583f,0.0062135565094650f}, 357 {-0.9935833332128823f,0.0063115493394434f}, 358 {-0.9932638457976282f,0.0066249934025109f}, 359 {-0.9936831989325583f,0.0062135565094650f}, 360 {-0.9931269618682563f,0.0067592649720609f}, 361 {-0.9932638457976282f,0.0066249934025109f}, 362 {-0.9933686633594334f,0.0065221670083702f}, 363 {-0.9931269618682563f,0.0067592649720609f}, 364 /* 48kS/s */ 365 {-0.9932638457976282f,0.0066249934025109f}, 366 #ifdef HIGHER_FS 367 {-0.9931269618682563f,0.0067592649720609f}, 368 {-0.9932638457976282f,0.0066249934025109f}, 369 {-0.9931269618682563f,0.0067592649720609f}, 370 {-0.9932638457976282f,0.0066249934025109f}, 371 #endif 372 /* 8kS/s */ /* LVPSA_SPEED_MEDIUM */ 373 {-0.9568079425953329f,0.0418742666952312f}, 374 {-0.9561413046903908f,0.0425090822391212f}, 375 {-0.9540119562298059f,0.0445343819446862f}, 376 {-0.9568079425953329f,0.0418742666952312f}, 377 {-0.9531011912040412f,0.0453995238058269f}, 378 {-0.9540119562298059f,0.0445343819446862f}, 379 {-0.9547099955379963f,0.0438708555884659f}, 380 //{0x8600C7B9,0x05CFA6CF}, 381 {-0.9531011912040412f,0.0453995238058269f}, 382 /* 48kS/s */ 383 {-0.9540119562298059f,0.0445343819446862f}, 384 #ifdef HIGHER_FS 385 {-0.9531011912040412f,0.0453995238058269f}, 386 {-0.9540119562298059f,0.0445343819446862f}, 387 {-0.9531011912040412f,0.0453995238058269f}, 388 {-0.9540119562298059f,0.0445343819446862f}, 389 #endif 390 /* 8kS/s */ /* LVPSA_SPEED_HIGH */ 391 {-0.7415186790749431f,0.2254409026354551f}, 392 {-0.7381451204419136f,0.2279209652915597f}, 393 {-0.7274807319045067f,0.2356666540727019f}, 394 {-0.7415186790749431f,0.2254409026354551f}, 395 {-0.7229706319049001f,0.2388987224549055f}, 396 {-0.7274807319045067f,0.2356666540727019f}, 397 {-0.7309581353329122f,0.2331568226218224f}, 398 {-0.7229706319049001f,0.2388987224549055f}, 399 /* 48kS/s */ 400 {-0.7274807319045067f,0.2356666540727019f} 401 #ifdef HIGHER_FS 402 ,{-0.7229706319049001f,0.2388987224549055f} 403 ,{-0.7274807319045067f,0.2356666540727019f} 404 ,{-0.7229706319049001f,0.2388987224549055f} 405 ,{-0.7274807319045067f,0.2356666540727019f} 406 #endif 407 }; 408 #endif 409