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 ****************************************************************************************/
31 Pathname: ./audio/gsm-amr/c/src/residu.c
33 ------------------------------------------------------------------------------
36 Description: Updated template used to PV coding template. First attempt at
39 Description: Deleted stores listed in the Local Stores Needed/Modified
42 Description: Updated file per comments gathered from Phase 2/3 review.
44 Description: Updating to reflect variable name changes made in residu.asm
46 Description: Synchronized file with UMTS version 3.2.0. Updated coding
47 template. Removed unnecessary include files.
49 Description: Made the following changes per comments from Phase 2/3 review:
50 1. Modified FOR loops to count down.
51 2. Fixed typecasting issue with TI C compiler.
53 Description: Made the following changes
54 1. Unrolled the convolutional loop.
55 2. Performed 4 convolution per pass to avoid recalling the same
56 filter coefficient as many times.
57 2. Eliminated math operations that check for saturation.
59 Description: Replaced "int" and/or "char" with OSCL defined types.
61 Description: Changed round function name to pv_round to avoid conflict with
62 round function in C standard library.
67 ------------------------------------------------------------------------------
70 /*----------------------------------------------------------------------------
72 ----------------------------------------------------------------------------*/
77 /*----------------------------------------------------------------------------
79 ; Define module specific macros here
80 ----------------------------------------------------------------------------*/
82 /*----------------------------------------------------------------------------
84 ; Include all pre-processor statements here. Include conditional
85 ; compile variables also.
86 ----------------------------------------------------------------------------*/
88 /*----------------------------------------------------------------------------
89 ; LOCAL FUNCTION DEFINITIONS
90 ; Function Prototype declaration
91 ----------------------------------------------------------------------------*/
93 /*----------------------------------------------------------------------------
94 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
95 ; Variable declaration - defined here and used outside this module
96 ----------------------------------------------------------------------------*/
100 ------------------------------------------------------------------------------
101 FUNCTION NAME: Residu
102 ------------------------------------------------------------------------------
103 INPUT AND OUTPUT DEFINITIONS
106 coef_ptr = pointer to buffer containing the prediction coefficients
107 input_ptr = pointer to buffer containing the speech signal
108 input_len = filter order
109 residual_ptr = pointer to buffer of residual signal
112 residual_ptr buffer contains the newly calculated the residual signal
117 Global Variables Used:
120 Local Variables Needed:
123 ------------------------------------------------------------------------------
126 This function computes the LP residual by filtering the input speech through
127 the LP inverse filter A(z).
129 ------------------------------------------------------------------------------
134 ------------------------------------------------------------------------------
137 residu.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
139 ------------------------------------------------------------------------------
142 Note: Input argument names were changed to be more descriptive. Shown below
143 are the original names. Shown below are the name changes:
146 y[] <--> residual_ptr[]
151 Word16 a[], // (i) : prediction coefficients
152 Word16 x[], // (i) : speech signal
153 Word16 y[], // (o) : residual signal
154 Word16 lg // (i) : size of filtering
160 for (i = 0; i < lg; i++)
162 s = L_mult (x[i], a[0]);
163 for (j = 1; j <= M; j++)
165 s = L_mac (s, a[j], x[i - j]);
173 ------------------------------------------------------------------------------
174 RESOURCES USED [optional]
176 When the code is written for a specific target processor the
177 the resources used should be documented below.
179 HEAP MEMORY USED: x bytes
181 STACK MEMORY USED: x bytes
183 CLOCK CYCLES: (cycle count equation for this function) + (variable
184 used to represent cycle count for each subroutine
186 where: (cycle count variable) = cycle count for [subroutine
189 ------------------------------------------------------------------------------
191 [State any special notes, constraints or cautions for users of this function]
193 ------------------------------------------------------------------------------
197 Word16 coef_ptr[], /* (i) : prediction coefficients*/
198 Word16 input_ptr[], /* (i) : speech signal */
199 Word16 residual_ptr[], /* (o) : residual signal */
200 Word16 input_len /* (i) : size of filtering */
205 register Word16 i, j;
215 Word16 *p_residual_ptr = &residual_ptr[input_len-1];
216 Word16 *p_input_ptr = &input_ptr[input_len-1-M];
218 for (i = input_len >> 2; i != 0; i--)
224 p_coef = &coef_ptr[M];
225 p_input1 = p_input_ptr--;
226 p_input2 = p_input_ptr--;
227 p_input3 = p_input_ptr--;
228 p_input4 = p_input_ptr--;
230 for (j = M >> 1; j != 0; j--)
232 s1 += ((Word32) * (p_coef) * *(p_input1++));
233 s2 += ((Word32) * (p_coef) * *(p_input2++));
234 s3 += ((Word32) * (p_coef) * *(p_input3++));
235 s4 += ((Word32) * (p_coef--) * *(p_input4++));
236 s1 += ((Word32) * (p_coef) * *(p_input1++));
237 s2 += ((Word32) * (p_coef) * *(p_input2++));
238 s3 += ((Word32) * (p_coef) * *(p_input3++));
239 s4 += ((Word32) * (p_coef--) * *(p_input4++));
242 s1 += (((Word32) * (p_coef)) * *(p_input1));
243 s2 += (((Word32) * (p_coef)) * *(p_input2));
244 s3 += (((Word32) * (p_coef)) * *(p_input3));
245 s4 += (((Word32) * (p_coef)) * *(p_input4));
247 *(p_residual_ptr--) = (Word16)(s1 >> 12);
248 *(p_residual_ptr--) = (Word16)(s2 >> 12);
249 *(p_residual_ptr--) = (Word16)(s3 >> 12);
250 *(p_residual_ptr--) = (Word16)(s4 >> 12);