lsfwt.cpp revision 4f1efc098cb5791c3e9f483f2af84aef70d2d0a0
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/****************************************************************************************
19Portions 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)
26Permission to distribute, modify and use this file under the standard license
27terms listed above has been obtained from the copyright holder.
28****************************************************************************************/
29/*
30 Pathname: ./audio/gsm-amr/c/src/lsfwt.c
31 Functions: Lsf_wt
32
33------------------------------------------------------------------------------
34 REVISION HISTORY
35
36 Description: Updated to accept new parameter, Flag *pOverflow.  Placed
37 file in the proper PV Software template.
38
39 Description:
40              1. Eliminated unused include files.
41              2. Replaced array addressing by pointers
42              3. Eliminated math operations that unnecessary checked for
43                 saturation, by evaluating the operands
44              4. Unrolled loops to speed up processing, use decrement loops
45
46 Description:  Replaced "int" and/or "char" with OSCL defined types.
47
48 Who:                       Date:
49 Description:
50
51 ------------------------------------------------------------------------------
52 INPUT AND OUTPUT DEFINITIONS
53
54 Inputs:
55    lsf -- Pointer to Word16 -- LSF vector
56
57 Outputs:
58    wf -- Pointer to Word16 -- square of weighting factors
59    pOverflow -- Pointer to type Flag -- Flag set when overflow occurs
60
61 Returns:
62    None
63
64 Global Variables Used:
65    None
66
67 Local Variables Needed:
68    None
69
70------------------------------------------------------------------------------
71 FUNCTION DESCRIPTION
72
73Compute LSF weighting factors
74
75 d[i] = lsf[i+1] - lsf[i-1]
76
77 The weighting factors are approximated by two line segment
78
79 First segment passes by the following 2 points:
80
81    d[i] = 0Hz     wf[i] = 3.347
82    d[i] = 450Hz   wf[i] = 1.8
83
84 Second segment passes by the following 2 points:
85
86    d[i] = 450Hz   wf[i] = 1.8
87    d[i] = 1500Hz  wf[i] = 1.0
88
89 if( d[i] < 450Hz )
90   wf[i] = 3.347 - ( (3.347-1.8) / (450-0)) *  d[i]
91 else
92   wf[i] = 1.8 - ( (1.8-1.0) / (1500-450)) *  (d[i] - 450)
93
94
95 if( d[i] < 1843)
96   wf[i] = 3427 - (28160*d[i])>>15
97 else
98   wf[i] = 1843 - (6242*(d[i]-1843))>>15
99
100------------------------------------------------------------------------------
101 REQUIREMENTS
102
103
104
105------------------------------------------------------------------------------
106 REFERENCES
107
108 lsfwt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
109
110------------------------------------------------------------------------------
111 PSEUDO-CODE
112
113
114
115------------------------------------------------------------------------------
116 RESOURCES USED
117   When the code is written for a specific target processor the
118     the resources used should be documented below.
119
120 STACK USAGE: [stack count for this module] + [variable to represent
121          stack usage for each subroutine called]
122
123     where: [stack usage variable] = stack usage for [subroutine
124         name] (see [filename].ext)
125
126 DATA MEMORY USED: x words
127
128 PROGRAM MEMORY USED: x words
129
130 CLOCK CYCLES: [cycle count equation for this module] + [variable
131           used to represent cycle count for each subroutine
132           called]
133
134     where: [cycle count variable] = cycle count for [subroutine
135        name] (see [filename].ext)
136
137------------------------------------------------------------------------------
138*/
139
140
141/*----------------------------------------------------------------------------
142; INCLUDES
143----------------------------------------------------------------------------*/
144#include "lsfwt.h"
145#include "cnst.h"
146
147/*----------------------------------------------------------------------------
148; MACROS
149; Define module specific macros here
150----------------------------------------------------------------------------*/
151
152
153/*----------------------------------------------------------------------------
154; DEFINES
155; Include all pre-processor statements here. Include conditional
156; compile variables also.
157----------------------------------------------------------------------------*/
158
159
160/*----------------------------------------------------------------------------
161; LOCAL FUNCTION DEFINITIONS
162; Function Prototype declaration
163----------------------------------------------------------------------------*/
164
165
166/*----------------------------------------------------------------------------
167; LOCAL STORE/BUFFER/POINTER DEFINITIONS
168; Variable declaration - defined here and used outside this module
169----------------------------------------------------------------------------*/
170
171/*----------------------------------------------------------------------------
172; EXTERNAL FUNCTION REFERENCES
173; Declare functions defined elsewhere and referenced in this module
174----------------------------------------------------------------------------*/
175
176/*----------------------------------------------------------------------------
177; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
178; Declare variables used in this module but defined elsewhere
179----------------------------------------------------------------------------*/
180
181
182/*----------------------------------------------------------------------------
183; FUNCTION CODE
184----------------------------------------------------------------------------*/
185
186void Lsf_wt(
187    Word16 *lsf,         /* input : LSF vector                  */
188    Word16 *wf,          /* output: square of weighting factors */
189    Flag   *pOverflow
190)
191{
192    Word16 temp;
193    Word16 wgt_fct;
194    Word16 i;
195    Word16 *p_wf = wf;
196    Word16 *p_lsf   = &lsf[0];
197    Word16 *p_lsf_2 = &lsf[1];
198
199    OSCL_UNUSED_ARG(pOverflow);
200
201    /* wf[0] = lsf[1] - 0  */
202    *(p_wf++) = *(p_lsf_2++);
203
204    for (i = 4; i != 0 ; i--)
205    {
206        *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
207        *(p_wf++) = *(p_lsf_2++) - *(p_lsf++);
208    }
209    /*
210     *  wf[9] = 4000 - lsf[8]
211     */
212    *(p_wf) = 16384 - *(p_lsf);
213
214    p_wf = wf;
215
216    for (i = 10; i != 0; i--)
217    {
218        /*
219         *  (wf[i] - 450);
220         *  1843 == 450 Hz (Q15 considering 7FFF = 8000 Hz)
221         */
222        wgt_fct = *p_wf;
223        temp =  wgt_fct - 1843;
224
225        if (temp > 0)
226        {
227            temp = (Word16)(((Word32)temp * 6242) >> 15);
228            wgt_fct = 1843 - temp;
229        }
230        else
231        {
232            temp = (Word16)(((Word32)wgt_fct * 28160) >> 15);
233            wgt_fct = 3427 - temp;
234        }
235
236        *(p_wf++) = wgt_fct << 3;
237
238    } /* for (i = 10; i != 0; i--) */
239
240    return;
241
242} /* Lsf_wt() */
243