1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
33 ------------------------------------------------------------------------------
36 Rounding function with saturation.
38 ------------------------------------------------------------------------------
41 /*----------------------------------------------------------------------------
43 ----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------
48 ; [Define module specific macros here]
49 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
53 ; [Include all pre-processor statements here. Include conditional
54 ; compile variables also.]
55 ----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------
58 ; LOCAL FUNCTION DEFINITIONS
59 ; [List function prototypes here]
60 ----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
63 ; LOCAL VARIABLE DEFINITIONS
64 ; [Variable declaration - defined here and used outside this module]
65 ----------------------------------------------------------------------------*/
68 ------------------------------------------------------------------------------
69 FUNCTION NAME: pv_round
70 ------------------------------------------------------------------------------
71 INPUT AND OUTPUT DEFINITIONS
74 L_var1 = 32 bit signed integer (Word32) whose value falls
75 in the range : 0x8000 0000 <= L_var1 <= 0x7fff ffff.
77 pOverflow = pointer to overflow (Flag)
83 result = MS 16 bits of rounded input L_var1.
85 Global Variables Used:
88 Local Variables Needed:
91 ------------------------------------------------------------------------------
94 This function rounds the lower 16 bits of the 32 bit input number into the
95 MS 16 bits with saturation. Shift the resulting bits right by 16 and return
97 pv_round(L_var1) = extract_h(L_add(L_var1,32768))
99 ------------------------------------------------------------------------------
104 ------------------------------------------------------------------------------
107 [1] round() function in basic_op2.c, UMTS GSM AMR speech codec, R99 -
108 Version 3.2.0, March 2, 2001
110 ------------------------------------------------------------------------------
113 Word16 pv_round (Word32 L_var1)
118 * The reference ETSI code uses a global flag for Overflow in the L_add() function.
119 * In the actual implementation a pointer to Overflow flag is passed in as a
120 * parameter to the function.
122 L_rounded = L_add (L_var1, (Word32) 0x00008000L);
124 multiCounter[currCounter].L_add--;
126 var_out = extract_h (L_rounded);
128 multiCounter[currCounter].extract_h--;
129 multiCounter[currCounter].round++;
134 ------------------------------------------------------------------------------
136 [State any special notes, constraints or cautions for users of this function]
138 ------------------------------------------------------------------------------
141 /*----------------------------------------------------------------------------
143 ----------------------------------------------------------------------------*/
144 OSCL_EXPORT_REF Word16 pv_round(register Word32 L_var1, Flag *pOverflow)
148 L_var1 = L_add(L_var1, (Word32) 0x00008000L, pOverflow);
149 result = (Word16)(L_var1 >> 16);