log2.cpp revision 4f1efc098cb5791c3e9f483f2af84aef70d2d0a0
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/****************************************************************************************
19Portions 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)
26Permission to distribute, modify and use this file under the standard license
27terms listed above has been obtained from the copyright holder.
28****************************************************************************************/
29/*
30 Filename: /audio/gsm_amr/c/src/log2.c
31
32------------------------------------------------------------------------------
33 REVISION HISTORY
34
35 Description: Updated template used to PV coding template. Moved Log2_norm
36          function to its own file.
37
38 Description: Changed l_shl.c to l_shl.h in Include section.
39
40 Description: Updated template. Changed function interface to pass in a
41              pointer to overflow flag into the function instead of using a
42              global flag. Changed input pointer names for clarity.
43
44 Description:
45              1. Eliminated l_shl function knowing that after normalization
46                 the left shift factor will not saturate.
47              2. Eliminated unused include files typedef.h and l_shl.h.
48
49
50 Who:                       Date:
51 Description:
52
53------------------------------------------------------------------------------
54*/
55
56/*----------------------------------------------------------------------------
57; INCLUDES
58----------------------------------------------------------------------------*/
59#include "log2.h"
60#include "basic_op.h"
61#include "log2_norm.h"
62
63/*----------------------------------------------------------------------------
64; MACROS
65; [Define module specific macros here]
66----------------------------------------------------------------------------*/
67
68/*----------------------------------------------------------------------------
69; DEFINES
70; [Include all pre-processor statements here. Include conditional
71; compile variables also.]
72----------------------------------------------------------------------------*/
73
74/*----------------------------------------------------------------------------
75; LOCAL FUNCTION DEFINITIONS
76; [List function prototypes here]
77----------------------------------------------------------------------------*/
78
79/*----------------------------------------------------------------------------
80; LOCAL VARIABLE DEFINITIONS
81; [Variable declaration - defined here and used outside this module]
82----------------------------------------------------------------------------*/
83
84
85/*
86------------------------------------------------------------------------------
87 FUNCTION NAME: log2()
88------------------------------------------------------------------------------
89 INPUT AND OUTPUT DEFINITIONS
90
91 Inputs:
92    L_x = input value of type Word32
93    pExponent = pointer to the integer part of Log2 of type Word16 whose
94           valid range is: 0 <= value <= 30
95    pFraction = pointer to the fractional part of Log2 of type Word16
96           whose valid range is: 0 <= value < 1
97    pOverflow = pointer to overflow flag
98
99
100 Outputs:
101    pExponent -> integer part of the newly calculated Log2
102    pFraction -> fractional part of the newly calculated Log2
103    pOverflow -> 1 if the log2() operation resulted in saturation
104
105 Returns:
106    None
107
108 Global Variables Used:
109    None
110
111 Local Variables Needed:
112    None
113
114------------------------------------------------------------------------------
115 FUNCTION DESCRIPTION
116
117 This function computes logarithm (base2) of the input L_x, where L_x is
118 positive. If L_x is negative or zero, the result is 0.
119
120 This function first normalizes the input L_x and calls the function Log2_norm
121 to calculate the logarithm.
122
123------------------------------------------------------------------------------
124 REQUIREMENTS
125
126 None
127
128------------------------------------------------------------------------------
129 REFERENCES
130
131 [1] log2.c,  UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
132
133------------------------------------------------------------------------------
134 PSEUDO-CODE
135
136
137------------------------------------------------------------------------------
138 RESOURCES USED [optional]
139
140 When the code is written for a specific target processor the
141 the resources used should be documented below.
142
143 HEAP MEMORY USED: x bytes
144
145 STACK MEMORY USED: x bytes
146
147 CLOCK CYCLES: (cycle count equation for this function) + (variable
148                used to represent cycle count for each subroutine
149                called)
150     where: (cycle count variable) = cycle count for [subroutine
151                                     name]
152
153------------------------------------------------------------------------------
154 CAUTION [optional]
155 [State any special notes, constraints or cautions for users of this function]
156
157------------------------------------------------------------------------------
158*/
159
160/*----------------------------------------------------------------------------
161; FUNCTION CODE
162----------------------------------------------------------------------------*/
163void Log2(
164    Word32 L_x,         /* (i) : input value                                */
165    Word16 *pExponent,  /* (o) : Integer part of Log2.   (range: 0<=val<=30)*/
166    Word16 *pFraction,  /* (o) : Fractional part of Log2. (range: 0<=val<1) */
167    Flag   *pOverflow   /* (i/o) : overflow flag                            */
168)
169{
170    Word16 exp;
171    Word32 result;
172    OSCL_UNUSED_ARG(pOverflow);
173
174    exp = norm_l(L_x);
175    result = L_x << exp;
176    Log2_norm(result, exp, pExponent, pFraction);
177
178    return;
179}
180