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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: /audio/gsm-amr/c/src/a_refl.c
39 ------------------------------------------------------------------------------
42 Description: Removing unneeded include files and the goto statement.
45 Description: Changed function name to pv_round to avoid conflict with
46 round function in C standard library.
48 Description: Replaced "int" and/or "char" with OSCL defined types.
50 Description: Using inline functions from basic_op.h .
51 Removing unneeded include files.
55 ------------------------------------------------------------------------------
59 /*----------------------------------------------------------------------------
61 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
69 ; [Define module specific macros here]
70 ----------------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------------
74 ; [Include all pre-processor statements here. Include conditional
75 ; compile variables also.]
76 ----------------------------------------------------------------------------*/
78 /*----------------------------------------------------------------------------
79 ; LOCAL FUNCTION DEFINITIONS
80 ; [List function prototypes here]
81 ----------------------------------------------------------------------------*/
83 /*----------------------------------------------------------------------------
84 ; LOCAL VARIABLE DEFINITIONS
85 ; [Variable declaration - defined here and used outside this module]
86 ----------------------------------------------------------------------------*/
89 ------------------------------------------------------------------------------
90 FUNCTION NAME: AMREncode
91 ------------------------------------------------------------------------------
92 INPUT AND OUTPUT DEFINITIONS
95 a[] = pointer to directform coefficients of type Word16
96 refl[] = pointer to reflection coefficients of type Word16
99 pOverflow = 1 if overflow exists in the math operations else zero.
104 Global Variables Used:
107 Local Variables Needed:
110 ------------------------------------------------------------------------------
114 Purpose : Convert from direct form coefficients to
115 reflection coefficients
117 ------------------------------------------------------------------------------
122 ------------------------------------------------------------------------------
125 [1] a_refl.c , 3GPP TS 26.101 version 4.1.0 Release 4, June 2001
127 ------------------------------------------------------------------------------
132 Word16 a[], // i : Directform coefficients
133 Word16 refl[] // o : Reflection coefficients
149 for (i = 0; i < M; i++)
154 // backward Levinson recursion
155 for (i = M-1; i >= 0; i--)
157 if (sub(abs_s(aState[i]), 4096) >= 0)
162 refl[i] = shl(aState[i], 3);
164 L_temp = L_mult(refl[i], refl[i]);
165 L_acc = L_sub(MAX_32, L_temp);
167 normShift = norm_l(L_acc);
168 scale = sub(15, normShift);
170 L_acc = L_shl(L_acc, normShift);
171 normProd = pv_round(L_acc);
173 mult = div_s(16384, normProd);
175 for (j = 0; j < i; j++)
177 L_acc = L_deposit_h(aState[j]);
178 L_acc = L_msu(L_acc, refl[i], aState[i-j-1]);
180 temp = pv_round(L_acc);
181 L_temp = L_mult(mult, temp);
182 L_temp = L_shr_r(L_temp, scale);
184 if (L_sub(L_abs(L_temp), 32767) > 0)
189 bState[j] = extract_l(L_temp);
192 for (j = 0; j < i; j++)
194 aState[j] = bState[j];
200 for (i = 0; i < M; i++)
206 ------------------------------------------------------------------------------
207 RESOURCES USED [optional]
209 When the code is written for a specific target processor the
210 the resources used should be documented below.
212 HEAP MEMORY USED: x bytes
214 STACK MEMORY USED: x bytes
216 CLOCK CYCLES: (cycle count equation for this function) + (variable
217 used to represent cycle count for each subroutine
219 where: (cycle count variable) = cycle count for [subroutine
222 ------------------------------------------------------------------------------
224 [State any special notes, constraints or cautions for users of this function]
226 ------------------------------------------------------------------------------
230 Word16 a[], /* i : Directform coefficients */
231 Word16 refl[], /* o : Reflection coefficients */
235 /* local variables */
248 /* initialize states */
249 for (i = 0; i < M; i++)
254 /* backward Levinson recursion */
255 for (i = M - 1; i >= 0; i--)
257 if (abs_s(aState[i]) >= 4096)
259 for (i = 0; i < M; i++)
266 refl[i] = shl(aState[i], 3, pOverflow);
268 L_temp = L_mult(refl[i], refl[i], pOverflow);
269 L_acc = L_sub(MAX_32, L_temp, pOverflow);
271 normShift = norm_l(L_acc);
272 scale = sub(15, normShift, pOverflow);
274 L_acc = L_shl(L_acc, normShift, pOverflow);
275 normProd = pv_round(L_acc, pOverflow);
277 mult = div_s(16384, normProd);
279 for (j = 0; j < i; j++)
281 L_acc = L_deposit_h(aState[j]);
282 L_acc = L_msu(L_acc, refl[i], aState[i-j-1], pOverflow);
284 temp = pv_round(L_acc, pOverflow);
285 L_temp = L_mult(mult, temp, pOverflow);
286 L_temp = L_shr_r(L_temp, scale, pOverflow);
288 if (L_abs(L_temp) > 32767)
290 for (i = 0; i < M; i++)
297 bState[j] = extract_l(L_temp);
300 for (j = 0; j < i; j++)
302 aState[j] = bState[j];