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 Filename: convolve.cpp
36 ------------------------------------------------------------------------------
39 /*----------------------------------------------------------------------------
41 ----------------------------------------------------------------------------*/
46 /*----------------------------------------------------------------------------
48 ; Define module specific macros here
49 ----------------------------------------------------------------------------*/
52 /*----------------------------------------------------------------------------
54 ; Include all pre-processor statements here. Include conditional
55 ; compile variables also.
56 ----------------------------------------------------------------------------*/
59 /*----------------------------------------------------------------------------
60 ; LOCAL FUNCTION DEFINITIONS
61 ; Function Prototype declaration
62 ----------------------------------------------------------------------------*/
64 /*----------------------------------------------------------------------------
65 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
66 ; Variable declaration - defined here and used outside this module
67 ----------------------------------------------------------------------------*/
71 ------------------------------------------------------------------------------
72 FUNCTION NAME: Convolve
73 ------------------------------------------------------------------------------
74 INPUT AND OUTPUT DEFINITIONS
77 x = pointer to input vector of L elements of type Word16
78 h = pointer to the filter's impulse response vector of L elements
80 y = pointer to the output vector of L elements of type Word16 used for
81 storing the convolution of x and h;
82 L = Length of the convolution; type definition is Word16
85 y buffer contains the new convolution output
90 Global Variables Used:
93 Local Variables Needed:
96 ------------------------------------------------------------------------------
99 Perform the convolution between two vectors x[] and h[] and write the result
100 in the vector y[]. All vectors are of length L and only the first L samples
101 of the convolution are computed.
103 The convolution is given by:
105 y[n] = sum_{i=0}^{n} x[i] h[n-i], n=0,...,L-1
107 ------------------------------------------------------------------------------
112 ------------------------------------------------------------------------------
115 convolve.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
117 ------------------------------------------------------------------------------
121 Word16 x[], // (i) : input vector
122 Word16 h[], // (i) : impulse response
123 Word16 y[], // (o) : output vector
124 Word16 L // (i) : vector size
130 for (n = 0; n < L; n++)
133 for (i = 0; i <= n; i++)
135 s = L_mac (s, x[i], h[n - i]);
138 y[n] = extract_h (s); move16 ();
144 ------------------------------------------------------------------------------
146 [State any special notes, constraints or cautions for users of this function]
148 ------------------------------------------------------------------------------
152 Word16 x[], /* (i) : input vector */
153 Word16 h[], /* (i) : impulse response */
154 Word16 y[], /* (o) : output vector */
155 Word16 L /* (i) : vector size */
158 register Word16 i, n;
162 for (n = 1; n < L; n = n + 2)
167 s2 = ((Word32) * (x)) * *(h--);
168 s1 = ((Word32) * (x++)) * *(h);
170 for (i = (n - 1) >> 1; i != 0; i--)
172 s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h--), s2);
173 s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (x++), (Word32) * (h), s1);
174 s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h--), s2);
175 s1 = amrnb_fxp_mac_16_by_16bb((Word32) * (x++), (Word32) * (h), s1);
178 s2 = amrnb_fxp_mac_16_by_16bb((Word32) * (x), (Word32) * (h), s2);
180 *(y++) = (Word16)(s1 >> 12);
181 *(y++) = (Word16)(s2 >> 12);