source: roaraudio/libroardsp/filterchain.c @ 3327:3ff4287ec9f7

Last change on this file since 3327:3ff4287ec9f7 was 1131:bca464362519, checked in by phi, 15 years ago

added support to reset a filter(chain) :), works only for dcblock at the moment :(

File size: 2.6 KB
Line 
1//filterchain.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - August 2008
5 *
6 *  This file is part of libroardsp a part of RoarAudio,
7 *  a cross-platform sound system for both, home and professional use.
8 *  See README for details.
9 *
10 *  This file is free software; you can redistribute it and/or modify
11 *  it under the terms of the GNU General Public License version 3
12 *  as published by the Free Software Foundation.
13 *
14 *  libroardsp is distributed in the hope that it will be useful,
15 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 *  GNU General Public License for more details.
18 *
19 *  You should have received a copy of the GNU General Public License
20 *  along with this software; see the file COPYING.  If not, write to
21 *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
22 *
23 */
24
25#include "libroardsp.h"
26
27int roardsp_fchain_init  (struct roardsp_filterchain * chain) {
28 if ( chain == NULL )
29  return -1;
30
31 memset((void*)chain, 0, sizeof(struct roardsp_filterchain));
32 return 0;
33}
34
35int roardsp_fchain_uninit(struct roardsp_filterchain * chain) {
36 int i;
37 int ret = 0;
38
39 if ( chain == NULL )
40  return -1;
41
42 for (i = 0; i < chain->filters; i++) {
43  if ( roardsp_filter_uninit(chain->filter[i]) == -1 )
44   ret = -1;
45 }
46
47 if ( roardsp_fchain_init(chain) == -1 )
48  ret = -1;
49
50 return ret;
51}
52
53int roardsp_fchain_add   (struct roardsp_filterchain * chain, struct roardsp_filter * filter) {
54 if ( chain == NULL )
55  return -1;
56
57 if ( chain->filters < ROARDSP_MAX_FILTERS_PER_CHAIN ) {
58  chain->filter[chain->filters++] = filter;
59  return 0;
60 }
61
62 return -1;
63}
64
65int roardsp_fchain_calc  (struct roardsp_filterchain * chain, void * data, size_t len) {
66 int i;
67 int ret = 0;
68
69 if ( chain == NULL )
70  return -1;
71
72 for (i = 0; i < chain->filters; i++) {
73  if ( roardsp_filter_calc(chain->filter[i], data, len) == -1 )
74   ret = -1;
75 }
76
77 return ret;
78}
79
80int roardsp_fchain_reset (struct roardsp_filterchain * chain, int what) {
81 int i;
82 int ret = 0;
83/*
84 struct roardsp_filterchain backup[1];
85*/
86
87 if ( chain == NULL )
88  return -1;
89
90/*
91 if ( what == ROARDSP_RESET_FULL ) {
92  if ( roardsp_fchain_init(backup) == -1 )
93   return -1;
94
95  if ( roardsp_fchain_uninit(chain) == -1 )
96   return -1;
97
98  if ( roardsp_fchain_init(chain) == -1 )
99   return -1;
100 } else {
101*/
102  for (i = 0; i < chain->filters; i++) {
103   if ( roardsp_filter_reset(chain->filter[i], what) == -1 )
104    ret = -1;
105  }
106/*
107 }
108*/
109
110 return ret;
111}
112
113int roardsp_fchain_num   (struct roardsp_filterchain * chain) {
114 if ( chain == NULL )
115  return -1;
116
117 return chain->filters;
118}
119
120//ll
Note: See TracBrowser for help on using the repository browser.