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.173
     22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
     23     Available from http://www.3gpp.org
     24 
     25 (C) 2007, 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: ./src/pvamrwbdecoder_basic_op.h
     35 
     36      Date: 05/07/2007
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41  Description:
     42 ------------------------------------------------------------------------------
     43  INCLUDE DESCRIPTION
     44 
     45 ------------------------------------------------------------------------------
     46 */
     47 
     48 
     49 #ifndef PVAMRWBDECODER_BASIC_OP_H
     50 #define PVAMRWBDECODER_BASIC_OP_H
     51 
     52 
     53 #include "normalize_amr_wb.h"
     54 
     55 
     56 #define MAX_32 (int32)0x7fffffffL
     57 #define MIN_32 (int32)0x80000000L
     58 
     59 #define MAX_16 ((int16)+32767)    /* 0x7fff */
     60 #define MIN_16 ((int16)-32768)    /* 0x8000 */
     61 
     62 
     63 
     64 
     65 /*----------------------------------------------------------------------------
     66      Function Name : negate_int16
     67 
     68      Negate var1 with saturation, saturate in the case where input is -32768:
     69                   negate(var1) = sub(0,var1).
     70 
     71      Inputs :
     72       var1
     73                16 bit short signed integer (int16) whose value falls in the
     74                range : 0x8000 <= var1 <= 0x7fff.
     75 
     76      Outputs :
     77       none
     78 
     79      Return Value :
     80                16 bit short signed integer (int16) whose value falls in the
     81                range : 0x8000 <= var_out <= 0x7fff.
     82  ----------------------------------------------------------------------------*/
     83 
     84 __inline int16 negate_int16(int16 var1)
     85 {
     86     return (((var1 == MIN_16) ? MAX_16 : -var1));
     87 }
     88 
     89 
     90 /*----------------------------------------------------------------------------
     91 
     92      Function Name : shl_int16
     93 
     94      Arithmetically shift the 16 bit input var1 left var2 positions.Zero fill
     95      the var2 LSB of the result. If var2 is negative, arithmetically shift
     96      var1 right by -var2 with sign extension. Saturate the result in case of
     97      underflows or overflows.
     98 
     99      Inputs :
    100       var1
    101                16 bit short signed integer (int16) whose value falls in the
    102                range : 0x8000 <= var1 <= 0x7fff.
    103 
    104       var2
    105                16 bit short signed integer (int16) whose value falls in the
    106                range : 0x8000 <= var1 <= 0x7fff.
    107 
    108      Return Value :
    109       var_out
    110                16 bit short signed integer (int16) whose value falls in the
    111                range : 0x8000 <= var_out <= 0x7fff.
    112  ----------------------------------------------------------------------------*/
    113 
    114 __inline int16 shl_int16(int16 var1, int16 var2)
    115 {
    116     int16 var_out;
    117 
    118     if (var2 < 0)
    119     {
    120         var2 = (-var2) & (0xf);
    121         var_out = var1 >> var2;
    122     }
    123     else
    124     {
    125         var2 &= 0xf;
    126         var_out = var1 << var2;
    127         if (var_out >> var2 != var1)
    128         {
    129             var_out = (var1 >> 15) ^ MAX_16;
    130         }
    131     }
    132     return (var_out);
    133 }
    134 
    135 
    136 /*----------------------------------------------------------------------------
    137 
    138      Function Name : shl_int32
    139 
    140      Arithmetically shift the 32 bit input L_var1 left var2 positions. Zero
    141      fill the var2 LSB of the result. If var2 is negative, arithmetically
    142      shift L_var1 right by -var2 with sign extension. Saturate the result in
    143      case of underflows or overflows.
    144 
    145      Inputs :
    146       L_var1   32 bit long signed integer (int32) whose value falls in the
    147                range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
    148 
    149       var2
    150                16 bit short signed integer (int16) whose value falls in the
    151                range :  8000 <= var2 <= 7fff.
    152      Return Value :
    153                32 bit long signed integer (int32) whose value falls in the
    154                range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    155 
    156  ----------------------------------------------------------------------------*/
    157 
    158 __inline int32 shl_int32(int32 L_var1, int16 var2)
    159 {
    160     int32 L_var_out;
    161 
    162     if (var2 > 0)
    163     {
    164         L_var_out = L_var1 << var2;
    165         if (L_var_out >> var2 != L_var1)
    166         {
    167             L_var_out = (L_var1 >> 31) ^ MAX_32;
    168         }
    169     }
    170     else
    171     {
    172         var2 = (-var2) & (0xf);
    173         L_var_out = L_var1 >> var2;
    174     }
    175 
    176     return (L_var_out);
    177 }
    178 
    179 
    180 /*----------------------------------------------------------------------------
    181 
    182      Function Name : shr_int32
    183 
    184      Arithmetically shift the 32 bit input L_var1 right var2 positions with
    185      sign extension. If var2 is negative, arithmetically shift L_var1 left
    186      by -var2 and zero fill the -var2 LSB of the result. Saturate the result
    187      in case of underflows or overflows.
    188 
    189      Inputs :
    190       L_var1   32 bit long signed integer (int32) whose value falls in the
    191                range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
    192 
    193       var2
    194                16 bit short signed integer (int16) whose value falls in the
    195                range :  8000 <= var2 <= 7fff.
    196      Return Value :
    197                32 bit long signed integer (int32) whose value falls in the
    198                range : 0x8000 0000 <= L_var_out <= 0x7fff ffff.
    199 
    200  ----------------------------------------------------------------------------*/
    201 
    202 __inline int32 shr_int32(int32 L_var1, int16 var2)
    203 {
    204     int32 L_var_out;
    205 
    206     if (var2 >= 0)
    207     {
    208         L_var_out = L_var1 >> (var2 & 0x1f);
    209     }
    210     else
    211     {
    212         var2 = (int16)(-var2);
    213         var2 &= 0x1f;
    214         L_var_out = L_var1 << var2;
    215         if (L_var_out >> var2 != L_var1)
    216         {
    217             L_var_out = (L_var1 >> 31) ^ MAX_32;
    218         }
    219 
    220     }
    221     return (L_var_out);
    222 }
    223 
    224 
    225 
    226 
    227 
    228 
    229 #if defined(PV_ARM_V5)
    230 
    231 #include "pvamrwbdecoder_basic_op_armv5.h"
    232 
    233 #elif defined(PV_ARM_GCC_V5)
    234 
    235 #include "pvamrwbdecoder_basic_op_gcc_armv5.h"
    236 
    237 #else
    238 
    239 #ifndef C_EQUIVALENT
    240 #define C_EQUIVALENT        // default to C_EQUIVALENT
    241 #endif
    242 
    243 #include "pvamrwbdecoder_basic_op_cequivalent.h"
    244 
    245 #endif
    246 
    247 
    248 #endif   /*  PVAMRWBDECODER_BASIC_OP_H  */
    249 
    250