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 ------------------------------------------------------------------------------
     31 
     32 
     33 
     34  Pathname: ./audio/gsm-amr/c/src/int_lsf.c
     35 
     36      Date: 04/20/2000
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41  Description: Put file into template and first pass at optimization.
     42 
     43  Description: Made changes based on comments from the review meeting. Used
     44     pointers instead of index addressing in the arrays.
     45 
     46  Description: Added type definition to the input/output section. Fixed tabs.
     47               Deleted pseudo-code.
     48 
     49  Description: Synchronized file with UMTS versin 3.2.0. Updated coding
     50               template. Removed unnecessary include files.
     51 
     52  Description: Made the following changes per comments from Phase 2/3 review:
     53               1. Modified FOR loops to count down.
     54               2. Made some cosmetic changes in the Pseudo-code section.
     55 
     56  Description: Changed to pass in overflow flag pointer to the add() routine.
     57 
     58  Description:  Replaced "int" and/or "char" with OSCL defined types.
     59 
     60  Description:
     61 
     62 ------------------------------------------------------------------------------
     63 */
     64 
     65 /*----------------------------------------------------------------------------
     66 ; INCLUDES
     67 ----------------------------------------------------------------------------*/
     68 #include    "int_lsf.h"
     69 #include    "typedef.h"
     70 #include    "basic_op.h"
     71 #include    "cnst.h"
     72 
     73 /*----------------------------------------------------------------------------
     74 ; MACROS
     75 ; Define module specific macros here
     76 ----------------------------------------------------------------------------*/
     77 
     78 
     79 /*----------------------------------------------------------------------------
     80 ; DEFINES
     81 ; Include all pre-processor statements here. Include conditional
     82 ; compile variables also.
     83 ----------------------------------------------------------------------------*/
     84 
     85 
     86 /*----------------------------------------------------------------------------
     87 ; LOCAL FUNCTION DEFINITIONS
     88 ; Function Prototype declaration
     89 ----------------------------------------------------------------------------*/
     90 
     91 
     92 /*----------------------------------------------------------------------------
     93 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
     94 ; Variable declaration - defined here and used outside this module
     95 ----------------------------------------------------------------------------*/
     96 
     97 
     98 /*
     99 ------------------------------------------------------------------------------
    100  FUNCTION NAME: Int_lsf
    101 ------------------------------------------------------------------------------
    102  INPUT AND OUTPUT DEFINITIONS
    103 
    104  Inputs:
    105     lsf_old = LSF vector at the 4th SF of past frame (Word16)
    106     lsf_new = LSF vector at the 4th SF of present frame (Word16)
    107     i_subfr = Current subframe (equal to 0,40,80 or 120) (Word16)
    108     lsf_out = interpolated LSF parameters for current subframe (Word16)
    109 
    110  Outputs:
    111     lsf_out   = new interpolated LSF parameters for current subframe
    112     pOverflow = pointer of type Flag * to overflow indicator.
    113 
    114  Returns:
    115     None.
    116 
    117  Global Variables Used:
    118     None.
    119 
    120  Local Variables Needed:
    121     None.
    122 
    123 ------------------------------------------------------------------------------
    124  FUNCTION DESCRIPTION
    125 
    126  This function interpolates the LSFs for selected subframe.
    127  The 20 ms speech frame is divided into 4 subframes. The LSFs are
    128  interpolated at the 1st, 2nd and 3rd subframe and only forwarded
    129  at the 4th subframe.
    130 
    131                       |------|------|------|------|
    132                          sf1    sf2    sf3    sf4
    133                    F0                          F1
    134 
    135                  sf1:   3/4 F0 + 1/4 F1         sf3:   1/4 F0 + 3/4 F1
    136                  sf2:   1/2 F0 + 1/2 F1         sf4:       F1
    137 
    138 ------------------------------------------------------------------------------
    139  REQUIREMENTS
    140 
    141  None.
    142 
    143 ------------------------------------------------------------------------------
    144  REFERENCES
    145 
    146  int_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
    147 
    148 ------------------------------------------------------------------------------
    149  PSEUDO-CODE
    150 
    151 void Int_lsf(
    152     Word16 lsf_old[], // i : LSF vector at the 4th SF of past frame
    153     Word16 lsf_new[], // i : LSF vector at the 4th SF of present frame
    154     Word16 i_subfr,   // i : Pointer to current sf (equal to 0,40,80 or 120)
    155     Word16 lsf_out[]  // o : interpolated LSF parameters for current sf
    156 )
    157 {
    158     Word16 i;
    159 
    160     if ( i_subfr == 0 )
    161     {
    162        for (i = 0; i < M; i++) {
    163           lsf_out[i] = add(sub(lsf_old[i], shr(lsf_old[i], 2)),
    164                            shr(lsf_new[i], 2));
    165        }
    166     }
    167     else if ( sub(i_subfr, 40) == 0 )
    168     {
    169        for (i = 0; i < M; i++) {
    170           lsf_out[i] = add(shr(lsf_old[i],1), shr(lsf_new[i], 1) );
    171        }
    172     }
    173     else if ( sub(i_subfr, 80) == 0 )
    174     {
    175        for (i = 0; i < M; i++) {
    176           lsf_out[i] = add(shr(lsf_old[i], 2),
    177                            sub(lsf_new[i], shr(lsf_new[i], 2)));
    178        }
    179     }
    180     else if ( sub(i_subfr, 120) == 0 )
    181     {
    182        for (i = 0; i < M; i++) {
    183           lsf_out[i] = lsf_new[i];
    184        }
    185     }
    186 
    187     return;
    188 }
    189 
    190 ------------------------------------------------------------------------------
    191  RESOURCES USED [optional]
    192 
    193  When the code is written for a specific target processor the
    194  the resources used should be documented below.
    195 
    196  HEAP MEMORY USED: x bytes
    197 
    198  STACK MEMORY USED: x bytes
    199 
    200  CLOCK CYCLES: (cycle count equation for this function) + (variable
    201                 used to represent cycle count for each subroutine
    202                 called)
    203      where: (cycle count variable) = cycle count for [subroutine
    204                                      name]
    205 
    206 ------------------------------------------------------------------------------
    207  CAUTION [optional]
    208  [State any special notes, constraints or cautions for users of this function]
    209 
    210 ------------------------------------------------------------------------------
    211 */
    212 
    213 void Int_lsf(
    214     Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame         */
    215     Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame      */
    216     Word16 i_subfr,   /* i : Current sf (equal to 0,40,80 or 120)           */
    217     Word16 lsf_out[], /* o : interpolated LSF parameters for current sf     */
    218     Flag  *pOverflow  /* o : flag set if overflow occurs                    */
    219 )
    220 {
    221     register Word16 i;
    222     register Word16 temp1;
    223     register Word16 temp2;
    224 
    225     if (i_subfr == 0)
    226     {
    227         for (i = M - 1; i >= 0; i--)
    228         {
    229             if (*(lsf_old + i) < 0)
    230             {
    231                 temp1 = ~(~(*(lsf_old + i)) >> 2);
    232             }
    233             else
    234             {
    235                 temp1 = *(lsf_old + i) >> 2;
    236             }
    237             if (*(lsf_new + i) < 0)
    238             {
    239                 temp2 = ~(~(*(lsf_new + i)) >> 2);
    240             }
    241             else
    242             {
    243                 temp2 = *(lsf_new + i) >> 2;
    244             }
    245             *(lsf_out + i) = add((Word16)(*(lsf_old + i) - temp1),
    246                                  (Word16)temp2,
    247                                  pOverflow);
    248         }
    249     }
    250 
    251     else if (i_subfr == 40)
    252     {
    253         for (i = M - 1; i >= 0; i--)
    254         {
    255             if (*(lsf_old + i) < 0)
    256             {
    257                 temp1 = ~(~(*(lsf_old + i)) >> 1);
    258             }
    259             else
    260             {
    261                 temp1 = *(lsf_old + i) >> 1;
    262             }
    263             if (*(lsf_new + i) < 0)
    264             {
    265                 temp2 = ~(~(*(lsf_new + i)) >> 1);
    266             }
    267             else
    268             {
    269                 temp2 = *(lsf_new + i) >> 1;
    270             }
    271             *(lsf_out + i) = add(
    272                                  temp1,
    273                                  temp2,
    274                                  pOverflow);
    275         }
    276     }
    277 
    278     else if (i_subfr == 80)
    279     {
    280         for (i = M - 1; i >= 0; i--)
    281         {
    282             if (*(lsf_old + i) < 0)
    283             {
    284                 temp1 = ~(~(*(lsf_old + i)) >> 2);
    285             }
    286             else
    287             {
    288                 temp1 = *(lsf_old + i) >> 2;
    289             }
    290             if (*(lsf_new + i) < 0)
    291             {
    292                 temp2 = ~(~(*(lsf_new + i)) >> 2);
    293             }
    294             else
    295             {
    296                 temp2 = *(lsf_new + i) >> 2;
    297             }
    298             *(lsf_out + i) = add((Word16)temp1,
    299                                  (Word16)(*(lsf_new + i) - temp2),
    300                                  pOverflow);
    301 
    302         }
    303     }
    304 
    305     else if (i_subfr == 120)
    306     {
    307         for (i = M - 1; i >= 0; i--)
    308         {
    309             *(lsf_out + i) = *(lsf_new + i);
    310         }
    311     }
    312 
    313     return;
    314 }
    315 
    316