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: d1035pf.cpp
35
36 ------------------------------------------------------------------------------
37 */
38
39 /*----------------------------------------------------------------------------
40 ; INCLUDES
41 ----------------------------------------------------------------------------*/
42 #include "d1035pf.h"
43 #include "typedef.h"
44 #include "basic_op.h"
45 #include "cnst.h"
46
47 /*----------------------------------------------------------------------------
48 ; MACROS
49 ; Define module specific macros here
strip_trailoptnull50 ----------------------------------------------------------------------------*/
51
52 /*----------------------------------------------------------------------------
53 ; DEFINES
54 ; Include all pre-processor statements here. Include conditional
55 ; compile variables also.
56 ----------------------------------------------------------------------------*/
57 #define NB_PULSE 10 /* number of pulses */
58
59 /*----------------------------------------------------------------------------
60 ; LOCAL FUNCTION DEFINITIONS
61 ; Function Prototype declaration
62 ----------------------------------------------------------------------------*/
63
64 /*----------------------------------------------------------------------------
65 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
66 ; Variable declaration - defined here and used outside this module
67 ----------------------------------------------------------------------------*/
68
69 /*
70 ------------------------------------------------------------------------------
71 FUNCTION NAME: dec_10i40_35bits
72 ------------------------------------------------------------------------------
73 INPUT AND OUTPUT DEFINITIONS
74
75 Inputs:
76 index = buffer containing index of 10 pulses; each element is
77 represented by sign+position
78 cod = buffer of algebraic (fixed) codebook excitation
79
80 Outputs:
81 cod buffer contains the new algebraic codebook excitation
82
83 Returns:
84 None
85
86 Global Variables Used:
87 dgray = gray decoding table
88
89 Local Variables Needed:
90 None
91
92 ------------------------------------------------------------------------------
93 FUNCTION DESCRIPTION
94
95 This function builds the innovative codevector from the received index of
96 algebraic codebook. See c1035pf.c for more details about the algebraic
97 codebook structure.
98
99 ------------------------------------------------------------------------------
100 REQUIREMENTS
101
102 None
103
104 ------------------------------------------------------------------------------
105 REFERENCES
106
107 d1035pf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
108
109 ------------------------------------------------------------------------------
110 PSEUDO-CODE
111
112 void dec_10i40_35bits (
113 Word16 index[], // (i) : index of 10 pulses (sign+position)
114 Word16 cod[] // (o) : algebraic (fixed) codebook excitation
115 )
116 {
117 Word16 i, j, pos1, pos2, sign, tmp;
118
119 for (i = 0; i < L_CODE; i++)
120 {
121 cod[i] = 0;
122 }
123
124 // decode the positions and signs of pulses and build the codeword
125
126 for (j = 0; j < NB_TRACK; j++)
127 {
128 // compute index i
129
130 tmp = index[j];
131 i = tmp & 7;
132 i = dgray[i];
133
134 i = extract_l (L_shr (L_mult (i, 5), 1));
135 pos1 = add (i, j); // position of pulse "j"
136
137 i = shr (tmp, 3) & 1;
138 if (i == 0)
139 {
140 sign = 4096; // +1.0
141 }
142 else
143 {
144 sign = -4096; // -1.0
145 }
146
147 cod[pos1] = sign;
148
149 // compute index i
150
151 i = index[add (j, 5)] & 7;
152 i = dgray[i];
153 i = extract_l (L_shr (L_mult (i, 5), 1));
154
155 pos2 = add (i, j); // position of pulse "j+5"
156
157 if (sub (pos2, pos1) < 0)
158 {
159 sign = negate (sign);
160 }
161 cod[pos2] = add (cod[pos2], sign);
162 }
163
164 return;
165 }
166
167 ------------------------------------------------------------------------------
168 CAUTION [optional]
169 [State any special notes, constraints or cautions for users of this function]
170
171 ------------------------------------------------------------------------------
172 */
173
174 void dec_10i40_35bits(
175 Word16 index[], /* (i) : index of 10 pulses (sign+position) */
176 Word16 cod[], /* (o) : algebraic (fixed) codebook excitation */
177 const Word16* dgray_ptr /* i : ptr to read-only tbl */
178 )
179 {
180 register Word16 i, j, pos1, pos2;
181 Word16 sign, tmp;
182
183 for (i = 0; i < L_CODE; i++)
184 {
185 *(cod + i) = 0;
186 }
187
188 /* decode the positions and signs of pulses and build the codeword */
189
190 for (j = 0; j < NB_TRACK; j++)
191 {
192 /* compute index i */
193
194 tmp = *(index + j);
195 i = tmp & 7;
196 i = *(dgray_ptr + i);
197
198 i = (Word16)(i * 5);
199 pos1 = i + j; /* position of pulse "j" */
200
201 i = (tmp >> 3) & 1;
202
203 if (i == 0)
204 {
205 sign = 4096; /* +1.0 */
206 }
207 else
208 {
209 sign = -4096; /* -1.0 */
210 }
211
212 *(cod + pos1) = sign;
213
214 /* compute index i */
215
216 i = *(index + j + 5) & 7;
217 i = *(dgray_ptr + i);
218 i = (Word16)(i * 5);
219
220 pos2 = i + j; /* position of pulse "j+5" */
221
222
223 if (pos2 < pos1)
224 {
225 sign = negate(sign);
226 }
227 *(cod + pos2) += sign;
228 }
229
230 return;
231 }
232