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 Filename: d2_9pf.cpp
35 Functions: decode_2i40_9bits
36
37 ------------------------------------------------------------------------------
38 MODULE DESCRIPTION
39
40
41 FUNCTION: decode_2i40_9bits (decod_ACELP())
42
43 PURPOSE: Algebraic codebook decoder. For details about the encoding see
44 c2_9pf.c
45 */
46
47 /*----------------------------------------------------------------------------
48 ; INCLUDES
49 ----------------------------------------------------------------------------*/
50 #include "d2_9pf.h"
51 #include "typedef.h"
52 #include "basic_op.h"
53 #include "cnst.h"
54
55
56 /*--------------------------------------------------------------------------*/
57 #ifdef __cplusplus
58 extern "C"
59 {
60 #endif
61
62 /*----------------------------------------------------------------------------
63 ; MACROS
64 ; Define module specific macros here
65 ----------------------------------------------------------------------------*/
66
67 /*----------------------------------------------------------------------------
68 ; DEFINES
69 ; Include all pre-processor statements here. Include conditional
70 ; compile variables also.
71 ----------------------------------------------------------------------------*/
72 #define NB_PULSE 2
73
74
75 /*----------------------------------------------------------------------------
76 ; LOCAL FUNCTION DEFINITIONS
77 ; Function Prototype declaration
78 ----------------------------------------------------------------------------*/
79
80 /*----------------------------------------------------------------------------
81 ; LOCAL VARIABLE DEFINITIONS
82 ; Variable declaration - defined here and used outside this module
83 ----------------------------------------------------------------------------*/
84
85 /*--------------------------------------------------------------------------*/
86 #ifdef __cplusplus
87 }
88 #endif
89
90 /*
91 ------------------------------------------------------------------------------
92 FUNCTION NAME: decode_2i40_11bits
93 ------------------------------------------------------------------------------
94 INPUT AND OUTPUT DEFINITIONS
95
96 Inputs:
97 sign -- Word16 -- signs of 2 pulses.
98 index -- Word16 -- Positions of the 2 pulses.
99
100 Outputs:
101 cod[] -- array of type Word16 -- algebraic (fixed) codebook excitation
102 pOverflow = pointer to overflow flag
103
104 Returns:
105 None
106
107 Global Variables Used:
108 None
109
110 Local Variables Needed:
111 None
112
113 ------------------------------------------------------------------------------
114 FUNCTION DESCRIPTION
115
116
117 ------------------------------------------------------------------------------
118 REQUIREMENTS
119
120 None
121
122 ------------------------------------------------------------------------------
123 REFERENCES
124
125 d2_9pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
126
127 ------------------------------------------------------------------------------
128 PSEUDO-CODE
129
130
131 ------------------------------------------------------------------------------
132 CAUTION [optional]
133 [State any special notes, constraints or cautions for users of this function]
134
135 ------------------------------------------------------------------------------
136 */
137
decode_2i40_9bits(Word16 subNr,Word16 sign,Word16 index,const Word16 * startPos_ptr,Word16 cod[],Flag * pOverflow)138 void decode_2i40_9bits(
139 Word16 subNr, /* i : subframe number */
140 Word16 sign, /* i : signs of 2 pulses. */
141 Word16 index, /* i : Positions of the 2 pulses. */
142 const Word16* startPos_ptr, /* i: ptr to read only table */
143 Word16 cod[], /* o : algebraic (fixed) codebook excitation */
144 Flag *pOverflow /* o : Flag set when overflow occurs */
145 )
146 {
147 Word16 i;
148 Word16 j;
149 Word16 k;
150
151 Word16 pos[NB_PULSE];
152
153 /* Decode the positions */
154 /* table bit is the MSB */
155
156 j = (Word16)(index & 64);
157
158 j >>= 3;
159
160 i = index & 7;
161
162 k =
163 shl(
164 subNr,
165 1,
166 pOverflow);
167
168 k += j;
169
170 /* pos0 =i*5+startPos_ptr[j*8+subNr*2] */
171 pos[0] = i * 5 + startPos_ptr[k++];
172
173
174 index >>= 3;
175
176 i = index & 7;
177
178 /* pos1 =i*5+startPos_ptr[j*8+subNr*2 + 1] */
179 pos[1] = i * 5 + startPos_ptr[k];
180
181
182 /* decode the signs and build the codeword */
183
184 for (i = L_SUBFR - 1; i >= 0; i--)
185 {
186 cod[i] = 0;
187 }
188
189 for (j = 0; j < NB_PULSE; j++)
190 {
191 i = sign & 0x1;
192
193 /* This line is equivalent to...
194 *
195 *
196 * if (i == 1)
197 * {
198 * cod[pos[j]] = 8191;
199 * }
200 * if (i == 0)
201 * {
202 * cod[pos[j]] = -8192;
203 * }
204 */
205
206 cod[pos[j]] = i * 16383 - 8192;
207
208 sign >>= 1;
209 }
210
211 return;
212 }
213