1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
34 ------------------------------------------------------------------------------
37 This file contains the functions that convert line spectral pairs (LSP) to
38 line spectral frequencies (LSF) and vice-versa.
40 ------------------------------------------------------------------------------
43 /*----------------------------------------------------------------------------
45 ----------------------------------------------------------------------------*/
47 #include "basicop_malloc.h"
50 /*--------------------------------------------------------------------------*/
56 /*----------------------------------------------------------------------------
58 ; Define module specific macros here
59 ----------------------------------------------------------------------------*/
61 /*----------------------------------------------------------------------------
63 ; Include all pre-processor statements here. Include conditional
64 ; compile variables also.
65 ----------------------------------------------------------------------------*/
67 /*----------------------------------------------------------------------------
68 ; LOCAL FUNCTION DEFINITIONS
69 ; Function Prototype declaration
70 ----------------------------------------------------------------------------*/
72 /*----------------------------------------------------------------------------
73 ; LOCAL VARIABLE DEFINITIONS
74 ; Variable declaration - defined here and used outside this module
75 ----------------------------------------------------------------------------*/
77 extern const Word16 table[];
78 extern const Word16 slope[];
81 /*--------------------------------------------------------------------------*/
87 ------------------------------------------------------------------------------
88 FUNCTION NAME: Lsf_lsp
89 ------------------------------------------------------------------------------
90 INPUT AND OUTPUT DEFINITIONS
93 lsf = buffer containing normalized line spectral frequencies; valid
94 range is between 0 and 0.5 (Word16)
95 lsp = buffer containing line spectral pairs; valid range is between
97 m = LPC order (Word16)
100 lsp contains the newly calculated line spectral pairs
105 Global Variables Used:
108 Local Variables Needed:
111 ------------------------------------------------------------------------------
114 This function performs the LSF to LSP transformation using the equation:
116 lsf[i] = arccos(lsp[i])/(2*pi)
118 The transformation from lsp[i] to lsf[i] is approximated by a look-up table
121 ------------------------------------------------------------------------------
126 ------------------------------------------------------------------------------
129 lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
131 ------------------------------------------------------------------------------
135 Word16 lsf[], // (i) : lsf[m] normalized (range: 0.0<=val<=0.5)
136 Word16 lsp[], // (o) : lsp[m] (range: -1<=val<1)
137 Word16 m // (i) : LPC order
140 Word16 i, ind, offset;
143 for (i = 0; i < m; i++)
145 ind = shr (lsf[i], 8); // ind = b8-b15 of lsf[i]
146 offset = lsf[i] & 0x00ff; // offset = b0-b7 of lsf[i]
148 // lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256
150 L_tmp = L_mult (sub (table[ind + 1], table[ind]), offset);
151 lsp[i] = add (table[ind], extract_l (L_shr (L_tmp, 9)));
157 ------------------------------------------------------------------------------
159 [State any special notes, constraints or cautions for users of this function]
161 ------------------------------------------------------------------------------
164 OSCL_EXPORT_REF void Lsf_lsp(
165 Word16 lsf[], /* (i) : lsf[m] normalized (range: 0.0<=val<=0.5) */
166 Word16 lsp[], /* (o) : lsp[m] (range: -1<=val<1) */
167 Word16 m, /* (i) : LPC order */
168 Flag *pOverflow /* (o) : Flag set when overflow occurs */
171 Word16 i, ind, offset;
174 for (i = 0; i < m; i++)
176 ind = lsf[i] >> 8; /* ind = b8-b15 of lsf[i] */
177 offset = lsf[i] & 0x00ff; /* offset = b0-b7 of lsf[i] */
179 /* lsp[i] = table[ind]+ ((table[ind+1]-table[ind])*offset) / 256 */
181 L_tmp = ((Word32)(table[ind + 1] - table[ind]) * offset) >> 8;
182 lsp[i] = table[ind] + (Word16) L_tmp;
189 /****************************************************************************/
193 ------------------------------------------------------------------------------
194 FUNCTION NAME: Lsp_lsf
195 ------------------------------------------------------------------------------
196 INPUT AND OUTPUT DEFINITIONS
199 lsp = buffer containing line spectral pairs; valid range is between
201 lsf = buffer containing normalized line spectral frequencies; valid
202 range is between 0 and 0.5 (Word16)
203 m = LPC order (Word16)
206 lsf contains the newly calculated normalized line spectral frequencies
211 Global Variables Used:
213 slope = table to used to calculate inverse cosine
215 Local Variables Needed:
218 ------------------------------------------------------------------------------
221 This function performs the LSP to LSF transformation using the equation:
223 lsp[i] = cos(2*pi*lsf[i])
225 The transformation from lsf[i] to lsp[i] is approximated by a look-up table
228 ------------------------------------------------------------------------------
233 ------------------------------------------------------------------------------
236 lsp_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
238 ------------------------------------------------------------------------------
242 Word16 lsp[], // (i) : lsp[m] (range: -1<=val<1)
243 Word16 lsf[], // (o) : lsf[m] normalized (range: 0.0<=val<=0.5)
244 Word16 m // (i) : LPC order
250 ind = 63; // begin at end of table -1
252 for (i = m - 1; i >= 0; i--)
254 // find value in table that is just greater than lsp[i]
256 while (sub (table[ind], lsp[i]) < 0)
262 // acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
265 L_tmp = L_mult (sub (lsp[i], table[ind]), slope[ind]);
266 //(lsp[i]-table[ind])*slope[ind])>>12
267 lsf[i] = pv_round (L_shl (L_tmp, 3));
268 lsf[i] = add (lsf[i], shl (ind, 8));
273 ------------------------------------------------------------------------------
275 [State any special notes, constraints or cautions for users of this function]
277 ------------------------------------------------------------------------------
280 OSCL_EXPORT_REF void Lsp_lsf(
281 Word16 lsp[], /* (i) : lsp[m] (range: -1<=val<1) */
282 Word16 lsf[], /* (o) : lsf[m] normalized (range: 0.0<=val<=0.5) */
283 Word16 m, /* (i) : LPC order */
284 Flag *pOverflow /* (o) : Flag set when overflow occurs */
291 Word16 *p_lsp = &lsp[m-1];
292 Word16 *p_lsf = &lsf[m-1];
293 OSCL_UNUSED_ARG(pOverflow);
295 ind = 63; /* begin at end of table -1 */
297 for (i = m - 1; i >= 0; i--)
299 /* find value in table that is just greater than lsp[i] */
301 while (table[ind] < temp)
306 /* acos(lsp[i])= ind*256 + ( ( lsp[i]-table[ind] ) *
309 L_tmp = (Word32)(temp - table[ind]) * slope[ind];
311 /*(lsp[i]-table[ind])*slope[ind])>>12*/
312 L_tmp = (L_tmp + 0x00000800) >> 12;
314 *(p_lsf--) = (Word16)(L_tmp) + (ind << 8);