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