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 */ 37const LVM_UINT16 LVPSA_SampleRateTab[] = { 8000, /* 8kS/s */ 38 11025, 39 12000, 40 16000, 41 22050, 42 24000, 43 32000, 44 44100, 45 48000}; /* 48kS/s */ 46 47/************************************************************************************/ 48/* */ 49/* Sample rate inverse table */ 50/* */ 51/************************************************************************************/ 52 53/* 54 * Sample rate table for converting between the enumerated type and the actual 55 * frequency 56 */ 57const LVM_UINT32 LVPSA_SampleRateInvTab[] = { 268435, /* 8kS/s */ 58 194783, 59 178957, 60 134218, 61 97391, 62 89478, 63 67109, 64 48696, 65 44739}; /* 48kS/s */ 66 67 68 69/************************************************************************************/ 70/* */ 71/* Number of samples in 20ms */ 72/* */ 73/************************************************************************************/ 74 75/* 76 * Table for converting between the enumerated type and the number of samples 77 * during 20ms 78 */ 79const LVM_UINT16 LVPSA_nSamplesBufferUpdate[] = { 160, /* 8kS/s */ 80 220, 81 240, 82 320, 83 441, 84 480, 85 640, 86 882, 87 960}; /* 48kS/s */ 88/************************************************************************************/ 89/* */ 90/* Down sampling factors */ 91/* */ 92/************************************************************************************/ 93 94/* 95 * Table for converting between the enumerated type and the down sampling factor 96 */ 97const LVM_UINT16 LVPSA_DownSamplingFactor[] = { 5, /* 8000 S/s */ 98 7, /* 11025 S/s */ 99 8, /* 12000 S/s */ 100 10, /* 16000 S/s */ 101 15, /* 22050 S/s */ 102 16, /* 24000 S/s */ 103 21, /* 32000 S/s */ 104 30, /* 44100 S/s */ 105 32}; /* 48000 S/s */ 106 107 108/************************************************************************************/ 109/* */ 110/* Coefficient calculation tables */ 111/* */ 112/************************************************************************************/ 113 114/* 115 * Table for 2 * Pi / Fs 116 */ 117const LVM_INT16 LVPSA_TwoPiOnFsTable[] = { 26354, /* 8kS/s */ 118 19123, 119 17569, 120 13177, 121 9561, 122 8785, 123 6588, 124 4781, 125 4392}; /* 48kS/s */ 126 127/* 128 * Gain table 129 */ 130const LVM_INT16 LVPSA_GainTable[] = { 364, /* -15dB gain */ 131 408, 132 458, 133 514, 134 577, 135 647, 136 726, 137 815, 138 914, 139 1026, 140 1151, 141 1292, 142 1449, 143 1626, 144 1825, 145 2048, /* 0dB gain */ 146 2297, 147 2578, 148 2892, 149 3245, 150 3641, 151 4096, 152 4584, 153 5144, 154 5772, 155 6476, 156 7266, 157 8153, 158 9148, 159 10264, 160 11576}; /* +15dB gain */ 161 162/************************************************************************************/ 163/* */ 164/* Cosone polynomial coefficients */ 165/* */ 166/************************************************************************************/ 167 168/* 169 * Coefficients for calculating the cosine with the equation: 170 * 171 * Cos(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + a5*x^5) 172 * 173 * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting 174 * a range of 0 to Pi. The output is in the range 32767 to -32768 representing the range 175 * +1.0 to -1.0 176 */ 177const LVM_INT16 LVPSA_CosCoef[] = { 3, /* Shifts */ 178 4096, /* a0 */ 179 -36, /* a1 */ 180 -19725, /* a2 */ 181 -2671, /* a3 */ 182 23730, /* a4 */ 183 -9490}; /* a5 */ 184 185/* 186 * Coefficients for calculating the cosine error with the equation: 187 * 188 * CosErr(x) = (2^Shifts)*(a0 + a1*x + a2*x^2 + a3*x^3) 189 * 190 * These coefficients expect the input, x, to be in the range 0 to 32768 respresenting 191 * a range of 0 to Pi/25. The output is in the range 0 to 32767 representing the range 192 * 0.0 to 0.0078852986 193 * 194 * This is used to give a double precision cosine over the range 0 to Pi/25 using the 195 * the equation: 196 * 197 * Cos(x) = 1.0 - CosErr(x) 198 */ 199const LVM_INT16 LVPSA_DPCosCoef[] = { 1, /* Shifts */ 200 0, /* a0 */ 201 -6, /* a1 */ 202 16586, /* a2 */ 203 -44}; /* a3 */ 204 205/************************************************************************************/ 206/* */ 207/* Quasi peak filter coefficients table */ 208/* */ 209/************************************************************************************/ 210const QPD_C32_Coefs LVPSA_QPD_Coefs[] = { 211 212 {0x80CEFD2B,0x00CB9B17}, /* 8kS/s */ /* LVPSA_SPEED_LOW */ 213 {0x80D242E7,0x00CED11D}, 214 {0x80DCBAF5,0x00D91679}, 215 {0x80CEFD2B,0x00CB9B17}, 216 {0x80E13739,0x00DD7CD3}, 217 {0x80DCBAF5,0x00D91679}, 218 {0x80D94BAF,0x00D5B7E7}, 219 {0x80E13739,0x00DD7CD3}, 220 {0x80DCBAF5,0x00D91679}, /* 48kS/s */ 221 222 {0x8587513D,0x055C22CF}, /* 8kS/s */ /* LVPSA_SPEED_MEDIUM */ 223 {0x859D2967,0x0570F007}, 224 {0x85E2EFAC,0x05B34D79}, 225 {0x8587513D,0x055C22CF}, 226 {0x8600C7B9,0x05CFA6CF}, 227 {0x85E2EFAC,0x05B34D79}, 228 {0x85CC1018,0x059D8F69}, 229 {0x8600C7B9,0x05CFA6CF},//{0x8600C7B9,0x05CFA6CF}, 230 {0x85E2EFAC,0x05B34D79}, /* 48kS/s */ 231 232 {0xA115EA7A,0x1CDB3F5C}, /* 8kS/s */ /* LVPSA_SPEED_HIGH */ 233 {0xA18475F0,0x1D2C83A2}, 234 {0xA2E1E950,0x1E2A532E}, 235 {0xA115EA7A,0x1CDB3F5C}, 236 {0xA375B2C6,0x1E943BBC}, 237 {0xA2E1E950,0x1E2A532E}, 238 {0xA26FF6BD,0x1DD81530}, 239 {0xA375B2C6,0x1E943BBC}, 240 {0xA2E1E950,0x1E2A532E}}; /* 48kS/s */ 241 242