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 - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 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 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
39 int16 isp[], (i) Q15 : Immittance spectral pairs
40 int16 a[], (o) Q12 : predictor coefficients (order=M)
42 int16 adaptive_scaling (i) 0 : adaptive scaling disabled
43 1 : adaptive scaling enabled
46 ------------------------------------------------------------------------------
49 Compute the LPC coefficients from isp (order=M)
50 ------------------------------------------------------------------------------
54 ------------------------------------------------------------------------------
57 ------------------------------------------------------------------------------
60 ------------------------------------------------------------------------------
64 /*----------------------------------------------------------------------------
66 ----------------------------------------------------------------------------*/
68 #include "pv_amr_wb_type_defs.h"
69 #include "pvamrwbdecoder_basic_op.h"
70 #include "pvamrwbdecoder_cnst.h"
71 #include "pvamrwbdecoder_acelp.h"
72 #include "pvamrwb_math_op.h"
74 /*----------------------------------------------------------------------------
76 ; Define module specific macros here
77 ----------------------------------------------------------------------------*/
80 /*----------------------------------------------------------------------------
82 ; Include all pre-processor statements here. Include conditional
83 ; compile variables also.
84 ----------------------------------------------------------------------------*/
86 #define NC16k (M16k/2)
88 /*----------------------------------------------------------------------------
89 ; LOCAL FUNCTION DEFINITIONS
90 ; Function Prototype declaration
91 ----------------------------------------------------------------------------*/
99 void Get_isp_pol(int16 * isp, int32 * f, int16 n);
100 void Get_isp_pol_16kHz(int16 * isp, int32 * f, int16 n);
106 /*----------------------------------------------------------------------------
107 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
108 ; Variable declaration - defined here and used outside this module
109 ----------------------------------------------------------------------------*/
111 /*----------------------------------------------------------------------------
112 ; EXTERNAL FUNCTION REFERENCES
113 ; Declare functions defined elsewhere and referenced in this module
114 ----------------------------------------------------------------------------*/
116 /*----------------------------------------------------------------------------
117 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
118 ; Declare variables used in this module but defined elsewhere
119 ----------------------------------------------------------------------------*/
121 /*----------------------------------------------------------------------------
123 ----------------------------------------------------------------------------*/
126 int16 isp[], /* (i) Q15 : Immittance spectral pairs */
127 int16 a[], /* (o) Q12 : predictor coefficients (order=M) */
128 int16 m, /* (i) : order */
129 int16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
130 /* 1 : adaptive scaling enabled */
134 int32 f1[NC16k + 1], f2[NC16k];
146 Get_isp_pol_16kHz(&isp[0], f1, nc);
147 for (i = 0; i <= nc; i++)
149 f1[i] = shl_int32(f1[i], 2);
151 Get_isp_pol_16kHz(&isp[1], f2, nc - 1);
152 for (i = 0; i <= nc - 1; i++)
154 f2[i] = shl_int32(f2[i], 2);
159 Get_isp_pol(&isp[0], f1, nc);
160 Get_isp_pol(&isp[1], f2, nc - 1);
164 * Multiply F2(z) by (1 - z^-2)
167 for (i = nc - 1; i > 1; i--)
169 f2[i] -= f2[i - 2]; /* f2[i] -= f2[i-2]; */
173 * Scale F1(z) by (1+isp[m-1]) and F2(z) by (1-isp[m-1])
176 for (i = 0; i < nc; i++)
178 /* f1[i] *= (1.0 + isp[M-1]); */
180 /* f2[i] *= (1.0 - isp[M-1]); */
183 t0 = fxp_mul32_by_16b(t0, isp[m - 1]) << 1;
184 t1 = fxp_mul32_by_16b(t1, isp[m - 1]) << 1;
191 * A(z) = (F1(z)+F2(z))/2
192 * F1(z) is symmetric and F2(z) is antisymmetric
199 for (i = 1; i < nc; i++)
201 /* a[i] = 0.5*(f1[i] + f2[i]); */
203 t0 = add_int32(f1[i], f2[i]); /* f1[i] + f2[i] */
204 /* compute t1 = abs(t0) */
206 t1 = t1 ^(t1 >> 31); /* t1 = t1 ^sign(t1) */
209 /* from Q23 to Q12 and * 0.5 */
210 a[i] = (int16)((t0 >> 12) + ((t0 >> 11) & 1));
213 /* a[j] = 0.5*(f1[i] - f2[i]); */
215 t0 = sub_int32(f1[i], f2[i]); /* f1[i] - f2[i] */
216 /* compute t1 = abs(t0) */
218 t1 = t1 ^(t1 >> 31); /* t1 = t1 ^sign(t1) */
222 /* from Q23 to Q12 and * 0.5 */
223 a[j--] = (int16)((t0 >> 12) + ((t0 >> 11) & 1));
227 /* rescale data if overflow has occured and reprocess the loop */
230 if (adaptive_scaling == 1)
232 q = 4 - normalize_amr_wb(tmax); /* adaptive scaling enabled */
236 q = 0; /* adaptive scaling disabled */
243 for (i = 1, j = m - 1; i < nc; i++, j--)
245 /* a[i] = 0.5*(f1[i] + f2[i]); */
247 t0 = add_int32(f1[i], f2[i]); /* f1[i] + f2[i] */
248 /* from Q23 to Q12 and * 0.5 */
249 a[i] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
252 /* a[j] = 0.5*(f1[i] - f2[i]); */
254 t0 = sub_int32(f1[i], f2[i]); /* f1[i] - f2[i] */
255 /* from Q23 to Q12 and * 0.5 */
256 a[j] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
267 /* a[NC] = 0.5*f1[NC]*(1.0 + isp[M-1]); */
270 t0 = (int32)(((int64)f1[nc] * isp[m - 1]) >> 16) << 1;
273 t0 = add_int32(f1[nc], t0);
275 /* from Q23 to Q12 and * 0.5 */
276 a[nc] = (int16)((t0 >> q_sug) + ((t0 >> (q_sug - 1)) & 1));
277 a[m] = shr_rnd(isp[m - 1], (3 + q)); /* from Q15 to Q12 */
279 /* a[m] = isp[m-1]; */
289 ------------------------------------------------------------------------------
290 INPUT AND OUTPUT DEFINITIONS
292 isp[] : isp vector (cosine domaine) in Q15
293 f[] : the coefficients of F1 or F2 in Q23
294 n : == NC for F1(z); == NC-1 for F2(z)
297 ------------------------------------------------------------------------------
300 Find the polynomial F1(z) or F2(z) from the ISPs.
301 This is performed by expanding the product polynomials:
303 F1(z) = product ( 1 - 2 isp_i z^-1 + z^-2 )
305 F2(z) = product ( 1 - 2 isp_i z^-1 + z^-2 )
308 where isp_i are the ISPs in the cosine domain.
309 ------------------------------------------------------------------------------
313 ------------------------------------------------------------------------------
316 ------------------------------------------------------------------------------
319 ----------------------------------------------------------------------------*/
321 /*----------------------------------------------------------------------------
323 ----------------------------------------------------------------------------*/
326 void Get_isp_pol(int16 * isp, int32 * f, int16 n)
332 /* All computation in Q23 */
334 f[0] = 0x00800000; /* f[0] = 1.0; in Q23 */
335 f[1] = -isp[0] << 9; /* f[1] = -2.0*isp[0] in Q23 */
337 f += 2; /* Advance f pointer */
338 isp += 2; /* Advance isp pointer */
340 for (i = 2; i <= n; i++)
344 for (j = 1; j < i; j++)
347 t0 = fxp_mul32_by_16b(f[-1], *isp);
348 t0 = shl_int32(t0, 2);
350 *f -= t0; /* *f -= t0 */
351 *(f) += f[-2]; /* *f += f[-2] */
358 f += i; /* Advance f pointer */
359 isp += 2; /* Advance isp pointer */
363 void Get_isp_pol_16kHz(int16 * isp, int32 * f, int16 n)
368 /* All computation in Q23 */
370 f[0] = 0x00200000; /* f[0] = 0.25; in Q23 */
372 f[1] = -isp[0] << 7; /* f[1] = -0.5*isp[0] in Q23 */
374 f += 2; /* Advance f pointer */
375 isp += 2; /* Advance isp pointer */
377 for (i = 2; i <= n; i++)
381 for (j = 1; j < i; j++, f--)
383 t0 = fxp_mul32_by_16b(f[-1], *isp);
384 t0 = shl_int32(t0, 2);
386 *f -= t0; /* *f -= t0 */
387 *f += f[-2]; /* *f += f[-2] */
390 f += i; /* Advance f pointer */
391 isp += 2; /* Advance isp pointer */