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