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 ****************************************************************************************/
31 Filename: bits2prm.cpp
33 ------------------------------------------------------------------------------
36 /*----------------------------------------------------------------------------
38 ----------------------------------------------------------------------------*/
42 #include "bitno_tab.h"
44 /*----------------------------------------------------------------------------
46 ; [Define module specific macros here]
47 ----------------------------------------------------------------------------*/
49 /*----------------------------------------------------------------------------
51 ; [Include all pre-processor statements here. Include conditional
52 ; compile variables also.]
53 ----------------------------------------------------------------------------*/
55 /*----------------------------------------------------------------------------
56 ; LOCAL FUNCTION DEFINITIONS
57 ; [List function prototypes here]
58 ----------------------------------------------------------------------------*/
60 /*----------------------------------------------------------------------------
61 ; LOCAL VARIABLE DEFINITIONS
62 ; [Variable declaration - defined here and used outside this module]
63 ----------------------------------------------------------------------------*/
66 ------------------------------------------------------------------------------
67 FUNCTION NAME: Bin2int
68 ------------------------------------------------------------------------------
69 INPUT AND OUTPUT DEFINITIONS
72 no_of_bits = number of bits associated with value
73 bitstream = pointer to buffer where bits are read
81 Global Variables Used:
84 Local Variables Needed:
87 ------------------------------------------------------------------------------
91 Purpose : Read "no_of_bits" bits from the array bitstream[]
92 and convert to integer.
94 ------------------------------------------------------------------------------
99 ------------------------------------------------------------------------------
102 bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
104 ------------------------------------------------------------------------------
107 static Word16 Bin2int ( // Reconstructed parameter
108 Word16 no_of_bits, // input : number of bits associated with value
109 Word16 *bitstream // output: address where bits are written
112 Word16 value, i, bit;
115 for (i = 0; i < no_of_bits; i++)
117 value = shl (value, 1);
119 if (sub (bit, BIT_1) == 0)
120 value = add (value, 1);
125 ------------------------------------------------------------------------------
127 [State any special notes, constraints or cautions for users of this function]
129 ------------------------------------------------------------------------------
132 /*----------------------------------------------------------------------------
134 ----------------------------------------------------------------------------*/
135 static Word16 Bin2int( /* Reconstructed parameter */
136 Word16 no_of_bits, /* input : number of bits associated with value */
137 Word16 *bitstream /* input: address where bits are read from */
145 for (i = 0; i < no_of_bits; i++)
148 single_bit = *(bitstream++);
156 ------------------------------------------------------------------------------
157 FUNCTION NAME: bits2prm
158 ------------------------------------------------------------------------------
159 INPUT AND OUTPUT DEFINITIONS
162 mode = AMR mode of type enum Mode
163 bits[] = pointer to serial bits of type Word16
164 prm[] = pointer to analysis parameters of type Word16
172 Global Variables Used:
175 Local Variables Needed:
178 ------------------------------------------------------------------------------
182 Purpose : Retrieves the vector of encoder parameters from
183 the received serial bits in a frame.
185 ------------------------------------------------------------------------------
190 ------------------------------------------------------------------------------
193 bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
195 ------------------------------------------------------------------------------
199 enum Mode mode, // i : AMR mode
200 Word16 bits[], // i : serial bits (size <= MAX_SERIAL_SIZE)
201 Word16 prm[] // o : analysis parameters (size <= MAX_PRM_SIZE)
206 for (i = 0; i < prmno[mode]; i++)
208 prm[i] = Bin2int (bitno[mode][i], bits);
209 bits += bitno[mode][i];
210 add(0,0); // account for above pointer update
216 ------------------------------------------------------------------------------
218 [State any special notes, constraints or cautions for users of this function]
220 ------------------------------------------------------------------------------
223 /*----------------------------------------------------------------------------
225 ----------------------------------------------------------------------------*/
226 OSCL_EXPORT_REF void Bits2prm(
227 enum Mode mode, /* i : AMR mode */
228 Word16 bits[], /* i : serial bits (size <= MAX_SERIAL_SIZE) */
229 Word16 prm[] /* o : analysis parameters (size <= MAX_PRM_SIZE) */
234 for (i = 0; i < prmno[mode]; i++)
236 prm[i] = Bin2int(bitno[mode][i], bits);
237 bits += bitno[mode][i];