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 ****************************************************************************************/
32 Functions: Get_lsp_pol
35 ------------------------------------------------------------------------------
38 This file contains functions that convert line spectral pairs (LSP) to
39 linear predictive (LP) coefficients (filter order = 10). The functions
40 included in this file include Get_lsp_pol, which finds the coefficients of
41 F1(z) and F2(z), and Lsp_Az, which converts LSP to LPC by multiplying
42 F1(z) by 1+z^(-1) and F2(z) by 1-z^(-1), then calculating A(z) = (F1(z) +
45 ------------------------------------------------------------------------------
48 /*----------------------------------------------------------------------------
50 ----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
55 ; Define module specific macros here
56 ----------------------------------------------------------------------------*/
58 /*----------------------------------------------------------------------------
60 ; Include all pre-processor statements here. Include conditional
61 ; compile variables also.
62 ----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------
65 ; LOCAL FUNCTION DEFINITIONS
66 ; Function Prototype declaration
67 ----------------------------------------------------------------------------*/
69 /*----------------------------------------------------------------------------
70 ; LOCAL VARIABLE DEFINITIONS
71 ; Variable declaration - defined here and used outside this module
72 ----------------------------------------------------------------------------*/
76 ------------------------------------------------------------------------------
77 FUNCTION NAME: Get_lsp_pol
78 ------------------------------------------------------------------------------
79 INPUT AND OUTPUT DEFINITIONS
82 lsp = pointer to the buffer containing the line spectral pairs (LSP)
84 f = pointer to the polynomial of type Word32 to be generated
86 pOverflow = pointer set in case where one of the operations overflows.
87 [data type Pointer to Flag]
90 buffer pointed to by f contains the polynomial generated
92 pOverflow = pointer set in case where one of the operations overflows.
93 [data type Pointer to Flag]
98 Global Variables Used:
101 Local Variables Needed:
104 ------------------------------------------------------------------------------
107 This function finds the polynomial F1(z) or F2(z) from the LSPs. If the LSP
108 vector is passed at address 0, F1(z) is computed and if it is passed at
109 address 1, F2(z) is computed.
111 This is performed by expanding the product polynomials:
113 F1(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
115 F2(z) = product ( 1 - 2 lsp[i] z^-1 + z^-2 )
118 where lsp[] is the LSP vector in the cosine domain.
120 The expansion is performed using the following recursion:
126 b = -2.0 * lsp[2*i-2];
127 for j=i-1 down to 2 do
128 f[j] = f[j] + b*f[j-1] + f[j-2];
131 ------------------------------------------------------------------------------
136 ------------------------------------------------------------------------------
139 lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
141 ------------------------------------------------------------------------------
144 static void Get_lsp_pol (Word16 *lsp, Word32 *f)
150 *f = L_mult (4096, 2048);
152 *f = L_msu ((Word32) 0, *lsp, 512); // f[1] = -2.0 * lsp[0];
154 lsp += 2; // Advance lsp pointer
156 for (i = 2; i <= 5; i++)
160 for (j = 1; j < i; j++, f--)
162 L_Extract (f[-1], &hi, &lo);
163 t0 = Mpy_32_16 (hi, lo, *lsp); // t0 = f[-1] * lsp
165 *f = L_add (*f, f[-2]); // *f += f[-2]
166 *f = L_sub (*f, t0); // *f -= t0
168 *f = L_msu (*f, *lsp, 512); // *f -= lsp<<9
169 f += i; // Advance f pointer
170 lsp += 2; // Advance lsp pointer
176 ------------------------------------------------------------------------------
178 [State any special notes, constraints or cautions for users of this function]
180 ------------------------------------------------------------------------------
183 static void Get_lsp_pol(
194 OSCL_UNUSED_ARG(pOverflow);
197 *f++ = (Word32) 0x01000000;
198 *f++ = (Word32) - *(lsp++) << 10; /* f[1] = -2.0 * lsp[0]; */
199 lsp++; /* Advance lsp pointer */
201 for (i = 2; i <= 5; i++)
205 for (j = 1; j < i; j++)
207 hi = (Word16)(*(f - 1) >> 16);
209 lo = (Word16)((*(f - 1) >> 1) - ((Word32) hi << 15));
211 t0 = ((Word32)hi * *lsp);
212 t0 += ((Word32)lo * *lsp) >> 15;
214 *(f) += *(f - 2); /* *f += f[-2] */
215 *(f--) -= t0 << 2; /* *f -= t0 */
219 *f -= (Word32)(*lsp++) << 10;
228 /****************************************************************************/
234 ------------------------------------------------------------------------------
235 FUNCTION NAME: Lsp_Az
236 ------------------------------------------------------------------------------
237 INPUT AND OUTPUT DEFINITIONS
240 lsp = pointer to the buffer containing the line spectral pairs (LSP)
243 a = pointer to the buffer containing Linear Predictive (LP)
244 coefficients of type Word16 to be generated
246 pOverflow = pointer set in case where one of the operations overflows.
247 [data type Pointer to Flag]
249 Local Stores/Buffers/Pointers Needed:
252 Global Stores/Buffers/Pointers Needed:
256 pOverflow = pointer set in case where one of the operations overflows.
257 [data type Pointer to Flag]
259 Pointers and Buffers Modified:
260 a buffer contains the generated Linear Predictive (LP) coefficients
262 Local Stores Modified:
265 Global Stores Modified:
268 ------------------------------------------------------------------------------
271 This function converts from the line spectral pairs (LSP) to LP coefficients
272 for a 10th order filter.
275 (1) Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
276 (2) Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
277 (3) A(z) = ( F1(z) + F2(z) ) / 2
279 ------------------------------------------------------------------------------
284 ------------------------------------------------------------------------------
287 lsp_az.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
289 ------------------------------------------------------------------------------
293 Word16 lsp[], // (i) : line spectral frequencies
294 Word16 a[] // (o) : predictor coefficients (order = 10)
301 Get_lsp_pol (&lsp[0], f1);
302 Get_lsp_pol (&lsp[1], f2);
304 for (i = 5; i > 0; i--)
306 f1[i] = L_add (f1[i], f1[i - 1]); // f1[i] += f1[i-1];
307 f2[i] = L_sub (f2[i], f2[i - 1]); // f2[i] -= f2[i-1];
311 for (i = 1, j = 10; i <= 5; i++, j--)
313 t0 = L_add (f1[i], f2[i]); // f1[i] + f2[i]
314 a[i] = extract_l (L_shr_r (t0, 13));
315 t0 = L_sub (f1[i], f2[i]); // f1[i] - f2[i]
316 a[j] = extract_l (L_shr_r (t0, 13));
322 ------------------------------------------------------------------------------
324 [State any special notes, constraints or cautions for users of this function]
326 ------------------------------------------------------------------------------
329 OSCL_EXPORT_REF void Lsp_Az(
330 Word16 lsp[], /* (i) : line spectral frequencies */
331 Word16 a[], /* (o) : predictor coefficients (order = 10) */
332 Flag *pOverflow /* (o) : overflow flag */
346 Get_lsp_pol(&lsp[0], f1, pOverflow);
348 Get_lsp_pol(&lsp[1], f2, pOverflow);
353 for (i = 5; i > 0; i--)
355 *(p_f1--) += f1[i-1];
356 *(p_f2--) -= f2[i-1];
363 for (i = 1, j = 10; i <= 5; i++, j--)
365 t0 = *(p_f1) + *(p_f2); /* f1[i] + f2[i] */
366 t1 = *(p_f1++) - *(p_f2++); /* f1[i] - f2[i] */
368 t0 = t0 + ((Word32) 1 << 12);
369 t1 = t1 + ((Word32) 1 << 12);
371 *(p_a++) = (Word16)(t0 >> 13);
372 a[j] = (Word16)(t1 >> 13);