diff options
author | Kevin P. Fleming <kpfleming@digium.com> | 2008-05-21 15:11:48 +0000 |
---|---|---|
committer | Kevin P. Fleming <kpfleming@digium.com> | 2008-05-21 15:11:48 +0000 |
commit | 802b567e6c7ba7803a950324cbed13f7d57944cb (patch) | |
tree | 6b90ca3119aaa2e4073d3b651ac965dea5d3430e /drivers/dahdi/fir.h | |
parent | ec5ce88e015b41c2f46f6c9b783339b945f9502a (diff) |
start copying kernel bits
git-svn-id: http://svn.asterisk.org/svn/dahdi/linux/trunk@4315 a0bf4364-ded3-4de4-8d8a-66a801d63aff
Diffstat (limited to 'drivers/dahdi/fir.h')
-rw-r--r-- | drivers/dahdi/fir.h | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/drivers/dahdi/fir.h b/drivers/dahdi/fir.h new file mode 100644 index 0000000..1722285 --- /dev/null +++ b/drivers/dahdi/fir.h @@ -0,0 +1,130 @@ +/* + * SpanDSP - a series of DSP components for telephony + * + * fir.h - General telephony FIR routines + * + * Written by Steve Underwood <steveu@coppice.org> + * + * Copyright (C) 2002 Steve Underwood + * + * All rights reserved. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * + */ + +#if !defined(_FIR_H_) +#define _FIR_H_ + +typedef struct +{ + int taps; + int curr_pos; + int16_t *coeffs; + int16_t *history; +} fir16_state_t; + +typedef struct +{ + int taps; + int curr_pos; + int32_t *coeffs; + int16_t *history; +} fir32_state_t; + +static inline void fir16_create (fir16_state_t *fir, + int16_t *coeffs, + int taps) +{ + fir->taps = taps; + fir->curr_pos = taps - 1; + fir->coeffs = coeffs; + fir->history = MALLOC (taps*sizeof (int16_t)); + if (fir->history) + memset (fir->history, '\0', taps*sizeof (int16_t)); +} +/*- End of function --------------------------------------------------------*/ + +static inline void fir16_free (fir16_state_t *fir) +{ + FREE (fir->history); +} +/*- End of function --------------------------------------------------------*/ + +static inline int16_t fir16 (fir16_state_t *fir, int16_t sample) +{ + int i; + int offset1; + int offset2; + int32_t y; + + fir->history[fir->curr_pos] = sample; + offset2 = fir->curr_pos + 1; + offset1 = fir->taps - offset2; + y = 0; + for (i = fir->taps - 1; i >= offset1; i--) + y += fir->coeffs[i]*fir->history[i - offset1]; + for ( ; i >= 0; i--) + y += fir->coeffs[i]*fir->history[i + offset2]; + if (fir->curr_pos <= 0) + fir->curr_pos = fir->taps; + fir->curr_pos--; + return y >> 15; +} +/*- End of function --------------------------------------------------------*/ + +static inline void fir32_create (fir32_state_t *fir, + int32_t *coeffs, + int taps) +{ + fir->taps = taps; + fir->curr_pos = taps - 1; + fir->coeffs = coeffs; + fir->history = MALLOC (taps*sizeof (int16_t)); + if (fir->history) + memset (fir->history, '\0', taps*sizeof (int16_t)); +} +/*- End of function --------------------------------------------------------*/ + +static inline void fir32_free (fir32_state_t *fir) +{ + FREE (fir->history); +} +/*- End of function --------------------------------------------------------*/ + +static inline int16_t fir32 (fir32_state_t *fir, int16_t sample) +{ + int i; + int offset1; + int offset2; + int32_t y; + + fir->history[fir->curr_pos] = sample; + offset2 = fir->curr_pos + 1; + offset1 = fir->taps - offset2; + y = 0; + for (i = fir->taps - 1; i >= offset1; i--) + y += fir->coeffs[i]*fir->history[i - offset1]; + for ( ; i >= 0; i--) + y += fir->coeffs[i]*fir->history[i + offset2]; + if (fir->curr_pos <= 0) + fir->curr_pos = fir->taps; + fir->curr_pos--; + return y >> 15; +} +/*- End of function --------------------------------------------------------*/ + +#endif +/*- End of file ------------------------------------------------------------*/ |