Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / log2.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  Filename: log2.cpp
31
32 ------------------------------------------------------------------------------
33 */
34
35 /*----------------------------------------------------------------------------
36 ; INCLUDES
37 ----------------------------------------------------------------------------*/
38 #include "log2.h"
39 #include "basic_op.h"
40 #include "log2_norm.h"
41
42 /*----------------------------------------------------------------------------
43 ; MACROS
44 ; [Define module specific macros here]
45 ----------------------------------------------------------------------------*/
46
47 /*----------------------------------------------------------------------------
48 ; DEFINES
49 ; [Include all pre-processor statements here. Include conditional
50 ; compile variables also.]
51 ----------------------------------------------------------------------------*/
52
53 /*----------------------------------------------------------------------------
54 ; LOCAL FUNCTION DEFINITIONS
55 ; [List function prototypes here]
56 ----------------------------------------------------------------------------*/
57
58 /*----------------------------------------------------------------------------
59 ; LOCAL VARIABLE DEFINITIONS
60 ; [Variable declaration - defined here and used outside this module]
61 ----------------------------------------------------------------------------*/
62
63
64 /*
65 ------------------------------------------------------------------------------
66  FUNCTION NAME: log2()
67 ------------------------------------------------------------------------------
68  INPUT AND OUTPUT DEFINITIONS
69
70  Inputs:
71     L_x = input value of type Word32
72     pExponent = pointer to the integer part of Log2 of type Word16 whose
73            valid range is: 0 <= value <= 30
74     pFraction = pointer to the fractional part of Log2 of type Word16
75            whose valid range is: 0 <= value < 1
76     pOverflow = pointer to overflow flag
77
78
79  Outputs:
80     pExponent -> integer part of the newly calculated Log2
81     pFraction -> fractional part of the newly calculated Log2
82     pOverflow -> 1 if the log2() operation resulted in saturation
83
84  Returns:
85     None
86
87  Global Variables Used:
88     None
89
90  Local Variables Needed:
91     None
92
93 ------------------------------------------------------------------------------
94  FUNCTION DESCRIPTION
95
96  This function computes logarithm (base2) of the input L_x, where L_x is
97  positive. If L_x is negative or zero, the result is 0.
98
99  This function first normalizes the input L_x and calls the function Log2_norm
100  to calculate the logarithm.
101
102 ------------------------------------------------------------------------------
103  REQUIREMENTS
104
105  None
106
107 ------------------------------------------------------------------------------
108  REFERENCES
109
110  [1] log2.c,  UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
111
112 ------------------------------------------------------------------------------
113  PSEUDO-CODE
114
115
116 ------------------------------------------------------------------------------
117  CAUTION [optional]
118  [State any special notes, constraints or cautions for users of this function]
119
120 ------------------------------------------------------------------------------
121 */
122
123 /*----------------------------------------------------------------------------
124 ; FUNCTION CODE
125 ----------------------------------------------------------------------------*/
126 OSCL_EXPORT_REF void Log2(
127     Word32 L_x,         /* (i) : input value                                */
128     Word16 *pExponent,  /* (o) : Integer part of Log2.   (range: 0<=val<=30)*/
129     Word16 *pFraction,  /* (o) : Fractional part of Log2. (range: 0<=val<1) */
130     Flag   *pOverflow   /* (i/o) : overflow flag                            */
131 )
132 {
133     Word16 exp;
134     Word32 result;
135     OSCL_UNUSED_ARG(pOverflow);
136
137     exp = norm_l(L_x);
138     result = L_x << exp;
139     Log2_norm(result, exp, pExponent, pFraction);
140
141     return;
142 }