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  Filename: normalize_amr_wb.cpp
     35 
     36      Date: 12/10/2004
     37 
     38 ------------------------------------------------------------------------------
     39  REVISION HISTORY
     40 
     41 
     42  Description:
     43 
     44 ------------------------------------------------------------------------------
     45  INPUT AND OUTPUT DEFINITIONS
     46 
     47 Input
     48     Int32 x             32-bit integer non-zero input
     49 Returns
     50     Int16 i             number of leading zeros on x
     51 
     52 
     53 ------------------------------------------------------------------------------
     54  FUNCTION DESCRIPTION
     55 
     56     Returns number of leading zeros on the non-zero input
     57 
     58 ------------------------------------------------------------------------------
     59  REQUIREMENTS
     60 
     61 
     62 ------------------------------------------------------------------------------
     63  REFERENCES
     64 
     65 ------------------------------------------------------------------------------
     66  PSEUDO-CODE
     67 
     68 ------------------------------------------------------------------------------
     69 */
     70 
     71 
     72 /*----------------------------------------------------------------------------
     73 ; INCLUDES
     74 ----------------------------------------------------------------------------*/
     75 
     76 #include "pv_amr_wb_type_defs.h"
     77 #include "normalize_amr_wb.h"
     78 
     79 /*----------------------------------------------------------------------------
     80 ; MACROS
     81 ; Define module specific macros here
     82 ----------------------------------------------------------------------------*/
     83 
     84 
     85 /*----------------------------------------------------------------------------
     86 ; DEFINES
     87 ; Include all pre-processor statements here. Include conditional
     88 ; compile variables also.
     89 ----------------------------------------------------------------------------*/
     90 
     91 /*----------------------------------------------------------------------------
     92 ; LOCAL FUNCTION DEFINITIONS
     93 ; Function Prototype declaration
     94 ----------------------------------------------------------------------------*/
     95 
     96 /*----------------------------------------------------------------------------
     97 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
     98 ; Variable declaration - defined here and used outside this module
     99 ----------------------------------------------------------------------------*/
    100 
    101 /*----------------------------------------------------------------------------
    102 ; EXTERNAL FUNCTION REFERENCES
    103 ; Declare functions defined elsewhere and referenced in this module
    104 ----------------------------------------------------------------------------*/
    105 
    106 /*----------------------------------------------------------------------------
    107 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    108 ; Declare variables used in this module but defined elsewhere
    109 ----------------------------------------------------------------------------*/
    110 
    111 /*----------------------------------------------------------------------------
    112 ; FUNCTION CODE
    113 ----------------------------------------------------------------------------*/
    114 
    115 #if defined(PV_ARM_V5)
    116 #elif defined(PV_ARM_GCC_V5)
    117 
    118 /* function is inlined in header file */
    119 
    120 
    121 #else
    122 
    123 int16 normalize_amr_wb(int32 x)
    124 {
    125     /*----------------------------------------------------------------------------
    126     ; Define all local variables
    127     ----------------------------------------------------------------------------*/
    128     int16 i;
    129 
    130 
    131     if (x > 0x0FFFFFFF)
    132     {
    133         i = 0;  /* most likely case */
    134     }
    135     else if (x > 0x00FFFFFF)
    136     {
    137         i = 3;  /* second most likely case */
    138     }
    139     else if (x > 0x0000FFFF)
    140     {
    141         i  = x > 0x000FFFFF ?  7 :  11;
    142     }
    143     else
    144     {
    145         if (x > 0x000000FF)
    146         {
    147             i  = x > 0x00000FFF ?  15 :  19;
    148         }
    149         else
    150         {
    151             i  = x > 0x0000000F ?  23 :  27;
    152         }
    153     }
    154 
    155 
    156     x <<= i;
    157 
    158     switch (x & 0x78000000)
    159     {
    160         case 0x08000000:
    161             i += 3;
    162             break;
    163 
    164         case 0x18000000:
    165         case 0x10000000:
    166             i += 2;
    167             break;
    168         case 0x28000000:
    169         case 0x20000000:
    170         case 0x38000000:
    171         case 0x30000000:
    172             i++;
    173 
    174         default:
    175             ;
    176     }
    177 
    178     return i;
    179 
    180 }
    181 
    182 #endif
    183 
    184