convolve.c revision f3664ae9369a861ffbc2354e8e93e48983802062
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 28void Convolve ( 29 Word16 x[], /* (i) : input vector */ 30 Word16 h[], /* (i) : impulse response */ 31 Word16 y[], /* (o) : output vector */ 32 Word16 L /* (i) : vector size */ 33 ) 34{ 35 Word32 i, n; 36 Word16 *tmpH,*tmpX; 37 Word32 s; 38 for (n = 0; n < 64;) 39 { 40 tmpH = h+n; 41 tmpX = x; 42 i=n+1; 43 s = vo_mult32((*tmpX++), (*tmpH--));i--; 44 while(i>0) 45 { 46 s += vo_mult32((*tmpX++), (*tmpH--)); 47 s += vo_mult32((*tmpX++), (*tmpH--)); 48 s += vo_mult32((*tmpX++), (*tmpH--)); 49 s += vo_mult32((*tmpX++), (*tmpH--)); 50 i -= 4; 51 } 52 y[n] = ((s<<1) + 0x8000)>>16; 53 n++; 54 55 tmpH = h+n; 56 tmpX = x; 57 i=n+1; 58 s = vo_mult32((*tmpX++), (*tmpH--));i--; 59 s += vo_mult32((*tmpX++), (*tmpH--));i--; 60 61 while(i>0) 62 { 63 s += vo_mult32((*tmpX++), (*tmpH--)); 64 s += vo_mult32((*tmpX++), (*tmpH--)); 65 s += vo_mult32((*tmpX++), (*tmpH--)); 66 s += vo_mult32((*tmpX++), (*tmpH--)); 67 i -= 4; 68 } 69 y[n] = ((s<<1) + 0x8000)>>16; 70 n++; 71 72 tmpH = h+n; 73 tmpX = x; 74 i=n+1; 75 s = vo_mult32((*tmpX++), (*tmpH--));i--; 76 s += vo_mult32((*tmpX++), (*tmpH--));i--; 77 s += vo_mult32((*tmpX++), (*tmpH--));i--; 78 79 while(i>0) 80 { 81 s += vo_mult32((*tmpX++), (*tmpH--)); 82 s += vo_mult32((*tmpX++), (*tmpH--)); 83 s += vo_mult32((*tmpX++), (*tmpH--)); 84 s += vo_mult32((*tmpX++), (*tmpH--)); 85 i -= 4; 86 } 87 y[n] = ((s<<1) + 0x8000)>>16; 88 n++; 89 90 s = 0; 91 tmpH = h+n; 92 tmpX = x; 93 i=n+1; 94 while(i>0) 95 { 96 s += vo_mult32((*tmpX++), (*tmpH--)); 97 s += vo_mult32((*tmpX++), (*tmpH--)); 98 s += vo_mult32((*tmpX++), (*tmpH--)); 99 s += vo_mult32((*tmpX++), (*tmpH--)); 100 i -= 4; 101 } 102 y[n] = ((s<<1) + 0x8000)>>16; 103 n++; 104 } 105 return; 106} 107 108 109 110