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 "LVCS_Private.h"
     26 #include "Filters.h"                            /* Filter definitions */
     27 #include "BIQUAD.h"                             /* Biquad definitions */
     28 #include "LVCS_Headphone_Coeffs.h"              /* Headphone coefficients */
     29 
     30 
     31 /************************************************************************************/
     32 /*                                                                                  */
     33 /*  Stereo Enhancer coefficient constant tables                                     */
     34 /*                                                                                  */
     35 /************************************************************************************/
     36 
     37 /* Coefficient table for the middle filter */
     38 const BiquadA01B1CoefsSP_t LVCS_SEMidCoefTable[] = {
     39     {CS_MIDDLE_8000_A0,         /* 8kS/s coefficients */
     40      CS_MIDDLE_8000_A1,
     41      CS_MIDDLE_8000_B1,
     42      (LVM_UINT16 )CS_MIDDLE_8000_SCALE},
     43     {CS_MIDDLE_11025_A0,        /* 11kS/s coefficients */
     44      CS_MIDDLE_11025_A1,
     45      CS_MIDDLE_11025_B1,
     46      (LVM_UINT16 )CS_MIDDLE_11025_SCALE},
     47     {CS_MIDDLE_12000_A0,        /* 12kS/s coefficients */
     48      CS_MIDDLE_12000_A1,
     49      CS_MIDDLE_12000_B1,
     50      (LVM_UINT16 )CS_MIDDLE_12000_SCALE},
     51     {CS_MIDDLE_16000_A0,        /* 16kS/s coefficients */
     52      CS_MIDDLE_16000_A1,
     53      CS_MIDDLE_16000_B1,
     54      (LVM_UINT16 )CS_MIDDLE_16000_SCALE},
     55     {CS_MIDDLE_22050_A0,        /* 22kS/s coefficients */
     56      CS_MIDDLE_22050_A1,
     57      CS_MIDDLE_22050_B1,
     58      (LVM_UINT16 )CS_MIDDLE_22050_SCALE},
     59     {CS_MIDDLE_24000_A0,        /* 24kS/s coefficients */
     60      CS_MIDDLE_24000_A1,
     61      CS_MIDDLE_24000_B1,
     62      (LVM_UINT16 )CS_MIDDLE_24000_SCALE},
     63     {CS_MIDDLE_32000_A0,        /* 32kS/s coefficients */
     64      CS_MIDDLE_32000_A1,
     65      CS_MIDDLE_32000_B1,
     66      (LVM_UINT16 )CS_MIDDLE_32000_SCALE},
     67     {CS_MIDDLE_44100_A0,        /* 44kS/s coefficients */
     68      CS_MIDDLE_44100_A1,
     69      CS_MIDDLE_44100_B1,
     70      (LVM_UINT16 )CS_MIDDLE_44100_SCALE},
     71     {CS_MIDDLE_48000_A0,        /* 48kS/s coefficients */
     72      CS_MIDDLE_48000_A1,
     73      CS_MIDDLE_48000_B1,
     74      (LVM_UINT16 )CS_MIDDLE_48000_SCALE}};
     75 
     76 /* Coefficient table for the side filter */
     77 const BiquadA012B12CoefsSP_t LVCS_SESideCoefTable[] = {
     78     /* Headphone Side coefficients */
     79     {CS_SIDE_8000_A0,           /* 8kS/s coefficients */
     80      CS_SIDE_8000_A1,
     81      CS_SIDE_8000_A2,
     82      CS_SIDE_8000_B1,
     83      CS_SIDE_8000_B2,
     84      (LVM_UINT16 )CS_SIDE_8000_SCALE},
     85     {CS_SIDE_11025_A0,          /* 11kS/s coefficients */
     86      CS_SIDE_11025_A1,
     87      CS_SIDE_11025_A2,
     88      CS_SIDE_11025_B1,
     89      CS_SIDE_11025_B2,
     90      (LVM_UINT16 )CS_SIDE_11025_SCALE},
     91     {CS_SIDE_12000_A0,          /* 12kS/s coefficients */
     92      CS_SIDE_12000_A1,
     93      CS_SIDE_12000_A2,
     94      CS_SIDE_12000_B1,
     95      CS_SIDE_12000_B2,
     96      (LVM_UINT16 )CS_SIDE_12000_SCALE},
     97     {CS_SIDE_16000_A0,          /* 16kS/s coefficients */
     98      CS_SIDE_16000_A1,
     99      CS_SIDE_16000_A2,
    100      CS_SIDE_16000_B1,
    101      CS_SIDE_16000_B2,
    102      (LVM_UINT16 )CS_SIDE_16000_SCALE},
    103     {CS_SIDE_22050_A0,          /* 22kS/s coefficients */
    104      CS_SIDE_22050_A1,
    105      CS_SIDE_22050_A2,
    106      CS_SIDE_22050_B1,
    107      CS_SIDE_22050_B2,
    108      (LVM_UINT16 )CS_SIDE_22050_SCALE},
    109     {CS_SIDE_24000_A0,          /* 24kS/s coefficients */
    110      CS_SIDE_24000_A1,
    111      CS_SIDE_24000_A2,
    112      CS_SIDE_24000_B1,
    113      CS_SIDE_24000_B2,
    114      (LVM_UINT16 )CS_SIDE_24000_SCALE},
    115     {CS_SIDE_32000_A0,          /* 32kS/s coefficients */
    116      CS_SIDE_32000_A1,
    117      CS_SIDE_32000_A2,
    118      CS_SIDE_32000_B1,
    119      CS_SIDE_32000_B2,
    120      (LVM_UINT16 )CS_SIDE_32000_SCALE},
    121     {CS_SIDE_44100_A0,          /* 44kS/s coefficients */
    122      CS_SIDE_44100_A1,
    123      CS_SIDE_44100_A2,
    124      CS_SIDE_44100_B1,
    125      CS_SIDE_44100_B2,
    126      (LVM_UINT16 )CS_SIDE_44100_SCALE},
    127     {CS_SIDE_48000_A0,          /* 48kS/s coefficients */
    128      CS_SIDE_48000_A1,
    129      CS_SIDE_48000_A2,
    130      CS_SIDE_48000_B1,
    131      CS_SIDE_48000_B2,
    132      (LVM_UINT16 )CS_SIDE_48000_SCALE}
    133 };
    134 
    135 
    136 /************************************************************************************/
    137 /*                                                                                  */
    138 /*  Equaliser coefficient constant tables                                           */
    139 /*                                                                                  */
    140 /************************************************************************************/
    141 
    142 const BiquadA012B12CoefsSP_t LVCS_EqualiserCoefTable[] = {
    143     /* Headphone coefficients */
    144     {CS_EQUALISER_8000_A0,      /* 8kS/s coefficients */
    145      CS_EQUALISER_8000_A1,
    146      CS_EQUALISER_8000_A2,
    147      CS_EQUALISER_8000_B1,
    148      CS_EQUALISER_8000_B2,
    149      (LVM_UINT16 )CS_EQUALISER_8000_SCALE},
    150     {CS_EQUALISER_11025_A0,     /* 11kS/s coefficients */
    151      CS_EQUALISER_11025_A1,
    152      CS_EQUALISER_11025_A2,
    153      CS_EQUALISER_11025_B1,
    154      CS_EQUALISER_11025_B2,
    155      (LVM_UINT16 )CS_EQUALISER_11025_SCALE},
    156     {CS_EQUALISER_12000_A0,     /* 12kS/s coefficients */
    157      CS_EQUALISER_12000_A1,
    158      CS_EQUALISER_12000_A2,
    159      CS_EQUALISER_12000_B1,
    160      CS_EQUALISER_12000_B2,
    161      (LVM_UINT16 )CS_EQUALISER_12000_SCALE},
    162     {CS_EQUALISER_16000_A0,     /* 16kS/s coefficients */
    163      CS_EQUALISER_16000_A1,
    164      CS_EQUALISER_16000_A2,
    165      CS_EQUALISER_16000_B1,
    166      CS_EQUALISER_16000_B2,
    167      (LVM_UINT16 )CS_EQUALISER_16000_SCALE},
    168     {CS_EQUALISER_22050_A0,     /* 22kS/s coefficients */
    169      CS_EQUALISER_22050_A1,
    170      CS_EQUALISER_22050_A2,
    171      CS_EQUALISER_22050_B1,
    172      CS_EQUALISER_22050_B2,
    173      (LVM_UINT16 )CS_EQUALISER_22050_SCALE},
    174     {CS_EQUALISER_24000_A0,     /* 24kS/s coefficients */
    175      CS_EQUALISER_24000_A1,
    176      CS_EQUALISER_24000_A2,
    177      CS_EQUALISER_24000_B1,
    178      CS_EQUALISER_24000_B2,
    179      (LVM_UINT16 )CS_EQUALISER_24000_SCALE},
    180     {CS_EQUALISER_32000_A0,     /* 32kS/s coefficients */
    181      CS_EQUALISER_32000_A1,
    182      CS_EQUALISER_32000_A2,
    183      CS_EQUALISER_32000_B1,
    184      CS_EQUALISER_32000_B2,
    185      (LVM_UINT16 )CS_EQUALISER_32000_SCALE},
    186     {CS_EQUALISER_44100_A0,     /* 44kS/s coefficients */
    187      CS_EQUALISER_44100_A1,
    188      CS_EQUALISER_44100_A2,
    189      CS_EQUALISER_44100_B1,
    190      CS_EQUALISER_44100_B2,
    191      (LVM_UINT16 )CS_EQUALISER_44100_SCALE},
    192     {CS_EQUALISER_48000_A0,     /* 48kS/s coefficients */
    193      CS_EQUALISER_48000_A1,
    194      CS_EQUALISER_48000_A2,
    195      CS_EQUALISER_48000_B1,
    196      CS_EQUALISER_48000_B2,
    197      (LVM_UINT16 )CS_EQUALISER_48000_SCALE},
    198 
    199     /* Concert Sound EX Headphone coefficients */
    200     {CSEX_EQUALISER_8000_A0,    /* 8kS/s coefficients */
    201      CSEX_EQUALISER_8000_A1,
    202      CSEX_EQUALISER_8000_A2,
    203      CSEX_EQUALISER_8000_B1,
    204      CSEX_EQUALISER_8000_B2,
    205      (LVM_UINT16 )CSEX_EQUALISER_8000_SCALE},
    206     {CSEX_EQUALISER_11025_A0,   /* 11kS/s coefficients */
    207      CSEX_EQUALISER_11025_A1,
    208      CSEX_EQUALISER_11025_A2,
    209      CSEX_EQUALISER_11025_B1,
    210      CSEX_EQUALISER_11025_B2,
    211      (LVM_UINT16 )CSEX_EQUALISER_11025_SCALE},
    212     {CSEX_EQUALISER_12000_A0,   /* 12kS/s coefficients */
    213      CSEX_EQUALISER_12000_A1,
    214      CSEX_EQUALISER_12000_A2,
    215      CSEX_EQUALISER_12000_B1,
    216      CSEX_EQUALISER_12000_B2,
    217      (LVM_UINT16 )CSEX_EQUALISER_12000_SCALE},
    218     {CSEX_EQUALISER_16000_A0,   /* 16kS/s coefficients */
    219      CSEX_EQUALISER_16000_A1,
    220      CSEX_EQUALISER_16000_A2,
    221      CSEX_EQUALISER_16000_B1,
    222      CSEX_EQUALISER_16000_B2,
    223      (LVM_UINT16 )CSEX_EQUALISER_16000_SCALE},
    224     {CSEX_EQUALISER_22050_A0,   /* 22kS/s coefficients */
    225      CSEX_EQUALISER_22050_A1,
    226      CSEX_EQUALISER_22050_A2,
    227      CSEX_EQUALISER_22050_B1,
    228      CSEX_EQUALISER_22050_B2,
    229      (LVM_UINT16 )CSEX_EQUALISER_22050_SCALE},
    230     {CSEX_EQUALISER_24000_A0,   /* 24kS/s coefficients */
    231      CSEX_EQUALISER_24000_A1,
    232      CSEX_EQUALISER_24000_A2,
    233      CSEX_EQUALISER_24000_B1,
    234      CSEX_EQUALISER_24000_B2,
    235      (LVM_UINT16 )CSEX_EQUALISER_24000_SCALE},
    236     {CSEX_EQUALISER_32000_A0,   /* 32kS/s coefficients */
    237      CSEX_EQUALISER_32000_A1,
    238      CSEX_EQUALISER_32000_A2,
    239      CSEX_EQUALISER_32000_B1,
    240      CSEX_EQUALISER_32000_B2,
    241      (LVM_UINT16 )CSEX_EQUALISER_32000_SCALE},
    242     {CSEX_EQUALISER_44100_A0,   /* 44kS/s coefficients */
    243      CSEX_EQUALISER_44100_A1,
    244      CSEX_EQUALISER_44100_A2,
    245      CSEX_EQUALISER_44100_B1,
    246      CSEX_EQUALISER_44100_B2,
    247      (LVM_UINT16 )CSEX_EQUALISER_44100_SCALE},
    248     {CSEX_EQUALISER_48000_A0,   /* 48kS/s coefficients */
    249      CSEX_EQUALISER_48000_A1,
    250      CSEX_EQUALISER_48000_A2,
    251      CSEX_EQUALISER_48000_B1,
    252      CSEX_EQUALISER_48000_B2,
    253      (LVM_UINT16 )CSEX_EQUALISER_48000_SCALE}
    254 };
    255 
    256 
    257 /************************************************************************************/
    258 /*                                                                                  */
    259 /*  Reverb delay constant tables                                                    */
    260 /*                                                                                  */
    261 /************************************************************************************/
    262 
    263 /* Stereo delay table for Concert Sound */
    264 const LVM_UINT16    LVCS_StereoDelayCS[] = {
    265     LVCS_STEREODELAY_CS_8KHZ,
    266     LVCS_STEREODELAY_CS_11KHZ,
    267     LVCS_STEREODELAY_CS_12KHZ,
    268     LVCS_STEREODELAY_CS_16KHZ,
    269     LVCS_STEREODELAY_CS_22KHZ,
    270     LVCS_STEREODELAY_CS_24KHZ,
    271     LVCS_STEREODELAY_CS_32KHZ,
    272     LVCS_STEREODELAY_CS_44KHZ,
    273     LVCS_STEREODELAY_CS_48KHZ};
    274 
    275 /************************************************************************************/
    276 /*                                                                                  */
    277 /*  Reverb coefficients constant table                                              */
    278 /*                                                                                  */
    279 /************************************************************************************/
    280 
    281 const BiquadA012B12CoefsSP_t LVCS_ReverbCoefTable[] = {
    282     /* Headphone coefficients */
    283     {CS_REVERB_8000_A0,             /* 8kS/s coefficients */
    284      CS_REVERB_8000_A1,
    285      CS_REVERB_8000_A2,
    286      CS_REVERB_8000_B1,
    287      CS_REVERB_8000_B2,
    288      (LVM_UINT16 )CS_REVERB_8000_SCALE},
    289     {CS_REVERB_11025_A0,            /* 11kS/s coefficients */
    290      CS_REVERB_11025_A1,
    291      CS_REVERB_11025_A2,
    292      CS_REVERB_11025_B1,
    293      CS_REVERB_11025_B2,
    294      (LVM_UINT16 )CS_REVERB_11025_SCALE},
    295     {CS_REVERB_12000_A0,            /* 12kS/s coefficients */
    296      CS_REVERB_12000_A1,
    297      CS_REVERB_12000_A2,
    298      CS_REVERB_12000_B1,
    299      CS_REVERB_12000_B2,
    300      (LVM_UINT16 )CS_REVERB_12000_SCALE},
    301     {CS_REVERB_16000_A0,            /* 16kS/s coefficients */
    302      CS_REVERB_16000_A1,
    303      CS_REVERB_16000_A2,
    304      CS_REVERB_16000_B1,
    305      CS_REVERB_16000_B2,
    306      (LVM_UINT16 )CS_REVERB_16000_SCALE},
    307     {CS_REVERB_22050_A0,            /* 22kS/s coefficients */
    308      CS_REVERB_22050_A1,
    309      CS_REVERB_22050_A2,
    310      CS_REVERB_22050_B1,
    311      CS_REVERB_22050_B2,
    312      (LVM_UINT16 )CS_REVERB_22050_SCALE},
    313     {CS_REVERB_24000_A0,            /* 24kS/s coefficients */
    314      CS_REVERB_24000_A1,
    315      CS_REVERB_24000_A2,
    316      CS_REVERB_24000_B1,
    317      CS_REVERB_24000_B2,
    318      (LVM_UINT16 )CS_REVERB_24000_SCALE},
    319     {CS_REVERB_32000_A0,            /* 32kS/s coefficients */
    320      CS_REVERB_32000_A1,
    321      CS_REVERB_32000_A2,
    322      CS_REVERB_32000_B1,
    323      CS_REVERB_32000_B2,
    324      (LVM_UINT16 )CS_REVERB_32000_SCALE},
    325     {CS_REVERB_44100_A0,            /* 44kS/s coefficients */
    326      CS_REVERB_44100_A1,
    327      CS_REVERB_44100_A2,
    328      CS_REVERB_44100_B1,
    329      CS_REVERB_44100_B2,
    330      (LVM_UINT16 )CS_REVERB_44100_SCALE},
    331     {CS_REVERB_48000_A0,            /* 48kS/s coefficients */
    332      CS_REVERB_48000_A1,
    333      CS_REVERB_48000_A2,
    334      CS_REVERB_48000_B1,
    335      CS_REVERB_48000_B2,
    336      (LVM_UINT16 )CS_REVERB_48000_SCALE}
    337 };
    338 
    339 
    340 /************************************************************************************/
    341 /*                                                                                  */
    342 /*  Bypass mixer constant tables                                                    */
    343 /*                                                                                  */
    344 /************************************************************************************/
    345 
    346 const Gain_t LVCS_OutputGainTable[] = {
    347     {LVCS_HEADPHONE_SHIFT,         /* Headphone, stereo mode */
    348      LVCS_HEADPHONE_SHIFTLOSS,
    349      LVCS_HEADPHONE_GAIN},
    350     {LVCS_EX_HEADPHONE_SHIFT,      /* EX Headphone, stereo mode */
    351      LVCS_EX_HEADPHONE_SHIFTLOSS,
    352      LVCS_EX_HEADPHONE_GAIN},
    353     {LVCS_HEADPHONE_SHIFT,         /* Headphone, mono mode */
    354      LVCS_HEADPHONE_SHIFTLOSS,
    355      LVCS_HEADPHONE_GAIN},
    356     {LVCS_EX_HEADPHONE_SHIFT,      /* EX Headphone, mono mode */
    357      LVCS_EX_HEADPHONE_SHIFTLOSS,
    358      LVCS_EX_HEADPHONE_GAIN}
    359 };
    360 
    361 
    362 /************************************************************************************/
    363 /*                                                                                  */
    364 /*  Volume correction table                                                         */
    365 /*                                                                                  */
    366 /*  Coefficient order:                                                              */
    367 /*      Compression 100% effect                                                     */
    368 /*      Compression 0% effect                                                       */
    369 /*      Gain 100% effect                                                            */
    370 /*      Gain 0% effect                                                              */
    371 /*                                                                                  */
    372 /*  The Compression gain is represented by a Q1.15 number to give a range of 0dB    */
    373 /*  to +6dB, E.g.:                                                                  */
    374 /*          0       is 0dB compression (no effect)                                  */
    375 /*          5461    is 1dB compression gain                                         */
    376 /*          10923   is 2dB compression gain                                         */
    377 /*          32767   is 6dB compression gain                                         */
    378 /*                                                                                  */
    379 /*  The Gain is represented as a Q3.13 number to give a range of +8 to -infinity    */
    380 /*  E.g.:                                                                           */
    381 /*          0       is -infinity                                                    */
    382 /*          32767   is +18dB (x8) gain                                              */
    383 /*          4096    is 0dB gain                                                     */
    384 /*          1024    is -12dB gain                                                   */
    385 /*                                                                                  */
    386 /************************************************************************************/
    387 const LVCS_VolCorrect_t LVCS_VolCorrectTable[] = {
    388     {14200,          /* Headphone, stereo mode */
    389      0,
    390      4096,
    391      5786},
    392     {14200,          /* EX Headphone, stereo mode */
    393      0,
    394      4096,
    395      5786},
    396     {32767,         /* Headphone, mono mode */
    397      0,
    398      4096,
    399      5786},
    400     {32767,         /* EX Headphone, mono mode */
    401      0,
    402      4096,
    403      5786}
    404 };
    405 
    406 /************************************************************************************/
    407 /*                                                                                  */
    408 /*  Mixer time constants, 100ms                                                     */
    409 /*                                                                                  */
    410 /************************************************************************************/
    411 
    412 #define LVCS_VOL_TC_Fs8000      32580       /* Floating point value 0.994262695 */
    413 #define LVCS_VOL_TC_Fs11025     32632       /* Floating point value 0.995849609 */
    414 #define LVCS_VOL_TC_Fs12000     32643       /* Floating point value 0.996185303 */
    415 #define LVCS_VOL_TC_Fs16000     32674       /* Floating point value 0.997131348 */
    416 #define LVCS_VOL_TC_Fs22050     32700       /* Floating point value 0.997924805 */
    417 #define LVCS_VOL_TC_Fs24000     32705       /* Floating point value 0.998077393 */
    418 #define LVCS_VOL_TC_Fs32000     32721       /* Floating point value 0.998565674 */
    419 #define LVCS_VOL_TC_Fs44100     32734       /* Floating point value 0.998962402 */
    420 #define LVCS_VOL_TC_Fs48000     32737       /* Floating point value 0.999053955 */
    421 
    422 
    423 const LVM_INT16 LVCS_VolumeTCTable[9] = {LVCS_VOL_TC_Fs8000,
    424                                         LVCS_VOL_TC_Fs11025,
    425                                         LVCS_VOL_TC_Fs12000,
    426                                         LVCS_VOL_TC_Fs16000,
    427                                         LVCS_VOL_TC_Fs22050,
    428                                         LVCS_VOL_TC_Fs24000,
    429                                         LVCS_VOL_TC_Fs32000,
    430                                         LVCS_VOL_TC_Fs44100,
    431                                         LVCS_VOL_TC_Fs48000};
    432 
    433 /************************************************************************************/
    434 /*                                                                                  */
    435 /*  Sample rate table                                                               */
    436 /*                                                                                  */
    437 /************************************************************************************/
    438 
    439 const LVM_INT32   LVCS_SampleRateTable[9] = {8000,
    440                                             11025,
    441                                             12000,
    442                                             16000,
    443                                             22050,
    444                                             24000,
    445                                             32000,
    446                                             44100,
    447                                             48000};
    448 
    449