Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / lsfwt.cpp
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30  Filename: lsfwt.cpp
31  Functions: Lsf_wt
32
33  ------------------------------------------------------------------------------
34  INPUT AND OUTPUT DEFINITIONS
35
36  Inputs:
37     lsf -- Pointer to Word16 -- LSF vector
38
39  Outputs:
40     wf -- Pointer to Word16 -- square of weighting factors
41     pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
42
43  Returns:
44     None
45
46  Global Variables Used:
47     None
48
49  Local Variables Needed:
50     None
51
52 ------------------------------------------------------------------------------
53  FUNCTION DESCRIPTION
54
55 Compute LSF weighting factors
56
57  d[i] = lsf[i+1] - lsf[i-1]
58
59  The weighting factors are approximated by two line segment
60
61  First segment passes by the following 2 points:
62
63     d[i] = 0Hz     wf[i] = 3.347
64     d[i] = 450Hz   wf[i] = 1.8
65
66  Second segment passes by the following 2 points:
67
68     d[i] = 450Hz   wf[i] = 1.8
69     d[i] = 1500Hz  wf[i] = 1.0
70
71  if( d[i] < 450Hz )
72    wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) *  d[i]
73  else
74    wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) *  (d[i] - 450)
75
76
77  if( d[i] < 1843)
78    wf[i] = 3427 - (28160*d[i])>>15
79  else
80    wf[i] = 1843 - (6242*(d[i]-1843))>>15
81
82 ------------------------------------------------------------------------------
83  REQUIREMENTS
84
85
86
87 ------------------------------------------------------------------------------
88  REFERENCES
89
90  lsfwt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
91
92 ------------------------------------------------------------------------------
93  PSEUDO-CODE
94
95
96
97 ------------------------------------------------------------------------------
98 */
99
100
101 /*----------------------------------------------------------------------------
102 ; INCLUDES
103 ----------------------------------------------------------------------------*/
104 #include "lsfwt.h"
105 #include "cnst.h"
106
107 /*----------------------------------------------------------------------------
108 ; MACROS
109 ; Define module specific macros here
110 ----------------------------------------------------------------------------*/
111
112
113 /*----------------------------------------------------------------------------
114 ; DEFINES
115 ; Include all pre-processor statements here. Include conditional
116 ; compile variables also.
117 ----------------------------------------------------------------------------*/
118
119
120 /*----------------------------------------------------------------------------
121 ; LOCAL FUNCTION DEFINITIONS
122 ; Function Prototype declaration
123 ----------------------------------------------------------------------------*/
124
125
126 /*----------------------------------------------------------------------------
127 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
128 ; Variable declaration - defined here and used outside this module
129 ----------------------------------------------------------------------------*/
130
131 /*----------------------------------------------------------------------------
132 ; EXTERNAL FUNCTION REFERENCES
133 ; Declare functions defined elsewhere and referenced in this module
134 ----------------------------------------------------------------------------*/
135
136 /*----------------------------------------------------------------------------
137 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
138 ; Declare variables used in this module but defined elsewhere
139 ----------------------------------------------------------------------------*/
140
141
142 /*----------------------------------------------------------------------------
143 ; FUNCTION CODE
144 ----------------------------------------------------------------------------*/
145
146 void Lsf_wt(
147     Word16 *lsf,         /* input : LSF vector                  */
148     Word16 *wf,          /* output: square of weighting factors */
149     Flag   *pOverflow
150 )
151 {
152     Word16 temp;
153     Word16 wgt_fct;
154     Word16 i;
155     Word16 *p_wf = wf;
156     Word16 *p_lsf   = &lsf[0];
157     Word16 *p_lsf_2 = &lsf[1];
158
159     OSCL_UNUSED_ARG(pOverflow);
160
161     /* wf[0] = lsf[1] - 0  */
162     *(p_wf++) = *(p_lsf_2++);
163
164     for (i = 4; i != 0 ; i--)
165     {
166         *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
167         *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
168     }
169     /*
170      *  wf[9] = 4000 - lsf[8]
171      */
172     *(p_wf) = 16384 - *(p_lsf);
173
174     p_wf = wf;
175
176     for (i = 10; i != 0; i--)
177     {
178         /*
179          *  (wf[i] - 450);
180          *  1843 == 450 Hz (Q15 considering 7FFF = 8000 Hz)
181          */
182         wgt_fct = *p_wf;
183         temp =  wgt_fct - 1843;
184
185         if (temp > 0)
186         {
187             temp = (Word16)(((Word32)temp * 6242) >> 15);
188             wgt_fct = 1843 - temp;
189         }
190         else
191         {
192             temp = (Word16)(((Word32)wgt_fct * 28160) >> 15);
193             wgt_fct = 3427 - temp;
194         }
195
196         *(p_wf++) = wgt_fct << 3;
197
198     } /* for (i = 10; i != 0; i--) */
199
200     return;
201
202 } /* Lsf_wt() */