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_Lsf2Lsp.c
16 
17 ******************************************************************/
18 
19 #include "defines.h"
20 #include "constants.h"
21 
22 /*----------------------------------------------------------------*
23  *  conversion from lsf to lsp coefficients
24  *---------------------------------------------------------------*/
25 
WebRtcIlbcfix_Lsf2Lsp(int16_t * lsf,int16_t * lsp,int16_t m)26 void WebRtcIlbcfix_Lsf2Lsp(
27     int16_t *lsf, /* (i) lsf in Q13 values between 0 and pi */
28     int16_t *lsp, /* (o) lsp in Q15 values between -1 and 1 */
29     int16_t m  /* (i) number of coefficients */
30                            ) {
31   int16_t i, k;
32   int16_t diff; /* difference, which is used for the
33                            linear approximation (Q8) */
34   int16_t freq; /* normalized frequency in Q15 (0..1) */
35   int32_t tmpW32;
36 
37   for(i=0; i<m; i++)
38   {
39     freq = (int16_t)((lsf[i] * 20861) >> 15);
40     /* 20861: 1.0/(2.0*PI) in Q17 */
41     /*
42        Upper 8 bits give the index k and
43        Lower 8 bits give the difference, which needs
44        to be approximated linearly
45     */
46     k = freq >> 8;
47     diff = (freq&0x00ff);
48 
49     /* Guard against getting outside table */
50 
51     if (k>63) {
52       k = 63;
53     }
54 
55     /* Calculate linear approximation */
56     tmpW32 = WebRtcIlbcfix_kCosDerivative[k] * diff;
57     lsp[i] = WebRtcIlbcfix_kCos[k] + (int16_t)(tmpW32 >> 12);
58   }
59 
60   return;
61 }
62