Home | History | Annotate | Download | only in src
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /****************************************************************************************
     19 Portions of this file are derived from the following 3GPP standard:
     20 
     21     3GPP TS 26.073
     22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
     26 Permission to distribute, modify and use this file under the standard license
     27 terms listed above has been obtained from the copyright holder.
     28 ****************************************************************************************/
     29 /*
     30  Pathname: ./audio/gsm-amr/c/src/int_lpc.c
     31  Functions:
     32 
     33 ------------------------------------------------------------------------------
     34  REVISION HISTORY
     35 
     36  Description: Updated template used to PV coding template.
     37  Changed to accept the pOverflow flag for EPOC compatibility.
     38 
     39  Description: Per review comments, replaced includes of "basic_op.h"
     40  and "count.h" with "shr.h", "sub.h", and "add.h"
     41 
     42  Description:  For Int_lpc_1and3()  and Int_lpc_1and3_2()
     43               1. Replaced array addressing by pointers
     44               2. Eliminated math operations that unnecessary checked for
     45                  saturation
     46               3. Unrolled loops to speed up processing
     47 
     48  Description:  Replaced "int" and/or "char" with OSCL defined types.
     49 
     50 
     51  Who:                           Date:
     52  Description:
     53 
     54 ------------------------------------------------------------------------------
     55  MODULE DESCRIPTION
     56 
     57 
     58 ------------------------------------------------------------------------------
     59 */
     60 
     61 /*----------------------------------------------------------------------------
     62 ; INCLUDES
     63 ----------------------------------------------------------------------------*/
     64 #include "int_lpc.h"
     65 #include "typedef.h"
     66 #include "cnst.h"
     67 #include "lsp_az.h"
     68 #include "basic_op.h"
     69 
     70 /*----------------------------------------------------------------------------
     71 ; MACROS
     72 ; Define module specific macros here
     73 ----------------------------------------------------------------------------*/
     74 
     75 /*----------------------------------------------------------------------------
     76 ; DEFINES
     77 ; Include all pre-processor statements here. Include conditional
     78 ; compile variables also.
     79 ----------------------------------------------------------------------------*/
     80 
     81 /*----------------------------------------------------------------------------
     82 ; LOCAL FUNCTION DEFINITIONS
     83 ; Function Prototype declaration
     84 ----------------------------------------------------------------------------*/
     85 
     86 /*----------------------------------------------------------------------------
     87 ; LOCAL VARIABLE DEFINITIONS
     88 ; Variable declaration - defined here and used outside this module
     89 ----------------------------------------------------------------------------*/
     90 
     91 
     92 /*
     93 ------------------------------------------------------------------------------
     94  FUNCTION NAME: Int_lpc_1and3
     95 ------------------------------------------------------------------------------
     96  INPUT AND OUTPUT DEFINITIONS
     97 
     98  Inputs:
     99     lsp_old -- array of type Word16 -- LSP vector at the
    100                                        4th subfr. of past frame (M)
    101     lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of
    102                                        present frame (M)
    103     lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
    104                                        present frame (M)
    105 
    106  Outputs:
    107     Az -- array of type Word16 -- interpolated LP parameters in all subfr.
    108                                   (AZ_SIZE)
    109     pOverflow -- pointer to type Flag -- Overflow indicator
    110 
    111  Returns:
    112     None
    113 
    114  Global Variables Used:
    115     None
    116 
    117  Local Variables Needed:
    118     None
    119 
    120 ------------------------------------------------------------------------------
    121  FUNCTION DESCRIPTION
    122 
    123  Purpose     : Interpolates the LSPs and converts to LPC parameters
    124                to get a different LP filter in each subframe.
    125  Description : The 20 ms speech frame is divided into 4 subframes.
    126                The LSPs are quantized and transmitted at the 2nd and
    127                4th subframes (twice per frame) and interpolated at the
    128                1st and 3rd subframe.
    129 
    130                      |------|------|------|------|
    131                         sf1    sf2    sf3    sf4
    132                   F0            Fm            F1
    133 
    134                 sf1:   1/2 Fm + 1/2 F0         sf3:   1/2 F1 + 1/2 Fm
    135                 sf2:       Fm                  sf4:       F1
    136 
    137 ------------------------------------------------------------------------------
    138  REQUIREMENTS
    139 
    140  None
    141 
    142 ------------------------------------------------------------------------------
    143  REFERENCES
    144 
    145  int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    146 
    147 ------------------------------------------------------------------------------
    148  PSEUDO-CODE
    149 
    150 
    151 ------------------------------------------------------------------------------
    152  RESOURCES USED [optional]
    153 
    154  When the code is written for a specific target processor the
    155  the resources used should be documented below.
    156 
    157  HEAP MEMORY USED: x bytes
    158 
    159  STACK MEMORY USED: x bytes
    160 
    161  CLOCK CYCLES: (cycle count equation for this function) + (variable
    162                 used to represent cycle count for each subroutine
    163                 called)
    164      where: (cycle count variable) = cycle count for [subroutine
    165                                      name]
    166 
    167 ------------------------------------------------------------------------------
    168  CAUTION [optional]
    169  [State any special notes, constraints or cautions for users of this function]
    170 
    171 ------------------------------------------------------------------------------
    172 */
    173 
    174 void Int_lpc_1and3(
    175     Word16 lsp_old[],  /* i : LSP vector at the 4th subfr. of past frame (M) */
    176     Word16 lsp_mid[],  /* i : LSP vector at the 2nd subfr. of
    177                               present frame (M)                              */
    178     Word16 lsp_new[],  /* i : LSP vector at the 4th subfr. of
    179                               present frame (M)                              */
    180     Word16 Az[],       /* o : interpolated LP parameters in all subfr.
    181                               (AZ_SIZE)                                      */
    182     Flag  *pOverflow
    183 )
    184 {
    185     Word16 i;
    186     Word16 lsp[M];
    187     Word16 *p_lsp_old = &lsp_old[0];
    188     Word16 *p_lsp_mid = &lsp_mid[0];
    189     Word16 *p_lsp_new = &lsp_new[0];
    190     Word16 *p_lsp     = &lsp[0];
    191 
    192     /*  lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
    193 
    194     for (i = M >> 1; i != 0; i--)
    195     {
    196         *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
    197         *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
    198     }
    199 
    200     Lsp_Az(
    201         lsp,
    202         Az,
    203         pOverflow);       /* Subframe 1 */
    204 
    205     Az += MP1;
    206 
    207     Lsp_Az(
    208         lsp_mid,
    209         Az,
    210         pOverflow);       /* Subframe 2 */
    211 
    212     Az += MP1;
    213 
    214     p_lsp_mid = &lsp_mid[0];
    215     p_lsp     = &lsp[0];
    216 
    217     for (i = M >> 1; i != 0; i--)
    218     {
    219         *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
    220         *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
    221     }
    222 
    223     Lsp_Az(
    224         lsp,
    225         Az,
    226         pOverflow);           /* Subframe 3 */
    227 
    228     Az += MP1;
    229 
    230     Lsp_Az(
    231         lsp_new,
    232         Az,
    233         pOverflow);       /* Subframe 4 */
    234 
    235     return;
    236 }
    237 
    238 
    239 /*
    240 ------------------------------------------------------------------------------
    241  FUNCTION NAME: Int_lpc_1and3_2
    242 ------------------------------------------------------------------------------
    243  INPUT AND OUTPUT DEFINITIONS
    244 
    245  Inputs:
    246     lsp_old -- array of type Word16 -- LSP vector at the
    247                                        4th subfr. of past frame (M)
    248     lsp_mid -- array of type Word16 -- LSP vector at the 2nd subfr. of
    249                                        present frame (M)
    250     lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
    251                                        present frame (M)
    252 
    253  Outputs:
    254     Az -- array of type Word16 -- interpolated LP parameters in.
    255                                   subfr 1 and 2.
    256     pOverflow -- pointer to type Flag -- Overflow indicator
    257 
    258  Returns:
    259     None
    260 
    261  Global Variables Used:
    262 
    263 
    264  Local Variables Needed:
    265     None
    266 
    267 ------------------------------------------------------------------------------
    268  FUNCTION DESCRIPTION
    269 
    270  Purpose : Interpolation of the LPC parameters. Same as the Int_lpc
    271            function but we do not recompute Az() for subframe 2 and
    272            4 because it is already available.
    273 
    274 ------------------------------------------------------------------------------
    275  REQUIREMENTS
    276 
    277  None
    278 
    279 ------------------------------------------------------------------------------
    280  REFERENCES
    281 
    282  int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    283 
    284 ------------------------------------------------------------------------------
    285  PSEUDO-CODE
    286 
    287 
    288 ------------------------------------------------------------------------------
    289  RESOURCES USED [optional]
    290 
    291  When the code is written for a specific target processor the
    292  the resources used should be documented below.
    293 
    294  HEAP MEMORY USED: x bytes
    295 
    296  STACK MEMORY USED: x bytes
    297 
    298  CLOCK CYCLES: (cycle count equation for this function) + (variable
    299                 used to represent cycle count for each subroutine
    300                 called)
    301      where: (cycle count variable) = cycle count for [subroutine
    302                                      name]
    303 
    304 ------------------------------------------------------------------------------
    305  CAUTION [optional]
    306  [State any special notes, constraints or cautions for users of this function]
    307 
    308 ------------------------------------------------------------------------------
    309 */
    310 
    311 void Int_lpc_1and3_2(
    312     Word16 lsp_old[],  /* i : LSP vector at the 4th subfr. of past frame (M) */
    313     Word16 lsp_mid[],  /* i : LSP vector at the 2nd subframe of
    314                              present frame (M)                               */
    315     Word16 lsp_new[],  /* i : LSP vector at the 4th subframe of
    316                              present frame (M)                               */
    317     Word16 Az[],       /* o :interpolated LP parameters
    318                              in subframes 1 and 3 (AZ_SIZE)                  */
    319     Flag  *pOverflow
    320 )
    321 {
    322     Word16 i;
    323     Word16 lsp[M];
    324     Word16 *p_lsp_old = &lsp_old[0];
    325     Word16 *p_lsp_mid = &lsp_mid[0];
    326     Word16 *p_lsp_new = &lsp_new[0];
    327     Word16 *p_lsp     = &lsp[0];
    328 
    329     /*  lsp[i] = lsp_mid[i] * 0.5 + lsp_old[i] * 0.5 */
    330 
    331     for (i = M >> 1; i != 0; i--)
    332     {
    333         *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
    334         *(p_lsp++) = (*(p_lsp_old++) >> 1) + (*(p_lsp_mid++) >> 1);
    335     }
    336     Lsp_Az(lsp, Az, pOverflow);            /* Subframe 1 */
    337     Az += MP1 * 2;
    338 
    339     p_lsp_mid = &lsp_mid[0];
    340     p_lsp     = &lsp[0];
    341 
    342     for (i = M >> 1; i != 0; i--)
    343     {
    344         *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
    345         *(p_lsp++) = (*(p_lsp_mid++) >> 1) + (*(p_lsp_new++) >> 1);
    346     }
    347 
    348     Lsp_Az(lsp, Az, pOverflow);            /* Subframe 3 */
    349 
    350     return;
    351 }
    352 
    353 
    354 /*
    355 ------------------------------------------------------------------------------
    356  FUNCTION NAME: lsp
    357 ------------------------------------------------------------------------------
    358  INPUT AND OUTPUT DEFINITIONS
    359 
    360  Inputs:
    361     lsp_old -- array of type Word16 -- LSP vector at the
    362                                        4th subfr. of past frame (M)
    363     lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
    364                                        present frame (M)
    365 
    366  Outputs:
    367     Az -- array of type Word16 -- interpolated LP parameters in.
    368                                   all subframes.
    369     pOverflow -- pointer to type Flag -- Overflow indicator
    370 
    371  Returns:
    372     None
    373 
    374  Global Variables Used:
    375 
    376 
    377  Local Variables Needed:
    378     None
    379 
    380 ------------------------------------------------------------------------------
    381  FUNCTION DESCRIPTION
    382 
    383  PURPOSE:  Interpolates the LSPs and convert to LP parameters to get
    384            a different LP filter in each subframe.
    385 
    386  DESCRIPTION:
    387     The 20 ms speech frame is divided into 4 subframes.
    388     The LSPs are quantized and transmitted at the 4th subframe
    389     (once per frame) and interpolated at the 1st, 2nd and 3rd subframe.
    390 
    391          |------|------|------|------|
    392             sf1    sf2    sf3    sf4
    393       F0                          F1
    394 
    395     sf1:   3/4 F0 + 1/4 F1         sf3:   1/4 F0 + 3/4 F1
    396     sf2:   1/2 F0 + 1/2 F1         sf4:       F1
    397 
    398 ------------------------------------------------------------------------------
    399  REQUIREMENTS
    400 
    401  None
    402 
    403 ------------------------------------------------------------------------------
    404  REFERENCES
    405 
    406  int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    407 
    408 ------------------------------------------------------------------------------
    409  PSEUDO-CODE
    410 
    411 
    412 ------------------------------------------------------------------------------
    413  RESOURCES USED [optional]
    414 
    415  When the code is written for a specific target processor the
    416  the resources used should be documented below.
    417 
    418  HEAP MEMORY USED: x bytes
    419 
    420  STACK MEMORY USED: x bytes
    421 
    422  CLOCK CYCLES: (cycle count equation for this function) + (variable
    423                 used to represent cycle count for each subroutine
    424                 called)
    425      where: (cycle count variable) = cycle count for [subroutine
    426                                      name]
    427 
    428 ------------------------------------------------------------------------------
    429  CAUTION [optional]
    430  [State any special notes, constraints or cautions for users of this function]
    431 
    432 ------------------------------------------------------------------------------
    433 */
    434 
    435 void Int_lpc_1to3(
    436     Word16 lsp_old[], /* input : LSP vector at the 4th SF of past frame    */
    437     Word16 lsp_new[], /* input : LSP vector at the 4th SF of present frame */
    438     Word16 Az[],      /* output: interpolated LP parameters in all SFs     */
    439     Flag   *pOverflow
    440 )
    441 {
    442     Word16 i;
    443     Word16 temp;
    444     Word16 temp2;
    445 
    446     Word16 lsp[M];
    447 
    448     for (i = 0; i < M; i++)
    449     {
    450         temp = shr(lsp_old[i], 2, pOverflow);
    451         temp = sub(lsp_old[i], temp, pOverflow);
    452         temp2 = shr(lsp_new[i], 2, pOverflow);
    453 
    454         lsp[i] = add(temp2, temp, pOverflow);
    455     }
    456 
    457     Lsp_Az(
    458         lsp,
    459         Az,
    460         pOverflow);        /* Subframe 1 */
    461 
    462     Az += MP1;
    463 
    464 
    465     for (i = 0; i < M; i++)
    466     {
    467         temp = shr(lsp_new[i], 1, pOverflow);
    468         temp2 = shr(lsp_old[i], 1, pOverflow);
    469         lsp[i] = add(temp, temp2, pOverflow);
    470     }
    471 
    472     Lsp_Az(
    473         lsp,
    474         Az,
    475         pOverflow);        /* Subframe 2 */
    476 
    477     Az += MP1;
    478 
    479     for (i = 0; i < M; i++)
    480     {
    481         temp = shr(lsp_new[i], 2, pOverflow);
    482         temp = sub(lsp_new[i], temp, pOverflow);
    483         temp2 = shr(lsp_old[i], 2, pOverflow);
    484 
    485         lsp[i] = add(temp2, temp, pOverflow);
    486     }
    487 
    488     Lsp_Az(
    489         lsp,
    490         Az,
    491         pOverflow);       /* Subframe 3 */
    492 
    493     Az += MP1;
    494 
    495     Lsp_Az(
    496         lsp_new,
    497         Az,
    498         pOverflow);        /* Subframe 4 */
    499 
    500     return;
    501 }
    502 /*
    503 ------------------------------------------------------------------------------
    504  FUNCTION NAME: Int_lpc_1to3_2
    505 ------------------------------------------------------------------------------
    506  INPUT AND OUTPUT DEFINITIONS
    507 
    508  Inputs:
    509     lsp_old -- array of type Word16 -- LSP vector at the
    510                                        4th subfr. of past frame (M)
    511     lsp_new -- array of type Word16 -- LSP vector at the 4th subfr. of
    512                                        present frame (M)
    513 
    514  Outputs:
    515     Az -- array of type Word16 -- interpolated LP parameters in.
    516                                   subfr 1, 2, and 3.
    517     pOverflow -- pointer to type Flag -- Overflow indicator
    518 
    519  Returns:
    520     None
    521 
    522  Global Variables Used:
    523     None
    524 
    525  Local Variables Needed:
    526     None
    527 
    528 ------------------------------------------------------------------------------
    529  FUNCTION DESCRIPTION
    530 
    531  Interpolation of the LPC parameters.
    532  Same as the previous function but we do not recompute Az() for
    533  subframe 4 because it is already available.
    534 
    535 ------------------------------------------------------------------------------
    536  REQUIREMENTS
    537 
    538  None
    539 
    540 ------------------------------------------------------------------------------
    541  REFERENCES
    542 
    543  int_lpc.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    544 
    545 ------------------------------------------------------------------------------
    546  PSEUDO-CODE
    547 
    548 
    549 ------------------------------------------------------------------------------
    550  RESOURCES USED [optional]
    551 
    552  When the code is written for a specific target processor the
    553  the resources used should be documented below.
    554 
    555  HEAP MEMORY USED: x bytes
    556 
    557  STACK MEMORY USED: x bytes
    558 
    559  CLOCK CYCLES: (cycle count equation for this function) + (variable
    560                 used to represent cycle count for each subroutine
    561                 called)
    562      where: (cycle count variable) = cycle count for [subroutine
    563                                      name]
    564 
    565 ------------------------------------------------------------------------------
    566  CAUTION [optional]
    567  [State any special notes, constraints or cautions for users of this function]
    568 
    569 ------------------------------------------------------------------------------
    570 */
    571 
    572 void Int_lpc_1to3_2(
    573     Word16 lsp_old[],  /* input : LSP vector at the 4th SF of past frame    */
    574     Word16 lsp_new[],  /* input : LSP vector at the 4th SF of present frame */
    575     Word16 Az[],       /* output: interpolated LP parameters in SFs 1,2,3   */
    576     Flag   *pOverflow
    577 )
    578 {
    579     Word16 i;
    580     Word16 temp;
    581     Word16 temp2;
    582     Word16 lsp[M];
    583 
    584     for (i = 0; i < M; i++)
    585     {
    586         temp = shr(lsp_old[i], 2, pOverflow);
    587 
    588         temp = sub(lsp_old[i], temp, pOverflow);
    589 
    590         temp2 = shr(lsp_new[i], 2, pOverflow);
    591 
    592         lsp[i] = add(temp2, temp, pOverflow);
    593     }
    594 
    595     Lsp_Az(
    596         lsp,
    597         Az,
    598         pOverflow);        /* Subframe 1 */
    599 
    600     Az += MP1;
    601 
    602     for (i = 0; i < M; i++)
    603     {
    604         temp = shr(lsp_new[i], 1, pOverflow);
    605         temp2 = shr(lsp_old[i], 1, pOverflow);
    606 
    607         lsp[i] = add(temp2, temp, pOverflow);
    608     }
    609 
    610     Lsp_Az(
    611         lsp,
    612         Az,
    613         pOverflow);        /* Subframe 2 */
    614 
    615     Az += MP1;
    616 
    617     for (i = 0; i < M; i++)
    618     {
    619         temp = shr(lsp_new[i], 2, pOverflow);
    620         temp = sub(lsp_new[i], temp, pOverflow);
    621         temp2 = shr(lsp_old[i], 2, pOverflow);
    622 
    623         lsp[i] = add(temp, temp2, pOverflow);
    624     }
    625 
    626     Lsp_Az(
    627         lsp,
    628         Az,
    629         pOverflow);        /* Subframe 3 */
    630 
    631     return;
    632 }
    633 
    634