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_Lsp2Lsf.c
16
17 ******************************************************************/
18
19 #include "modules/audio_coding/codecs/ilbc/lsp_to_lsf.h"
20
21 #include "modules/audio_coding/codecs/ilbc/constants.h"
22 #include "modules/audio_coding/codecs/ilbc/defines.h"
23
24 /*----------------------------------------------------------------*
25 * conversion from LSP coefficients to LSF coefficients
26 *---------------------------------------------------------------*/
27
WebRtcIlbcfix_Lsp2Lsf(int16_t * lsp,int16_t * lsf,int16_t m)28 void WebRtcIlbcfix_Lsp2Lsf(
29 int16_t *lsp, /* (i) lsp vector -1...+1 in Q15 */
30 int16_t *lsf, /* (o) Lsf vector 0...Pi in Q13
31 (ordered, so that lsf[i]<lsf[i+1]) */
32 int16_t m /* (i) Number of coefficients */
33 )
34 {
35 int16_t i, k;
36 int16_t diff; /* diff between table value and desired value (Q15) */
37 int16_t freq; /* lsf/(2*pi) (Q16) */
38 int16_t *lspPtr, *lsfPtr, *cosTblPtr;
39 int16_t tmp;
40
41 /* set the index to maximum index value in WebRtcIlbcfix_kCos */
42 k = 63;
43
44 /*
45 Start with the highest LSP and then work the way down
46 For each LSP the lsf is calculated by first order approximation
47 of the acos(x) function
48 */
49 lspPtr = &lsp[9];
50 lsfPtr = &lsf[9];
51 cosTblPtr=(int16_t*)&WebRtcIlbcfix_kCos[k];
52 for(i=m-1; i>=0; i--)
53 {
54 /*
55 locate value in the table, which is just above lsp[i],
56 basically an approximation to acos(x)
57 */
58 while( (((int32_t)(*cosTblPtr)-(*lspPtr)) < 0)&&(k>0) )
59 {
60 k-=1;
61 cosTblPtr--;
62 }
63
64 /* Calculate diff, which is used in the linear approximation of acos(x) */
65 diff = (*lspPtr)-(*cosTblPtr);
66
67 /*
68 The linear approximation of acos(lsp[i]) :
69 acos(lsp[i])= k*512 + (WebRtcIlbcfix_kAcosDerivative[ind]*offset >> 11)
70 */
71
72 /* tmp (linear offset) in Q16 */
73 tmp = (int16_t)((WebRtcIlbcfix_kAcosDerivative[k] * diff) >> 11);
74
75 /* freq in Q16 */
76 freq = (k << 9) + tmp;
77
78 /* lsf = freq*2*pi */
79 (*lsfPtr) = (int16_t)(((int32_t)freq*25736)>>15);
80
81 lsfPtr--;
82 lspPtr--;
83 }
84
85 return;
86 }
87