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