1e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard/* 2e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Copyright 2003-2010, VisualOn, Inc. 3e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 4e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Licensed under the Apache License, Version 2.0 (the "License"); 5e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** you may not use this file except in compliance with the License. 6e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** You may obtain a copy of the License at 7e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 8e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** http://www.apache.org/licenses/LICENSE-2.0 9e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** 10e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** Unless required by applicable law or agreed to in writing, software 11e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** distributed under the License is distributed on an "AS IS" BASIS, 12e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** See the License for the specific language governing permissions and 14e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ** limitations under the License. 15e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard */ 16e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 17e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard/*********************************************************************** 18e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard File: convolve.c 19e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 20e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Description:Perform the convolution between two vectors x[] and h[] 21e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard and write the result in the vector y[] 22e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 23e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard************************************************************************/ 24e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 25e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard#include "typedef.h" 26e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard#include "basic_op.h" 27e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 2884333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber#define UNUSED(x) (void)(x) 2984333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber 30e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgardvoid Convolve ( 31e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 x[], /* (i) : input vector */ 32e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 h[], /* (i) : impulse response */ 33e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 y[], /* (o) : output vector */ 34e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 L /* (i) : vector size */ 35e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard ) 36e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard{ 37e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word32 i, n; 38e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word16 *tmpH,*tmpX; 39e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard Word32 s; 4084333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber UNUSED(L); 4184333e0475bc911adc16417f4ca327c975cf6c36Andreas Huber 42e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard for (n = 0; n < 64;) 43e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 44e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpH = h+n; 45e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpX = x; 46e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i=n+1; 47e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s = vo_mult32((*tmpX++), (*tmpH--));i--; 48e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard while(i>0) 49e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 50e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 51e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 52e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 53e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 54e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i -= 4; 55e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 56b676a05348e4c516fa8b57e33b10548e6142c3f8Mans Rullgard y[n] = ((s<<1) + 0x8000)>>16; 57e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard n++; 58e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 59e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpH = h+n; 60e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpX = x; 61e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i=n+1; 62e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s = vo_mult32((*tmpX++), (*tmpH--));i--; 63e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--));i--; 64e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 65e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard while(i>0) 66e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 67e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 68e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 69e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 70e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 71e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i -= 4; 72e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 73b676a05348e4c516fa8b57e33b10548e6142c3f8Mans Rullgard y[n] = ((s<<1) + 0x8000)>>16; 74e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard n++; 75e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 76e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpH = h+n; 77e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpX = x; 78e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i=n+1; 79e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s = vo_mult32((*tmpX++), (*tmpH--));i--; 80e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--));i--; 81e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--));i--; 82e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 83e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard while(i>0) 84e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 85e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 86e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 87e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 88e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 89e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i -= 4; 90e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 91b676a05348e4c516fa8b57e33b10548e6142c3f8Mans Rullgard y[n] = ((s<<1) + 0x8000)>>16; 92e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard n++; 93e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 94e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s = 0; 95e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpH = h+n; 96e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard tmpX = x; 97e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i=n+1; 98e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard while(i>0) 99e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard { 100e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 101e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 102e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 103e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard s += vo_mult32((*tmpX++), (*tmpH--)); 104e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard i -= 4; 105e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 106b676a05348e4c516fa8b57e33b10548e6142c3f8Mans Rullgard y[n] = ((s<<1) + 0x8000)>>16; 107b676a05348e4c516fa8b57e33b10548e6142c3f8Mans Rullgard n++; 108e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard } 109e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard return; 110e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard} 111e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 112e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 113e2e838afcf03e603a41a0455846eaf9614537c16Mans Rullgard 114