]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - ep-processor-libraries/dsplib.git/blob - ti/dsplib/src/DSP_fir_r8/c64P/DSP_fir_r8_cn.c
DSPLIB: optimized signal processing functions for TI DSPs
[ep-processor-libraries/dsplib.git] / ti / dsplib / src / DSP_fir_r8 / c64P / DSP_fir_r8_cn.c
1 /* ======================================================================= */
2 /* DSP_fir_r8_cn.c -- FIR Filter (Radix 8)                                 */
3 /*                    Natural C Implementation                             */
4 /*                                                                         */
5 /* Rev 0.0.1                                                               */
6 /*                                                                         */
7 /*  Usage                                                                  */
8 /*     This routine is C-callable and can be called as:                    */
9 /*                                                                         */
10 /*     void DSP_fir_r8_cn (                                                */
11 /*         const short *restrict x,                                        */
12 /*         const short *restrict h,                                        */
13 /*         short *restrict r,                                              */
14 /*         int nh,                                                         */
15 /*         int nr,                                                         */
16 /*     )                                                                   */
17 /*                                                                         */
18 /*  Description                                                            */
19 /*     Computes a real FIR filter (direct-form) using coefficients         */
20 /*     stored in vector h.  The real data input is stored in vector x.     */
21 /*     The filter output result is stored in vector r.  Input data and     */
22 /*     filter taps are 16-bit, with intermediate values kept at 32-bit     */
23 /*     precision.  Filter taps are expected in Q15 format.                 */
24 /*                                                                         */
25 /*  Assumptions                                                            */
26 /*     Arrays x, h, and r do not overlap                                   */
27 /*                                                                         */
28 /* Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/  */ 
29 /*                                                                         */
30 /*                                                                         */
31 /*  Redistribution and use in source and binary forms, with or without     */
32 /*  modification, are permitted provided that the following conditions     */
33 /*  are met:                                                               */
34 /*                                                                         */
35 /*    Redistributions of source code must retain the above copyright       */
36 /*    notice, this list of conditions and the following disclaimer.        */
37 /*                                                                         */
38 /*    Redistributions in binary form must reproduce the above copyright    */
39 /*    notice, this list of conditions and the following disclaimer in the  */
40 /*    documentation and/or other materials provided with the               */
41 /*    distribution.                                                        */
42 /*                                                                         */
43 /*    Neither the name of Texas Instruments Incorporated nor the names of  */
44 /*    its contributors may be used to endorse or promote products derived  */
45 /*    from this software without specific prior written permission.        */
46 /*                                                                         */
47 /*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS    */
48 /*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT      */
49 /*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR  */
50 /*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT   */
51 /*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,  */
52 /*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT       */
53 /*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,  */
54 /*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY  */
55 /*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT    */
56 /*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE  */
57 /*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.   */
58 /*                                                                         */
59 /* ======================================================================= */
61 #pragma CODE_SECTION(DSP_fir_r8_cn, ".text:ansi");
63 #include "DSP_fir_r8_cn.h"
65 void DSP_fir_r8_cn (
66     const short *restrict x,    /* Input array [nr+nh-1 elements] */
67     const short *restrict h,    /* Coeff array [nh elements]      */
68     short       *restrict r,    /* Output array [nr elements]     */
69     int nh,                     /* Number of coefficients         */
70     int nr                      /* Number of output samples       */
71 )
72 {
73     int i, j, sum;
75 #ifndef NOASSUME
76     _nassert(nr % 4 == 0);
77     _nassert(nr >= 4);
78 #endif
79     for (j = 0; j < nr; j++) {
80         sum = 0;
81 #ifndef NOASSUME
82         _nassert(nh % 8 == 0);
83         _nassert(nh >= 8);
84 #endif
85         for (i = 0; i < nh; i++)
86             sum += x[i + j] * h[i];
87         r[j] = sum >> 15;
88     }
89 }
91 /* ======================================================================= */
92 /*  End of file:  DSP_fir_r8_cn.c                                          */
93 /* ----------------------------------------------------------------------- */
94 /*            Copyright (c) 2011 Texas Instruments, Incorporated.          */
95 /*                           All Rights Reserved.                          */
96 /* ======================================================================= */