1 /*
2  *  Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 /******************************************************************
12 
13  iLBC Speech Coder ANSI-C Source Code
14 
15  WebRtcIlbcfix_Lsf2Poly.c
16 
17 ******************************************************************/
18 
19 #include "defines.h"
20 #include "lsf_to_lsp.h"
21 #include "get_lsp_poly.h"
22 #include "constants.h"
23 
WebRtcIlbcfix_Lsf2Poly(int16_t * a,int16_t * lsf)24 void WebRtcIlbcfix_Lsf2Poly(
25     int16_t *a,     /* (o) predictor coefficients (order = 10) in Q12 */
26     int16_t *lsf    /* (i) line spectral frequencies in Q13 */
27                             ) {
28   int32_t f[2][6]; /* f[0][] and f[1][] corresponds to
29                             F1(z) and F2(z) respectivly */
30   int32_t *f1ptr, *f2ptr;
31   int16_t *a1ptr, *a2ptr;
32   int32_t tmpW32;
33   int16_t lsp[10];
34   int i;
35 
36   /* Convert lsf to lsp */
37   WebRtcIlbcfix_Lsf2Lsp(lsf, lsp, LPC_FILTERORDER);
38 
39   /* Get F1(z) and F2(z) from the lsp */
40   f1ptr=f[0];
41   f2ptr=f[1];
42   WebRtcIlbcfix_GetLspPoly(&lsp[0],f1ptr);
43   WebRtcIlbcfix_GetLspPoly(&lsp[1],f2ptr);
44 
45   /* for i = 5 down to 1
46      Compute f1[i] += f1[i-1];
47      and     f2[i] += f2[i-1];
48   */
49   f1ptr=&f[0][5];
50   f2ptr=&f[1][5];
51   for (i=5; i>0; i--)
52   {
53     (*f1ptr) += (*(f1ptr-1));
54     (*f2ptr) -= (*(f2ptr-1));
55     f1ptr--;
56     f2ptr--;
57   }
58 
59   /* Get the A(z) coefficients
60      a[0] = 1.0
61      for i = 1 to 5
62      a[i] = (f1[i] + f2[i] + round)>>13;
63      for i = 1 to 5
64      a[11-i] = (f1[i] - f2[i] + round)>>13;
65   */
66   a[0]=4096;
67   a1ptr=&a[1];
68   a2ptr=&a[10];
69   f1ptr=&f[0][1];
70   f2ptr=&f[1][1];
71   for (i=5; i>0; i--)
72   {
73     tmpW32 = (*f1ptr) + (*f2ptr);
74     *a1ptr = (int16_t)((tmpW32 + 4096) >> 13);
75 
76     tmpW32 = (*f1ptr) - (*f2ptr);
77     *a2ptr = (int16_t)((tmpW32 + 4096) >> 13);
78 
79     a1ptr++;
80     a2ptr--;
81     f1ptr++;
82     f2ptr++;
83   }
84 
85   return;
86 }
87