• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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: lp_dec2.c                                                *
19 *                                                                      *
20 *   Description:Decimate a vector by 2 with 2nd order fir filter   *
21 *                                                                      *
22 ************************************************************************/
23 
24 #include "typedef.h"
25 #include "basic_op.h"
26 #include "cnst.h"
27 
28 #define L_FIR  5
29 #define L_MEM  (L_FIR-2)
30 
31 /* static float h_fir[L_FIR] = {0.13, 0.23, 0.28, 0.23, 0.13}; */
32 /* fixed-point: sum of coef = 32767 to avoid overflow on DC */
33 static Word16 h_fir[L_FIR] = {4260, 7536, 9175, 7536, 4260};
34 
LP_Decim2(Word16 x[],Word16 l,Word16 mem[])35 void LP_Decim2(
36         Word16 x[],                           /* in/out: signal to process         */
37         Word16 l,                             /* input : size of filtering         */
38         Word16 mem[]                          /* in/out: memory (size=3)           */
39           )
40 {
41     Word16 *p_x, x_buf[L_FRAME + L_MEM];
42     Word32 i, j;
43     Word32 L_tmp;
44     /* copy initial filter states into buffer */
45     p_x = x_buf;
46     for (i = 0; i < L_MEM; i++)
47     {
48         *p_x++ = mem[i];
49         mem[i] = x[l - L_MEM + i];
50     }
51     for (i = 0; i < l; i++)
52     {
53         *p_x++ = x[i];
54     }
55     for (i = 0, j = 0; i < l; i += 2, j++)
56     {
57         p_x = &x_buf[i];
58         L_tmp  = ((*p_x++) * h_fir[0]);
59         L_tmp += ((*p_x++) * h_fir[1]);
60         L_tmp += ((*p_x++) * h_fir[2]);
61         L_tmp += ((*p_x++) * h_fir[3]);
62         L_tmp += ((*p_x++) * h_fir[4]);
63         x[j] = (L_tmp + 0x4000)>>15;
64     }
65     return;
66 }
67 
68 
69 
70 
71