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