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 ------------------------------------------------------------------------------
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
47 /*----------------------------------------------------------------------------
49 ; Define module specific macros here
50 ----------------------------------------------------------------------------*/
53 /*----------------------------------------------------------------------------
55 ; Include all pre-processor statements here. Include conditional
56 ; compile variables also.
57 ----------------------------------------------------------------------------*/
60 /*----------------------------------------------------------------------------
61 ; LOCAL FUNCTION DEFINITIONS
62 ; Function Prototype declaration
63 ----------------------------------------------------------------------------*/
66 /*----------------------------------------------------------------------------
67 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
68 ; Variable declaration - defined here and used outside this module
69 ----------------------------------------------------------------------------*/
73 ------------------------------------------------------------------------------
74 FUNCTION NAME: Int_lsf
75 ------------------------------------------------------------------------------
76 INPUT AND OUTPUT DEFINITIONS
79 lsf_old = LSF vector at the 4th SF of past frame (Word16)
80 lsf_new = LSF vector at the 4th SF of present frame (Word16)
81 i_subfr = Current subframe (equal to 0,40,80 or 120) (Word16)
82 lsf_out = interpolated LSF parameters for current subframe (Word16)
85 lsf_out = new interpolated LSF parameters for current subframe
86 pOverflow = pointer of type Flag * to overflow indicator.
91 Global Variables Used:
94 Local Variables Needed:
97 ------------------------------------------------------------------------------
100 This function interpolates the LSFs for selected subframe.
101 The 20 ms speech frame is divided into 4 subframes. The LSFs are
102 interpolated at the 1st, 2nd and 3rd subframe and only forwarded
105 |------|------|------|------|
109 sf1: 3/4 F0 + 1/4 F1 sf3: 1/4 F0 + 3/4 F1
110 sf2: 1/2 F0 + 1/2 F1 sf4: F1
112 ------------------------------------------------------------------------------
117 ------------------------------------------------------------------------------
120 int_lsf.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
122 ------------------------------------------------------------------------------
126 Word16 lsf_old[], // i : LSF vector at the 4th SF of past frame
127 Word16 lsf_new[], // i : LSF vector at the 4th SF of present frame
128 Word16 i_subfr, // i : Pointer to current sf (equal to 0,40,80 or 120)
129 Word16 lsf_out[] // o : interpolated LSF parameters for current sf
136 for (i = 0; i < M; i++) {
137 lsf_out[i] = add(sub(lsf_old[i], shr(lsf_old[i], 2)),
141 else if ( sub(i_subfr, 40) == 0 )
143 for (i = 0; i < M; i++) {
144 lsf_out[i] = add(shr(lsf_old[i],1), shr(lsf_new[i], 1) );
147 else if ( sub(i_subfr, 80) == 0 )
149 for (i = 0; i < M; i++) {
150 lsf_out[i] = add(shr(lsf_old[i], 2),
151 sub(lsf_new[i], shr(lsf_new[i], 2)));
154 else if ( sub(i_subfr, 120) == 0 )
156 for (i = 0; i < M; i++) {
157 lsf_out[i] = lsf_new[i];
164 ------------------------------------------------------------------------------
166 [State any special notes, constraints or cautions for users of this function]
168 ------------------------------------------------------------------------------
172 Word16 lsf_old[], /* i : LSF vector at the 4th SF of past frame */
173 Word16 lsf_new[], /* i : LSF vector at the 4th SF of present frame */
174 Word16 i_subfr, /* i : Current sf (equal to 0,40,80 or 120) */
175 Word16 lsf_out[], /* o : interpolated LSF parameters for current sf */
176 Flag *pOverflow /* o : flag set if overflow occurs */
180 register Word16 temp1;
181 register Word16 temp2;
185 for (i = M - 1; i >= 0; i--)
187 if (*(lsf_old + i) < 0)
189 temp1 = ~(~(*(lsf_old + i)) >> 2);
193 temp1 = *(lsf_old + i) >> 2;
195 if (*(lsf_new + i) < 0)
197 temp2 = ~(~(*(lsf_new + i)) >> 2);
201 temp2 = *(lsf_new + i) >> 2;
203 *(lsf_out + i) = add_16((Word16)(*(lsf_old + i) - temp1),
209 else if (i_subfr == 40)
211 for (i = M - 1; i >= 0; i--)
213 if (*(lsf_old + i) < 0)
215 temp1 = ~(~(*(lsf_old + i)) >> 1);
219 temp1 = *(lsf_old + i) >> 1;
221 if (*(lsf_new + i) < 0)
223 temp2 = ~(~(*(lsf_new + i)) >> 1);
227 temp2 = *(lsf_new + i) >> 1;
229 *(lsf_out + i) = temp1 + temp2;
233 else if (i_subfr == 80)
235 for (i = M - 1; i >= 0; i--)
237 if (*(lsf_old + i) < 0)
239 temp1 = ~(~(*(lsf_old + i)) >> 2);
243 temp1 = *(lsf_old + i) >> 2;
245 if (*(lsf_new + i) < 0)
247 temp2 = ~(~(*(lsf_new + i)) >> 2);
251 temp2 = *(lsf_new + i) >> 2;
253 *(lsf_out + i) = add_16((Word16)temp1,
254 (Word16)(*(lsf_new + i) - temp2),
260 else if (i_subfr == 120)
262 for (i = M - 1; i >= 0; i--)
264 *(lsf_out + i) = *(lsf_new + i);