comparison spandsp-0.0.6pre17/src/complex_filters.c @ 4:26cd8f1ef0b1

import spandsp-0.0.6pre17
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Fri, 25 Jun 2010 15:50:58 +0200
parents
children
comparison
equal deleted inserted replaced
3:c6c5a16ce2f2 4:26cd8f1ef0b1
1 /*
2 * SpanDSP - a series of DSP components for telephony
3 *
4 * complex_filters.c
5 *
6 * Written by Steve Underwood <steveu@coppice.org>
7 *
8 * Copyright (C) 2003 Steve Underwood
9 *
10 * All rights reserved.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 2.1,
14 * as published by the Free Software Foundation.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
20 *
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *
25 * $Id: complex_filters.c,v 1.16 2009/02/03 16:28:39 steveu Exp $
26 */
27
28 #if defined(HAVE_CONFIG_H)
29 #include "config.h"
30 #endif
31
32 #include <stdlib.h>
33 #include <stdio.h>
34 #include <inttypes.h>
35
36 #include "spandsp/telephony.h"
37 #include "spandsp/complex.h"
38 #include "spandsp/complex_filters.h"
39
40 SPAN_DECLARE(filter_t *) filter_create(fspec_t *fs)
41 {
42 int i;
43 filter_t *fi;
44
45 if ((fi = (filter_t *) malloc(sizeof(*fi) + sizeof(float)*(fs->np + 1))))
46 {
47 fi->fs = fs;
48 fi->sum = 0.0;
49 /* Moving average filters only */
50 fi->ptr = 0;
51 for (i = 0; i <= fi->fs->np; i++)
52 fi->v[i] = 0.0;
53 }
54 return fi;
55 }
56 /*- End of function --------------------------------------------------------*/
57
58 SPAN_DECLARE(void) filter_delete(filter_t *fi)
59 {
60 if (fi)
61 free(fi);
62 }
63 /*- End of function --------------------------------------------------------*/
64
65 SPAN_DECLARE(float) filter_step(filter_t *fi, float x)
66 {
67 return fi->fs->fsf(fi, x);
68 }
69 /*- End of function --------------------------------------------------------*/
70
71 SPAN_DECLARE(cfilter_t *) cfilter_create(fspec_t *fs)
72 {
73 cfilter_t *cfi;
74
75 if ((cfi = (cfilter_t *) malloc(sizeof(*cfi))))
76 {
77 if ((cfi->ref = filter_create(fs)) == NULL)
78 {
79 free(cfi);
80 return NULL;
81 }
82 if ((cfi->imf = filter_create(fs)) == NULL)
83 {
84 free(cfi->ref);
85 free(cfi);
86 return NULL;
87 }
88 }
89 return cfi;
90 }
91 /*- End of function --------------------------------------------------------*/
92
93 SPAN_DECLARE(void) cfilter_delete(cfilter_t *cfi)
94 {
95 if (cfi)
96 {
97 filter_delete(cfi->ref);
98 filter_delete(cfi->imf);
99 }
100 }
101 /*- End of function --------------------------------------------------------*/
102
103 SPAN_DECLARE(complexf_t) cfilter_step(cfilter_t *cfi, const complexf_t *z)
104 {
105 complexf_t cc;
106
107 cc.re = filter_step(cfi->ref, z->re);
108 cc.im = filter_step(cfi->imf, z->im);
109 return cc;
110 }
111 /*- End of function --------------------------------------------------------*/
112 /*- End of file ------------------------------------------------------------*/

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.