Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / bits2prm.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
31  Filename: bits2prm.cpp
32
33 ------------------------------------------------------------------------------
34 */
35
36 /*----------------------------------------------------------------------------
37 ; INCLUDES
38 ----------------------------------------------------------------------------*/
39 #include "bits2prm.h"
40 #include "typedef.h"
41 #include "mode.h"
42 #include "bitno_tab.h"
43
44 /*----------------------------------------------------------------------------
45 ; MACROS
46 ; [Define module specific macros here]
47 ----------------------------------------------------------------------------*/
48
49 /*----------------------------------------------------------------------------
50 ; DEFINES
51 ; [Include all pre-processor statements here. Include conditional
52 ; compile variables also.]
53 ----------------------------------------------------------------------------*/
54
55 /*----------------------------------------------------------------------------
56 ; LOCAL FUNCTION DEFINITIONS
57 ; [List function prototypes here]
58 ----------------------------------------------------------------------------*/
59
60 /*----------------------------------------------------------------------------
61 ; LOCAL VARIABLE DEFINITIONS
62 ; [Variable declaration - defined here and used outside this module]
63 ----------------------------------------------------------------------------*/
64
65 /*
66 ------------------------------------------------------------------------------
67  FUNCTION NAME: Bin2int
68 ------------------------------------------------------------------------------
69  INPUT AND OUTPUT DEFINITIONS
70
71  Inputs:
72     no_of_bits = number of bits associated with value
73     bitstream = pointer to buffer where bits are read
74
75  Outputs:
76     None
77
78  Returns:
79     None
80
81  Global Variables Used:
82     None
83
84  Local Variables Needed:
85     None
86
87 ------------------------------------------------------------------------------
88  FUNCTION DESCRIPTION
89
90   Function    : Bin2int
91   Purpose     : Read "no_of_bits" bits from the array bitstream[]
92                 and convert to integer.
93
94 ------------------------------------------------------------------------------
95  REQUIREMENTS
96
97  None
98
99 ------------------------------------------------------------------------------
100  REFERENCES
101
102  bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
103
104 ------------------------------------------------------------------------------
105  PSEUDO-CODE
106
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
110 )
111 {
112     Word16 value, i, bit;
113
114     value = 0;
115     for (i = 0; i < no_of_bits; i++)
116     {
117         value = shl (value, 1);
118         bit = *bitstream++;
119         if (sub (bit, BIT_1) == 0)
120             value = add (value, 1);
121     }
122     return (value);
123 }
124
125 ------------------------------------------------------------------------------
126  CAUTION [optional]
127  [State any special notes, constraints or cautions for users of this function]
128
129 ------------------------------------------------------------------------------
130 */
131
132 /*----------------------------------------------------------------------------
133 ; FUNCTION CODE
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      */
138 )
139 {
140     Word16 value;
141     Word16 i;
142     Word16 single_bit;
143
144     value = 0;
145     for (i = 0; i < no_of_bits; i++)
146     {
147         value <<= 1;
148         single_bit = *(bitstream++);
149         value |= single_bit;
150     }
151     return (value);
152 }
153
154
155 /*
156 ------------------------------------------------------------------------------
157  FUNCTION NAME: bits2prm
158 ------------------------------------------------------------------------------
159  INPUT AND OUTPUT DEFINITIONS
160
161  Inputs:
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
165
166  Outputs:
167     None
168
169  Returns:
170     None
171
172  Global Variables Used:
173     None
174
175  Local Variables Needed:
176     None
177
178 ------------------------------------------------------------------------------
179  FUNCTION DESCRIPTION
180
181   Function    : Bits2prm
182   Purpose     : Retrieves the vector of encoder parameters from
183                 the received serial bits in a frame.
184
185 ------------------------------------------------------------------------------
186  REQUIREMENTS
187
188  None
189
190 ------------------------------------------------------------------------------
191  REFERENCES
192
193  bits2prm.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
194
195 ------------------------------------------------------------------------------
196  PSEUDO-CODE
197
198 void Bits2prm (
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)
202 )
203 {
204     Word16 i;
205
206     for (i = 0; i < prmno[mode]; i++)
207     {
208         prm[i] = Bin2int (bitno[mode][i], bits);
209         bits += bitno[mode][i];
210         add(0,0);       // account for above pointer update
211     }
212
213    return;
214 }
215
216 ------------------------------------------------------------------------------
217  CAUTION [optional]
218  [State any special notes, constraints or cautions for users of this function]
219
220 ------------------------------------------------------------------------------
221 */
222
223 /*----------------------------------------------------------------------------
224 ; FUNCTION CODE
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) */
230 )
231 {
232     Word16 i;
233
234     for (i = 0; i < prmno[mode]; i++)
235     {
236         prm[i] = Bin2int(bitno[mode][i], bits);
237         bits += bitno[mode][i];
238     }
239
240     return;
241 }
242
243
244
245
246
247
248
249