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
32
33
34 Pathname: ./audio/gsm-amr/c/src/d2_9pf.c
35 Functions: decode_2i40_9bits
36
37 Date: 01/28/2002
38
39 ------------------------------------------------------------------------------
40 REVISION HISTORY
41
42 Description: Modified to place file in the correct template format. Eliminated
43 use of special functions to perform simple mathematical operations, where
44 possible. Added the parameter pOverflow for the basic math operations.
45
46 Description: Per review comments...
47 (1) Removed include of basic_op.h, replaced with shl.h
48 (2) Added pOverflow to the output section of the template
49
50 Description: Replaced "int" and/or "char" with OSCL defined types.
51
52 Description: Added #ifdef __cplusplus around extern'ed table.
53
54 Description:
55
56 ------------------------------------------------------------------------------
57 MODULE DESCRIPTION
58
59
60 FUNCTION: decode_2i40_9bits (decod_ACELP())
61
62 PURPOSE: Algebraic codebook decoder. For details about the encoding see
63 c2_9pf.c
64 */
65
66 /*----------------------------------------------------------------------------
67 ; INCLUDES
68 ----------------------------------------------------------------------------*/
69 #include "d2_9pf.h"
70 #include "typedef.h"
71 #include "basic_op.h"
72 #include "cnst.h"
73
74
75 /*--------------------------------------------------------------------------*/
76 #ifdef __cplusplus
77 extern "C"
78 {
79 #endif
80
81 /*----------------------------------------------------------------------------
82 ; MACROS
83 ; Define module specific macros here
84 ----------------------------------------------------------------------------*/
85
86 /*----------------------------------------------------------------------------
87 ; DEFINES
88 ; Include all pre-processor statements here. Include conditional
89 ; compile variables also.
90 ----------------------------------------------------------------------------*/
91 #define NB_PULSE 2
92
93
94 /*----------------------------------------------------------------------------
95 ; LOCAL FUNCTION DEFINITIONS
96 ; Function Prototype declaration
97 ----------------------------------------------------------------------------*/
98
99 /*----------------------------------------------------------------------------
100 ; LOCAL VARIABLE DEFINITIONS
101 ; Variable declaration - defined here and used outside this module
102 ----------------------------------------------------------------------------*/
103
104 extern const Word16 startPos[];
105
106 /*--------------------------------------------------------------------------*/
107 #ifdef __cplusplus
108 }
109 #endif
110
111 /*
112 ------------------------------------------------------------------------------
113 FUNCTION NAME: decode_2i40_11bits
114 ------------------------------------------------------------------------------
115 INPUT AND OUTPUT DEFINITIONS
116
117 Inputs:
118 sign -- Word16 -- signs of 2 pulses.
119 index -- Word16 -- Positions of the 2 pulses.
120
121 Outputs:
122 cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
123 pOverflow = pointer to overflow flag
124
125 Returns:
126 None
127
128 Global Variables Used:
129 None
130
131 Local Variables Needed:
132 None
133
134 ------------------------------------------------------------------------------
135 FUNCTION DESCRIPTION
136
137
138 ------------------------------------------------------------------------------
139 REQUIREMENTS
140
141 None
142
143 ------------------------------------------------------------------------------
144 REFERENCES
145
146 d2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
147
148 ------------------------------------------------------------------------------
149 PSEUDO-CODE
150
151
152 ------------------------------------------------------------------------------
153 RESOURCES USED [optional]
154
155 When the code is written for a specific target processor the
156 the resources used should be documented below.
157
158 HEAP MEMORY USED: x bytes
159
160 STACK MEMORY USED: x bytes
161
162 CLOCK CYCLES: (cycle count equation for this function) + (variable
163 used to represent cycle count for each subroutine
164 called)
165 where: (cycle count variable) = cycle count for [subroutine
166 name]
167
168 ------------------------------------------------------------------------------
169 CAUTION [optional]
170 [State any special notes, constraints or cautions for users of this function]
171
172 ------------------------------------------------------------------------------
173 */
174
decode_2i40_9bits(Word16 subNr,Word16 sign,Word16 index,Word16 cod[],Flag * pOverflow)175 void decode_2i40_9bits(
176 Word16 subNr, /* i : subframe number */
177 Word16 sign, /* i : signs of 2 pulses. */
178 Word16 index, /* i : Positions of the 2 pulses. */
179 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
180 Flag *pOverflow /* o : Flag set when overflow occurs */
181 )
182 {
183 Word16 i;
184 Word16 j;
185 Word16 k;
186
187 Word16 pos[NB_PULSE];
188
189 /* Decode the positions */
190 /* table bit is the MSB */
191
192 j = (Word16)(index & 64);
193
194 j >>= 3;
195
196 i = index & 7;
197
198 k =
199 shl(
200 subNr,
201 1,
202 pOverflow);
203
204 k += j;
205
206 /* pos0 =i*5+startPos[j*8+subNr*2] */
207 pos[0] = i * 5 + startPos[k++];
208
209
210 index >>= 3;
211
212 i = index & 7;
213
214 /* pos1 =i*5+startPos[j*8+subNr*2 + 1] */
215 pos[1] = i * 5 + startPos[k];
216
217
218 /* decode the signs and build the codeword */
219
220 for (i = L_SUBFR - 1; i >= 0; i--)
221 {
222 cod[i] = 0;
223 }
224
225 for (j = 0; j < NB_PULSE; j++)
226 {
227 i = sign & 0x1;
228
229 /* This line is equivalent to...
230 *
231 *
232 * if (i == 1)
233 * {
234 * cod[pos[j]] = 8191;
235 * }
236 * if (i == 0)
237 * {
238 * cod[pos[j]] = -8192;
239 * }
240 */
241
242 cod[pos[j]] = i * 16383 - 8192;
243
244 sign >>= 1;
245 }
246
247 return;
248 }
249