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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Pathname: ./audio/gsm-amr/c/src/int_lsf.c
38 ------------------------------------------------------------------------------
41 Description: Put file into template and first pass at optimization.
43 Description: Made changes based on comments from the review meeting. Used
44 pointers instead of index addressing in the arrays.
46 Description: Added type definition to the input/output section. Fixed tabs.
49 Description: Synchronized file with UMTS versin 3.2.0. Updated coding
50 template. Removed unnecessary include files.
52 Description: Made the following changes per comments from Phase 2/3 review:
53 1. Modified FOR loops to count down.
54 2. Made some cosmetic changes in the Pseudo-code section.
56 Description: Changed to pass in overflow flag pointer to the add() routine.
58 Description: Replaced "int" and/or "char" with OSCL defined types.
62 ------------------------------------------------------------------------------
65 /*----------------------------------------------------------------------------
67 ----------------------------------------------------------------------------*/
73 /*----------------------------------------------------------------------------
75 ; Define module specific macros here
76 ----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------
81 ; Include all pre-processor statements here. Include conditional
82 ; compile variables also.
83 ----------------------------------------------------------------------------*/
86 /*----------------------------------------------------------------------------
87 ; LOCAL FUNCTION DEFINITIONS
88 ; Function Prototype declaration
89 ----------------------------------------------------------------------------*/
92 /*----------------------------------------------------------------------------
93 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
94 ; Variable declaration - defined here and used outside this module
95 ----------------------------------------------------------------------------*/
99 ------------------------------------------------------------------------------
100 FUNCTION NAME: Int_lsf
101 ------------------------------------------------------------------------------
102 INPUT AND OUTPUT DEFINITIONS
105 lsf_old = LSF vector at the 4th SF of past frame (Word16)
106 lsf_new = LSF vector at the 4th SF of present frame (Word16)
107 i_subfr = Current subframe (equal to 0,40,80 or 120) (Word16)
108 lsf_out = interpolated LSF parameters for current subframe (Word16)
111 lsf_out = new interpolated LSF parameters for current subframe
112 pOverflow = pointer of type Flag * to overflow indicator.
117 Global Variables Used:
120 Local Variables Needed:
123 ------------------------------------------------------------------------------
126 This function interpolates the LSFs for selected subframe.
127 The 20 ms speech frame is divided into 4 subframes. The LSFs are
128 interpolated at the 1st, 2nd and 3rd subframe and only forwarded
131 |------|------|------|------|
135 sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
136 sf2: 1/2 F0 + 1/2 F1 sf4: F1
138 ------------------------------------------------------------------------------
143 ------------------------------------------------------------------------------
146 int_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
148 ------------------------------------------------------------------------------
152 Word16 lsf_old[], // i : LSF vector at the 4th SF of past frame
153 Word16 lsf_new[], // i : LSF vector at the 4th SF of present frame
154 Word16 i_subfr, // i : Pointer to current sf (equal to 0,40,80 or 120)
155 Word16 lsf_out[] // o : interpolated LSF parameters for current sf
162 for (i = 0; i < M; i++) {
163 lsf_out[i] = add(sub(lsf_old[i], shr(lsf_old[i], 2)),
167 else if ( sub(i_subfr, 40) == 0 )
169 for (i = 0; i < M; i++) {
170 lsf_out[i] = add(shr(lsf_old[i],1), shr(lsf_new[i], 1) );
173 else if ( sub(i_subfr, 80) == 0 )
175 for (i = 0; i < M; i++) {
176 lsf_out[i] = add(shr(lsf_old[i], 2),
177 sub(lsf_new[i], shr(lsf_new[i], 2)));
180 else if ( sub(i_subfr, 120) == 0 )
182 for (i = 0; i < M; i++) {
183 lsf_out[i] = lsf_new[i];
190 ------------------------------------------------------------------------------
191 RESOURCES USED [optional]
193 When the code is written for a specific target processor the
194 the resources used should be documented below.
196 HEAP MEMORY USED: x bytes
198 STACK MEMORY USED: x bytes
200 CLOCK CYCLES: (cycle count equation for this function) + (variable
201 used to represent cycle count for each subroutine
203 where: (cycle count variable) = cycle count for [subroutine
206 ------------------------------------------------------------------------------
208 [State any special notes, constraints or cautions for users of this function]
210 ------------------------------------------------------------------------------
214 Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame */
215 Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame */
216 Word16 i_subfr, /* i : Current sf (equal to 0,40,80 or 120) */
217 Word16 lsf_out[], /* o : interpolated LSF parameters for current sf */
218 Flag *pOverflow /* o : flag set if overflow occurs */
222 register Word16 temp1;
223 register Word16 temp2;
227 for (i = M - 1; i >= 0; i--)
229 if (*(lsf_old + i) < 0)
231 temp1 = ~(~(*(lsf_old + i)) >> 2);
235 temp1 = *(lsf_old + i) >> 2;
237 if (*(lsf_new + i) < 0)
239 temp2 = ~(~(*(lsf_new + i)) >> 2);
243 temp2 = *(lsf_new + i) >> 2;
245 *(lsf_out + i) = add((Word16)(*(lsf_old + i) - temp1),
251 else if (i_subfr == 40)
253 for (i = M - 1; i >= 0; i--)
255 if (*(lsf_old + i) < 0)
257 temp1 = ~(~(*(lsf_old + i)) >> 1);
261 temp1 = *(lsf_old + i) >> 1;
263 if (*(lsf_new + i) < 0)
265 temp2 = ~(~(*(lsf_new + i)) >> 1);
269 temp2 = *(lsf_new + i) >> 1;
271 *(lsf_out + i) = add(
278 else if (i_subfr == 80)
280 for (i = M - 1; i >= 0; i--)
282 if (*(lsf_old + i) < 0)
284 temp1 = ~(~(*(lsf_old + i)) >> 2);
288 temp1 = *(lsf_old + i) >> 2;
290 if (*(lsf_new + i) < 0)
292 temp2 = ~(~(*(lsf_new + i)) >> 2);
296 temp2 = *(lsf_new + i) >> 2;
298 *(lsf_out + i) = add((Word16)temp1,
299 (Word16)(*(lsf_new + i) - temp2),
305 else if (i_subfr == 120)
307 for (i = M - 1; i >= 0; i--)
309 *(lsf_out + i) = *(lsf_new + i);