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 /*----------------------------------------------------------------------------
38 ----------------------------------------------------------------------------*/
42 /*----------------------------------------------------------------------------
44 ; [Define module specific macros here]
45 ----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------
49 ; [Include all pre-processor statements here. Include conditional
50 ; compile variables also.]
51 ----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
54 ; LOCAL FUNCTION DEFINITIONS
55 ; [List function prototypes here]
56 ----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------
59 ; LOCAL VARIABLE DEFINITIONS
60 ; [Variable declaration - defined here and used outside this module]
61 ----------------------------------------------------------------------------*/
65 ------------------------------------------------------------------------------
67 ------------------------------------------------------------------------------
68 INPUT AND OUTPUT DEFINITIONS
71 L_num = 32 bit signed integer (Word32) whose value falls in the
72 range : 0x0000 0000 < L_num < L_denom
73 L_denom_hi = 16 bit positive normalized integer whose value falls in
74 the range : 0x4000 < hi < 0x7fff
75 L_denom_lo = 16 bit positive integer whose value falls in the range :
78 pOverflow = pointer to overflow (Flag)
81 pOverflow -> 1 if the 32 bit divide operation resulted in overflow
84 result = 32-bit quotient of of the division of two 32 bit integers
85 L_num / L_denom (Word32)
87 Global Variables Used:
90 Local Variables Needed:
93 ------------------------------------------------------------------------------
96 This function is a fractional integer division of two 32 bit numbers, the
97 numerator L_num and the denominator L_denom. The denominator is formed by
98 combining denom_hi and denom_lo. Note that denom_hi is a normalized numbers.
99 The numerator and denominator must be positive and the numerator must be
100 less than the denominator.
102 The division is done as follows:
103 1. Find 1/L_denom by first approximating: approx = 1 / denom_hi.
104 2. 1/L_denom = approx * (2.0 - L_denom * approx ).
105 3. result = L_num * (1/L_denom).
107 ------------------------------------------------------------------------------
112 ------------------------------------------------------------------------------
115 [1] div_32() function in oper_32b.c, UMTS GSM AMR speech codec, R99 -
116 Version 3.2.0, March 2, 2001
118 ------------------------------------------------------------------------------
122 ------------------------------------------------------------------------------
124 [State any special notes, constraints or cautions for users of this function]
126 ------------------------------------------------------------------------------
129 /*----------------------------------------------------------------------------
131 ----------------------------------------------------------------------------*/
132 Word32 Div_32(Word32 L_num,
145 /* First approximation: 1 / L_denom = 1/L_denom_hi */
147 approx = div_s((Word16) 0x3fff, L_denom_hi);
149 /* 1/L_denom = approx * (2.0 - L_denom * approx) */
151 result = Mpy_32_16(L_denom_hi, L_denom_lo, approx, pOverflow);
152 /* result is > 0 , and less than 1.0 */
153 result = 0x7fffffffL - result;
155 hi = (Word16)(result >> 16);
156 lo = (result >> 1) - (hi << 15);
158 result = Mpy_32_16(hi, lo, approx, pOverflow);
160 /* L_num * (1/L_denom) */
162 hi = (Word16)(result >> 16);
163 lo = (result >> 1) - (hi << 15);
165 n_hi = (Word16)(L_num >> 16);
166 n_lo = (L_num >> 1) - (n_hi << 15);
168 result = Mpy_32(n_hi, n_lo, hi, lo, pOverflow);
169 result = L_shl(result, 2, pOverflow);