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 ****************************************************************************************/
32 ------------------------------------------------------------------------------
35 /*----------------------------------------------------------------------------
37 ----------------------------------------------------------------------------*/
41 /*----------------------------------------------------------------------------
43 ; Define module specific macros here
44 ----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------
48 ; Include all pre-processor statements here. Include conditional
49 ; compile variables also.
50 ----------------------------------------------------------------------------*/
52 #define L_INTER10 (L_INTERPOL-1)
53 #define FIR_SIZE (UP_SAMP_MAX*L_INTER10+1)
55 /*----------------------------------------------------------------------------
56 ; LOCAL FUNCTION DEFINITIONS
57 ; Function Prototype declaration
58 ----------------------------------------------------------------------------*/
60 /*----------------------------------------------------------------------------
61 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
62 ; Variable declaration - defined here and used outside this module
63 ----------------------------------------------------------------------------*/
65 /* 1/6 resolution interpolation filter (-3 dB at 3600 Hz) */
66 /* Note: the 1/3 resolution filter is simply a subsampled
67 * version of the 1/6 resolution filter, i.e. it uses
68 * every second coefficient:
70 * inter_3l[k] = inter_6[2*k], 0 <= k <= 3*L_INTER10
73 const Word16 inter_6_pred_lt[FIR_SIZE] =
76 28346, 25207, 20449, 14701, 8693, 3143,
77 -1352, -4402, -5865, -5850, -4673, -2783,
78 -672, 1211, 2536, 3130, 2991, 2259,
79 1170, 0, -1001, -1652, -1868, -1666,
80 -1147, -464, 218, 756, 1060, 1099,
81 904, 550, 135, -245, -514, -634,
82 -602, -451, -231, 0, 191, 308,
83 340, 296, 198, 78, -36, -120,
84 -163, -165, -132, -79, -19, 34,
90 ------------------------------------------------------------------------------
91 FUNCTION NAME: Pred_lt_3or6
92 ------------------------------------------------------------------------------
93 INPUT AND OUTPUT DEFINITIONS
96 exc = buffer containing the excitation (Word16)
97 T0 = integer pitch lag (Word16)
98 frac = fraction of lag (Word16)
99 L_subfr = number of samples per subframe (Word16)
100 flag3 = flag to indicate the upsampling rate; if set, upsampling
101 rate is 3, otherwise, upsampling rate is 6 (Word16)
103 pOverflow = pointer to overflow (Flag)
109 exc buffer contains the newly formed adaptive codebook excitation
110 pOverflow -> 1 if the add operation resulted in overflow
112 Global Variables Used:
113 inter_6_pred_lt = (1/6) resolution interpolation filter table (Word16)
115 Local Variables Needed:
118 ------------------------------------------------------------------------------
121 This function computes the result of long term prediction with fractional
122 interpolation of resolution 1/3 or 1/6. (Interpolated past excitation).
124 The past excitation signal at the given delay is interpolated at
125 the given fraction to build the adaptive codebook excitation.
126 On return exc[0..L_subfr-1] contains the interpolated signal
127 (adaptive codebook excitation).
129 ------------------------------------------------------------------------------
134 ------------------------------------------------------------------------------
137 pred_lt.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
139 ------------------------------------------------------------------------------
143 Word16 exc[], // in/out: excitation buffer
144 Word16 T0, // input : integer pitch lag
145 Word16 frac, // input : fraction of lag
146 Word16 L_subfr, // input : subframe size
147 Word16 flag3 // input : if set, upsampling rate = 3 (6 otherwise)
151 Word16 *pX0, *pX1, *pX2;
152 const Word16 *pC1, *pC2;
157 frac = negate (frac);
160 frac = shl (frac, 1); // inter_3l[k] = inter_6[2*k] -> k' = 2*k
165 frac = add (frac, UP_SAMP_MAX);
169 for (j = 0; j < L_subfr; j++)
173 pC1 = &inter_6[frac];
174 pC2 = &inter_6[sub (UP_SAMP_MAX, frac)];
177 for (i = 0, k = 0; i < L_INTER10; i++, k += UP_SAMP_MAX)
179 s = L_mac (s, pX1[-i], pC1[k]);
180 s = L_mac (s, pX2[i], pC2[k]);
183 exc[j] = pv_round (s);
189 ------------------------------------------------------------------------------
191 [State any special notes, constraints or cautions for users of this function]
193 ------------------------------------------------------------------------------
196 OSCL_EXPORT_REF void Pred_lt_3or6(
197 Word16 exc[], /* in/out: excitation buffer */
198 Word16 T0, /* input : integer pitch lag */
199 Word16 frac, /* input : fraction of lag */
200 Word16 L_subfr, /* input : subframe size */
201 Word16 flag3, /* input : if set, upsampling rate = 3 (6 otherwise) */
202 Flag *pOverflow /* output: if set, overflow occurred in this function */
214 const Word16 *pC1_ref;
215 const Word16 *pC2_ref;
217 Word16 Coeff_1[(L_INTER10<<1)];
221 OSCL_UNUSED_ARG(pOverflow);
225 /* frac goes between -3 and 3 */
231 frac <<= 1; /* inter_3l[k] = inter_6[2*k] -> k' = 2*k */
240 pC1_ref = &inter_6_pred_lt[frac];
241 pC2_ref = &inter_6_pred_lt[UP_SAMP_MAX-frac];
248 for (i = L_INTER10 >> 1; i > 0; i--)
250 *(pC1++) = pC1_ref[k];
251 *(pC1++) = pC2_ref[k];
253 *(pC1++) = pC1_ref[k];
254 *(pC1++) = pC2_ref[k];
261 for (j = (L_subfr >> 1); j != 0 ; j--)
272 for (i = L_INTER10 >> 1; i > 0; i--)
274 s2 += ((Word32) * (pX3--)) * *(pC1);
275 s1 += ((Word32) * (pX3)) * *(pC1++);
276 s1 += ((Word32) * (pX2++)) * *(pC1);
277 s2 += ((Word32) * (pX2)) * *(pC1++);
278 s2 += ((Word32) * (pX3--)) * *(pC1);
279 s1 += ((Word32) * (pX3)) * *(pC1++);
280 s1 += ((Word32) * (pX2++)) * *(pC1);
281 s2 += ((Word32) * (pX2)) * *(pC1++);
283 } /* for (i = L_INTER10>>1; i > 0; i--) */
285 *(p_exc++) = (Word16)(s1 >> 15);
286 *(p_exc++) = (Word16)(s2 >> 15);
288 } /* for (j = (L_subfr>>1); j != 0 ; j--) */