1 /*
2 ** Copyright 2003-2010, VisualOn, Inc.
3 **
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
7 **
8 ** http://www.apache.org/licenses/LICENSE-2.0
9 **
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 express or implied.
13 ** See the License for the specific language governing permissions and
14 ** limitations under the License.
15 */
16
17 /***********************************************************************
18 File: convolve.c
19
20 Description:Perform the convolution between two vectors x[] and h[]
21 and write the result in the vector y[]
22
23 ************************************************************************/
24
25 #include "typedef.h"
26 #include "basic_op.h"
27
28 #define UNUSED(x) (void)(x)
29
Convolve(Word16 x[],Word16 h[],Word16 y[],Word16 L)30 void Convolve (
31 Word16 x[], /* (i) : input vector */
32 Word16 h[], /* (i) : impulse response */
33 Word16 y[], /* (o) : output vector */
34 Word16 L /* (i) : vector size */
35 )
36 {
37 Word32 i, n;
38 Word16 *tmpH,*tmpX;
39 Word32 s;
40 UNUSED(L);
41
42 for (n = 0; n < 64;)
43 {
44 tmpH = h+n;
45 tmpX = x;
46 i=n+1;
47 s = vo_mult32((*tmpX++), (*tmpH--));i--;
48 while(i>0)
49 {
50 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
51 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
52 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
53 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
54 i -= 4;
55 }
56 y[n] = voround(L_shl(s, 1));
57 n++;
58
59 tmpH = h+n;
60 tmpX = x;
61 i=n+1;
62 s = vo_mult32((*tmpX++), (*tmpH--));
63 i--;
64 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
65 i--;
66
67 while(i>0)
68 {
69 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
70 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
71 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
72 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
73 i -= 4;
74 }
75 y[n] = voround(L_shl(s, 1));
76 n++;
77
78 tmpH = h+n;
79 tmpX = x;
80 i=n+1;
81 s = vo_mult32((*tmpX++), (*tmpH--));
82 i--;
83 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
84 i--;
85 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
86 i--;
87
88 while(i>0)
89 {
90 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
91 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
92 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
93 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
94 i -= 4;
95 }
96 y[n] = voround(L_shl(s, 1));
97 n++;
98
99 s = 0;
100 tmpH = h+n;
101 tmpX = x;
102 i=n+1;
103 while(i>0)
104 {
105 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
106 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
107 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
108 s = L_add(s, vo_mult32((*tmpX++), (*tmpH--)));
109 i -= 4;
110 }
111 y[n] = voround(L_shl(s, 1));
112 n++;
113 }
114 return;
115 }
116
117
118
119