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 ****************************************************************************************/
34 Filename: prm2bits.cpp
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------
48 ; [Define module specific macros here]
49 ----------------------------------------------------------------------------*/
51 /*----------------------------------------------------------------------------
53 ; [Include all pre-processor statements here. Include conditional
54 ; compile variables also.]
55 ----------------------------------------------------------------------------*/
57 /*----------------------------------------------------------------------------
58 ; LOCAL FUNCTION DEFINITIONS
59 ; [List function prototypes here]
60 ----------------------------------------------------------------------------*/
62 /*----------------------------------------------------------------------------
63 ; LOCAL VARIABLE DEFINITIONS
64 ; [Variable declaration - defined here and used outside this module]
65 ----------------------------------------------------------------------------*/
68 ------------------------------------------------------------------------------
69 FUNCTION NAME: Int2bin
70 ------------------------------------------------------------------------------
71 INPUT AND OUTPUT DEFINITIONS
74 value = value to be converted to binary of type Word16
75 no_of_bits = number of bits associated with value of type Word16
78 bitstream = pointer to address where bits are written of type Word16
83 Global Variables Used:
86 Local Variables Needed:
89 ------------------------------------------------------------------------------
94 PURPOSE: convert integer to binary and write the bits to the array
95 bitstream[]. The most significant bits are written first.
97 ------------------------------------------------------------------------------
102 ------------------------------------------------------------------------------
105 prm2bits.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
107 ------------------------------------------------------------------------------
110 static void Int2bin (
111 Word16 value, // input : value to be converted to binary
112 Word16 no_of_bits, // input : number of bits associated with value
113 Word16 *bitstream // output: address where bits are written
116 Word16 *pt_bitstream, i, bit;
118 pt_bitstream = &bitstream[no_of_bits];
120 for (i = 0; i < no_of_bits; i++)
125 *--pt_bitstream = BIT_0;
129 *--pt_bitstream = BIT_1;
131 value = shr (value, 1);
135 ------------------------------------------------------------------------------
137 [State any special notes, constraints or cautions for users of this function]
139 ------------------------------------------------------------------------------
142 /*----------------------------------------------------------------------------
144 ----------------------------------------------------------------------------*/
146 Word16 value, /* input : value to be converted to binary */
147 Word16 no_of_bits, /* input : number of bits associated with value */
148 Word16 *bitstream /* output: address where bits are written */
151 Word16 *pt_bitstream;
154 pt_bitstream = &bitstream[no_of_bits-1];
156 for (i = no_of_bits; i != 0; i--)
158 *(pt_bitstream--) = value & MASK;
166 ------------------------------------------------------------------------------
167 FUNCTION NAME: prm2bits
168 ------------------------------------------------------------------------------
169 INPUT AND OUTPUT DEFINITIONS
172 mode = AMR mode of type enum Mode
173 prm[] = pointer to analysis parameters of type Word16
176 bits[] = pointer to serial bits of type Word16
181 Global Variables Used:
184 Local Variables Needed:
187 ------------------------------------------------------------------------------
192 PURPOSE: converts the encoder parameter vector into a vector of serial
195 DESCRIPTION: depending on the mode, different numbers of parameters
196 (with differing numbers of bits) are processed. Details
197 are found in bitno.tab
199 ------------------------------------------------------------------------------
204 ------------------------------------------------------------------------------
207 prm2bits.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
209 ------------------------------------------------------------------------------
213 enum Mode mode, // i : AMR mode
214 Word16 prm[], // i : analysis parameters (size <= MAX_PRM_SIZE)
215 Word16 bits[] // o : serial bits (size <= MAX_SERIAL_SIZE)
220 for (i = 0; i < prmno[mode]; i++)
222 Int2bin (prm[i], bitno[mode][i], bits);
223 bits += bitno[mode][i];
224 add(0,0); // account for above pointer update
230 ------------------------------------------------------------------------------
232 [State any special notes, constraints or cautions for users of this function]
234 ------------------------------------------------------------------------------
237 /*----------------------------------------------------------------------------
239 ----------------------------------------------------------------------------*/
241 enum Mode mode, /* i : AMR mode */
242 Word16 prm[], /* i : analysis parameters (size <= MAX_PRM_SIZE) */
243 Word16 bits[], /* o : serial bits (size <= MAX_SERIAL_SIZE) */
244 CommonAmrTbls* common_amr_tbls /* i : ptr to strcut of table ptrs */
248 const Word16 *p_mode;
250 const Word16* prmno_ptr = common_amr_tbls->prmno_ptr;
252 p_mode = &common_amr_tbls->bitno_ptr[mode][0];
255 for (i = prmno_ptr[mode]; i != 0; i--)
257 Int2bin(*(p_prm++), *(p_mode), bits);