Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / l_comp.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.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
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 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31  INPUT AND OUTPUT DEFINITIONS
32
33  Inputs:
34     hi = 16 bit signed integer (Word16) whose value falls in
35          the range : 0x8000 <= hi <= 0x7fff.
36     lo = 16 bit signed integer (Word16) whose value falls in
37          the range : 0x8000 <= lo <= 0x7fff.
38
39  Outputs:
40     pOverflow = 1 if overflow happens in a math function called by this function.
41     L_out = 32-bit result of (hi<<16 + lo<<1).
42
43  Returns:
44     None
45
46  Local Stores Modified:
47     None
48
49  Global Stores Modified:
50         None
51
52 ------------------------------------------------------------------------------
53  FUNCTION DESCRIPTION
54
55  This function composes a 32 bit integer from two 16 bit double precision
56  format (DPF) numbers hi and lo by the following operation:
57  1. Deposit hi into the 16 MS bits of the 32 bit output L_out.
58  2. Shift lo left by 1.
59  3. Add results from 1 and 2 with saturation to return the 32 bit result
60     L_out.
61
62 ------------------------------------------------------------------------------
63  REQUIREMENTS
64
65  None
66
67 ------------------------------------------------------------------------------
68  REFERENCES
69
70  [1] oper_32b.c, ETS Version 2.0.0, February 8, 1999
71
72 ------------------------------------------------------------------------------
73  PSEUDO-CODE
74
75 ------------------------------------------------------------------------------
76 */
77
78
79 /*----------------------------------------------------------------------------
80 ; INCLUDES
81 ----------------------------------------------------------------------------*/
82 #include "typedef.h"
83 #include "l_comp.h"
84 #include "basic_op.h"
85 /*----------------------------------------------------------------------------
86 ; MACROS
87 ; Define module specific macros here
88 ----------------------------------------------------------------------------*/
89
90 /*----------------------------------------------------------------------------
91 ; DEFINES
92 ; Include all pre-processor statements here. Include conditional
93 ; compile variables also.
94 ----------------------------------------------------------------------------*/
95
96 /*----------------------------------------------------------------------------
97 ; LOCAL FUNCTION DEFINITIONS
98 ; Function Prototype declaration
99 ----------------------------------------------------------------------------*/
100
101 /*----------------------------------------------------------------------------
102 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
103 ; Variable declaration - defined here and used outside this module
104 ----------------------------------------------------------------------------*/
105
106 /*----------------------------------------------------------------------------
107 ; EXTERNAL FUNCTION REFERENCES
108 ; Declare functions defined elsewhere and referenced in this module
109 ----------------------------------------------------------------------------*/
110
111 /*----------------------------------------------------------------------------
112 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
113 ; Declare variables used in this module but defined elsewhere
114 ----------------------------------------------------------------------------*/
115
116 /*----------------------------------------------------------------------------
117 ; FUNCTION CODE
118 ----------------------------------------------------------------------------*/
119
120 Word32 L_Comp(Word16 hi, Word16 lo, Flag *pOverflow)
121 {
122
123     /*----------------------------------------------------------------------------
124     ; Define all local variables
125     ----------------------------------------------------------------------------*/
126     Word32 L_32;
127     Word32 temp32;
128     /*----------------------------------------------------------------------------
129     ; Function body here
130     ----------------------------------------------------------------------------*/
131
132     L_32 = ((Word32)hi << 16);
133
134     temp32 = L_mac(L_32, lo, 1, pOverflow);
135     /*----------------------------------------------------------------------------
136     ; Return nothing or data or data pointer
137     ----------------------------------------------------------------------------*/
138
139     return (temp32);       /* = hi<<16 + lo<<1 */
140 }