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 ****************************************************************************************/
33 ------------------------------------------------------------------------------
36 /*----------------------------------------------------------------------------
38 ----------------------------------------------------------------------------*/
43 /*----------------------------------------------------------------------------
45 ; Define module specific macros here
46 ----------------------------------------------------------------------------*/
48 /*----------------------------------------------------------------------------
50 ; Include all pre-processor statements here. Include conditional
51 ; compile variables also.
52 ----------------------------------------------------------------------------*/
54 /*----------------------------------------------------------------------------
55 ; LOCAL FUNCTION DEFINITIONS
56 ; Function Prototype declaration
57 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
60 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
61 ; Variable declaration - defined here and used outside this module
62 ----------------------------------------------------------------------------*/
66 ------------------------------------------------------------------------------
68 ------------------------------------------------------------------------------
69 INPUT AND OUTPUT DEFINITIONS
72 coef_ptr = pointer to buffer containing the prediction coefficients
73 input_ptr = pointer to buffer containing the speech signal
74 input_len = filter order
75 residual_ptr = pointer to buffer of residual signal
78 residual_ptr buffer contains the newly calculated the residual signal
83 Global Variables Used:
86 Local Variables Needed:
89 ------------------------------------------------------------------------------
92 This function computes the LP residual by filtering the input speech through
93 the LP inverse filter A(z).
95 ------------------------------------------------------------------------------
100 ------------------------------------------------------------------------------
103 residu.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
105 ------------------------------------------------------------------------------
108 Note: Input argument names were changed to be more descriptive. Shown below
109 are the original names. Shown below are the name changes:
112 y[] <--> residual_ptr[]
117 Word16 a[], // (i) : prediction coefficients
118 Word16 x[], // (i) : speech signal
119 Word16 y[], // (o) : residual signal
120 Word16 lg // (i) : size of filtering
126 for (i = 0; i < lg; i++)
128 s = L_mult (x[i], a[0]);
129 for (j = 1; j <= M; j++)
131 s = L_mac (s, a[j], x[i - j]);
139 ------------------------------------------------------------------------------
141 [State any special notes, constraints or cautions for users of this function]
143 ------------------------------------------------------------------------------
146 OSCL_EXPORT_REF void Residu(
147 Word16 coef_ptr[], /* (i) : prediction coefficients*/
148 Word16 input_ptr[], /* (i) : speech signal */
149 Word16 residual_ptr[], /* (o) : residual signal */
150 Word16 input_len /* (i) : size of filtering */
155 register Word16 i, j;
165 Word16 *p_residual_ptr = &residual_ptr[input_len-1];
166 Word16 *p_input_ptr = &input_ptr[input_len-1-M];
168 for (i = input_len >> 2; i != 0; i--)
174 p_coef = &coef_ptr[M];
175 p_input1 = p_input_ptr--;
176 p_input2 = p_input_ptr--;
177 p_input3 = p_input_ptr--;
178 p_input4 = p_input_ptr--;
180 for (j = M >> 1; j != 0; j--)
182 s1 += ((Word32) * (p_coef) * *(p_input1++));
183 s2 += ((Word32) * (p_coef) * *(p_input2++));
184 s3 += ((Word32) * (p_coef) * *(p_input3++));
185 s4 += ((Word32) * (p_coef--) * *(p_input4++));
186 s1 += ((Word32) * (p_coef) * *(p_input1++));
187 s2 += ((Word32) * (p_coef) * *(p_input2++));
188 s3 += ((Word32) * (p_coef) * *(p_input3++));
189 s4 += ((Word32) * (p_coef--) * *(p_input4++));
192 s1 += (((Word32) * (p_coef)) * *(p_input1));
193 s2 += (((Word32) * (p_coef)) * *(p_input2));
194 s3 += (((Word32) * (p_coef)) * *(p_input3));
195 s4 += (((Word32) * (p_coef)) * *(p_input4));
197 *(p_residual_ptr--) = (Word16)(s1 >> 12);
198 *(p_residual_ptr--) = (Word16)(s2 >> 12);
199 *(p_residual_ptr--) = (Word16)(s3 >> 12);
200 *(p_residual_ptr--) = (Word16)(s4 >> 12);