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