2
* SpanDSP - a series of DSP components for telephony
4
* fir.h - General telephony FIR routines
6
* Written by Steve Underwood <steveu@coppice.org>
8
* Copyright (C) 2002 Steve Underwood
10
* All rights reserved.
12
* This program is free software; you can redistribute it and/or modify
13
* it under the terms of the GNU General Public License as published by
14
* the Free Software Foundation; either version 2 of the License, or
15
* (at your option) any later version.
17
* This program is distributed in the hope that it will be useful,
18
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
* GNU General Public License for more details.
22
* You should have received a copy of the GNU General Public License
23
* along with this program; if not, write to the Free Software
24
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
47
static inline void fir16_create (fir16_state_t *fir,
52
fir->curr_pos = taps - 1;
54
fir->history = MALLOC (taps*sizeof (int16_t));
56
memset (fir->history, '\0', taps*sizeof (int16_t));
58
/*- End of function --------------------------------------------------------*/
60
static inline void fir16_free (fir16_state_t *fir)
64
/*- End of function --------------------------------------------------------*/
66
static inline int16_t fir16 (fir16_state_t *fir, int16_t sample)
73
fir->history[fir->curr_pos] = sample;
74
offset2 = fir->curr_pos + 1;
75
offset1 = fir->taps - offset2;
77
for (i = fir->taps - 1; i >= offset1; i--)
78
y += fir->coeffs[i]*fir->history[i - offset1];
80
y += fir->coeffs[i]*fir->history[i + offset2];
81
if (fir->curr_pos <= 0)
82
fir->curr_pos = fir->taps;
86
/*- End of function --------------------------------------------------------*/
88
static inline void fir32_create (fir32_state_t *fir,
93
fir->curr_pos = taps - 1;
95
fir->history = MALLOC (taps*sizeof (int16_t));
97
memset (fir->history, '\0', taps*sizeof (int16_t));
99
/*- End of function --------------------------------------------------------*/
101
static inline void fir32_free (fir32_state_t *fir)
105
/*- End of function --------------------------------------------------------*/
107
static inline int16_t fir32 (fir32_state_t *fir, int16_t sample)
114
fir->history[fir->curr_pos] = sample;
115
offset2 = fir->curr_pos + 1;
116
offset1 = fir->taps - offset2;
118
for (i = fir->taps - 1; i >= offset1; i--)
119
y += fir->coeffs[i]*fir->history[i - offset1];
121
y += fir->coeffs[i]*fir->history[i + offset2];
122
if (fir->curr_pos <= 0)
123
fir->curr_pos = fir->taps;
127
/*- End of function --------------------------------------------------------*/
130
/*- End of file ------------------------------------------------------------*/