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 Filename: /audio/gsm_amr/c/src/bits2prm.c
32
33 ------------------------------------------------------------------------------
34 REVISION HISTORY
35
36 Description: Fixed a typo in the include section. Optimized some lines of
37 code as per review comments.
38
39 Description: Replaced "int" and/or "char" with OSCL defined types.
40
41 Who: Date:
42 Description:
43
44 ------------------------------------------------------------------------------
45 */
46
47 /*----------------------------------------------------------------------------
48 ; INCLUDES
49 ----------------------------------------------------------------------------*/
50 #include "bits2prm.h"
51 #include "typedef.h"
52 #include "mode.h"
53 #include "bitno_tab.h"
54
55 /*----------------------------------------------------------------------------
56 ; MACROS
57 ; [Define module specific macros here]
58 ----------------------------------------------------------------------------*/
59
60 /*----------------------------------------------------------------------------
61 ; DEFINES
62 ; [Include all pre-processor statements here. Include conditional
63 ; compile variables also.]
64 ----------------------------------------------------------------------------*/
65
66 /*----------------------------------------------------------------------------
67 ; LOCAL FUNCTION DEFINITIONS
68 ; [List function prototypes here]
69 ----------------------------------------------------------------------------*/
70
71 /*----------------------------------------------------------------------------
72 ; LOCAL VARIABLE DEFINITIONS
73 ; [Variable declaration - defined here and used outside this module]
74 ----------------------------------------------------------------------------*/
75
76 /*
77 ------------------------------------------------------------------------------
78 FUNCTION NAME: Bin2int
79 ------------------------------------------------------------------------------
80 INPUT AND OUTPUT DEFINITIONS
81
82 Inputs:
83 no_of_bits = number of bits associated with value
84 bitstream = pointer to buffer where bits are read
85
86 Outputs:
87 None
88
89 Returns:
90 None
91
92 Global Variables Used:
93 None
94
95 Local Variables Needed:
96 None
97
98 ------------------------------------------------------------------------------
99 FUNCTION DESCRIPTION
100
101 Function : Bin2int
102 Purpose : Read "no_of_bits" bits from the array bitstream[]
103 and convert to integer.
104
105 ------------------------------------------------------------------------------
106 REQUIREMENTS
107
108 None
109
110 ------------------------------------------------------------------------------
111 REFERENCES
112
113 bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
114
115 ------------------------------------------------------------------------------
116 PSEUDO-CODE
117
118 static Word16 Bin2int ( // Reconstructed parameter
119 Word16 no_of_bits, // input : number of bits associated with value
120 Word16 *bitstream // output: address where bits are written
121 )
122 {
123 Word16 value, i, bit;
124
125 value = 0;
126 for (i = 0; i < no_of_bits; i++)
127 {
128 value = shl (value, 1);
129 bit = *bitstream++;
130 if (sub (bit, BIT_1) == 0)
131 value = add (value, 1);
132 }
133 return (value);
134 }
135
136 ------------------------------------------------------------------------------
137 RESOURCES USED [optional]
138
139 When the code is written for a specific target processor the
140 the resources used should be documented below.
141
142 HEAP MEMORY USED: x bytes
143
144 STACK MEMORY USED: x bytes
145
146 CLOCK CYCLES: (cycle count equation for this function) + (variable
147 used to represent cycle count for each subroutine
148 called)
149 where: (cycle count variable) = cycle count for [subroutine
150 name]
151
152 ------------------------------------------------------------------------------
153 CAUTION [optional]
154 [State any special notes, constraints or cautions for users of this function]
155
156 ------------------------------------------------------------------------------
157 */
158
159 /*----------------------------------------------------------------------------
160 ; FUNCTION CODE
161 ----------------------------------------------------------------------------*/
Bin2int(Word16 no_of_bits,Word16 * bitstream)162 static Word16 Bin2int( /* Reconstructed parameter */
163 Word16 no_of_bits, /* input : number of bits associated with value */
164 Word16 *bitstream /* input: address where bits are read from */
165 )
166 {
167 Word16 value;
168 Word16 i;
169 Word16 single_bit;
170
171 value = 0;
172 for (i = 0; i < no_of_bits; i++)
173 {
174 value <<= 1;
175 single_bit = *(bitstream++);
176 value |= single_bit;
177 }
178 return (value);
179 }
180
181
182 /*
183 ------------------------------------------------------------------------------
184 FUNCTION NAME: bits2prm
185 ------------------------------------------------------------------------------
186 INPUT AND OUTPUT DEFINITIONS
187
188 Inputs:
189 mode = AMR mode of type enum Mode
190 bits[] = pointer to serial bits of type Word16
191 prm[] = pointer to analysis parameters of type Word16
192
193 Outputs:
194 None
195
196 Returns:
197 None
198
199 Global Variables Used:
200 None
201
202 Local Variables Needed:
203 None
204
205 ------------------------------------------------------------------------------
206 FUNCTION DESCRIPTION
207
208 Function : Bits2prm
209 Purpose : Retrieves the vector of encoder parameters from
210 the received serial bits in a frame.
211
212 ------------------------------------------------------------------------------
213 REQUIREMENTS
214
215 None
216
217 ------------------------------------------------------------------------------
218 REFERENCES
219
220 bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
221
222 ------------------------------------------------------------------------------
223 PSEUDO-CODE
224
225 void Bits2prm (
226 enum Mode mode, // i : AMR mode
227 Word16 bits[], // i : serial bits (size <= MAX_SERIAL_SIZE)
228 Word16 prm[] // o : analysis parameters (size <= MAX_PRM_SIZE)
229 )
230 {
231 Word16 i;
232
233 for (i = 0; i < prmno[mode]; i++)
234 {
235 prm[i] = Bin2int (bitno[mode][i], bits);
236 bits += bitno[mode][i];
237 add(0,0); // account for above pointer update
238 }
239
240 return;
241 }
242
243 ------------------------------------------------------------------------------
244 RESOURCES USED [optional]
245
246 When the code is written for a specific target processor the
247 the resources used should be documented below.
248
249 HEAP MEMORY USED: x bytes
250
251 STACK MEMORY USED: x bytes
252
253 CLOCK CYCLES: (cycle count equation for this function) + (variable
254 used to represent cycle count for each subroutine
255 called)
256 where: (cycle count variable) = cycle count for [subroutine
257 name]
258
259 ------------------------------------------------------------------------------
260 CAUTION [optional]
261 [State any special notes, constraints or cautions for users of this function]
262
263 ------------------------------------------------------------------------------
264 */
265
266 /*----------------------------------------------------------------------------
267 ; FUNCTION CODE
268 ----------------------------------------------------------------------------*/
Bits2prm(enum Mode mode,Word16 bits[],Word16 prm[])269 OSCL_EXPORT_REF void Bits2prm(
270 enum Mode mode, /* i : AMR mode */
271 Word16 bits[], /* i : serial bits (size <= MAX_SERIAL_SIZE) */
272 Word16 prm[] /* o : analysis parameters (size <= MAX_PRM_SIZE) */
273 )
274 {
275 Word16 i;
276
277 for (i = 0; i < prmno[mode]; i++)
278 {
279 prm[i] = Bin2int(bitno[mode][i], bits);
280 bits += bitno[mode][i];
281 }
282
283 return;
284 }
285
286
287
288
289
290
291
292
293