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_GetLspPoly.c
16 
17 ******************************************************************/
18 
19 #include "defines.h"
20 
21 /*----------------------------------------------------------------*
22  * Construct the polynomials F1(z) and F2(z) from the LSP
23  * (Computations are done in Q24)
24  *
25  * The expansion is performed using the following recursion:
26  *
27  * f[0] = 1;
28  * tmp = -2.0 * lsp[0];
29  * f[1] = tmp;
30  * for (i=2; i<=5; i++) {
31  *    b = -2.0 * lsp[2*i-2];
32  *    f[i] = tmp*f[i-1] + 2.0*f[i-2];
33  *    for (j=i; j>=2; j--) {
34  *       f[j] = f[j] + tmp*f[j-1] + f[j-2];
35  *    }
36  *    f[i] = f[i] + tmp;
37  * }
38  *---------------------------------------------------------------*/
39 
WebRtcIlbcfix_GetLspPoly(int16_t * lsp,int32_t * f)40 void WebRtcIlbcfix_GetLspPoly(
41     int16_t *lsp, /* (i) LSP in Q15 */
42     int32_t *f)  /* (o) polonymial in Q24 */
43 {
44   int32_t tmpW32;
45   int i, j;
46   int16_t high, low;
47   int16_t *lspPtr;
48   int32_t *fPtr;
49 
50   lspPtr = lsp;
51   fPtr = f;
52   /* f[0] = 1.0 (Q24) */
53   (*fPtr) = (int32_t)16777216;
54   fPtr++;
55 
56   (*fPtr) = WEBRTC_SPL_MUL((*lspPtr), -1024);
57   fPtr++;
58   lspPtr+=2;
59 
60   for(i=2; i<=5; i++)
61   {
62     (*fPtr) = fPtr[-2];
63 
64     for(j=i; j>1; j--)
65     {
66       /* Compute f[j] = f[j] + tmp*f[j-1] + f[j-2]; */
67       high = (int16_t)(fPtr[-1] >> 16);
68       low = (int16_t)((fPtr[-1] & 0xffff) >> 1);
69 
70       tmpW32 = 4 * high * *lspPtr + 4 * ((low * *lspPtr) >> 15);
71 
72       (*fPtr) += fPtr[-2];
73       (*fPtr) -= tmpW32;
74       fPtr--;
75     }
76     *fPtr -= *lspPtr * (1 << 10);
77 
78     fPtr+=i;
79     lspPtr+=2;
80   }
81   return;
82 }
83