source: roaraudio/libroardsp/filter.c @ 1104:bfe959698403

Last change on this file since 1104:bfe959698403 was 1104:bfe959698403, checked in by phi, 15 years ago

disable options needing libm

File size: 5.6 KB
Line 
1//filter.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
27struct _roardsp_filterlist {
28 int id;
29 char * name;
30 int (*  init      )(struct roardsp_filter * filter, struct roar_stream * stream, int id);
31 int (*uninit      )(struct roardsp_filter * filter);
32 int (*ctl         )(struct roardsp_filter * filter, int cmd, void * data);
33 int (*calc  [5][3])(struct roardsp_filter * filter, void * data, size_t samples);
34} _roardsp_filterlist[] = {
35 {ROARDSP_FILTER_AMP, "AMP", roardsp_amp_init, roardsp_amp_uninit, roardsp_amp_ctl, {
36           {NULL, NULL, NULL},{roardsp_amp_calc8, NULL, NULL},{roardsp_amp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
37 {ROARDSP_FILTER_ADD, "Add", roardsp_add_init, roardsp_amp_uninit, roardsp_amp_ctl, {
38           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_add_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
39#ifdef ROAR_HAVE_LIBM
40 {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, {
41           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
42 {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, {
43           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
44#endif
45 {ROARDSP_FILTER_QUANTIFY, "Quantifier", roardsp_quantify_init, NULL, roardsp_quantify_ctl, {
46           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_quantify_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
47 {ROARDSP_FILTER_CLIP, "Clip", roardsp_clip_init, NULL, roardsp_clip_ctl, {
48           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_clip_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
49 {ROARDSP_FILTER_DOWNMIX, "downmix", roardsp_downmix_init, NULL, roardsp_downmix_ctl, {
50           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, roardsp_downmix_calc162},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
51 {ROARDSP_FILTER_DCBLOCK, "DCBlock", roardsp_dcblock_init, NULL, NULL, {
52           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_dcblock_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
53 {-1, NULL, NULL, NULL, NULL, {
54      // ?                  8Bit               16Bit              24Bit              32Bit
55      // 0B:n     1     2   1B:n     1     2   2B:n     1     2   3B:n     1    2    4B:n     1     2
56           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}
57};
58
59int    roardsp_filter_str2id(char * str) {
60 struct _roardsp_filterlist * l = _roardsp_filterlist;
61
62 while ( l->id != -1 ) {
63  if ( strcasecmp(l->name, str) == 0 )
64   return l->id;
65  l++;
66 }
67
68 return -1;
69}
70
71char * roardsp_filter_id2str(int id) {
72 struct _roardsp_filterlist * l = _roardsp_filterlist;
73
74 while ( l->id != -1 ) {
75  if ( l->id == id )
76   return l->name;
77  l++;
78 }
79
80 return NULL;
81}
82
83int roardsp_filter_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
84 struct _roardsp_filterlist * l = _roardsp_filterlist;
85 int bytes;
86 int (*calc)(struct roardsp_filter * filter, void * data, size_t samples) = NULL;
87
88 if ( filter == NULL || stream == NULL ) {
89  ROAR_DBG("roardsp_filter_init(*) = -1 // filter or stream is NULL");
90  return -1;
91 }
92
93 ROAR_DBG("roardsp_filter_init(filter=%p, stream=%p, id=%i) = ?", filter, stream, id);
94
95 memset(filter, 0, sizeof(struct roardsp_filter));
96
97 filter->channels = stream->info.channels;
98 filter->bits     = stream->info.bits;
99 filter->rate     = stream->info.rate;
100
101 bytes            = stream->info.bits / 8;
102
103 while ( l->id != id ) {
104  if ( l->id == -1 )
105   return -1;
106  l++;
107 }
108
109 filter->uninit = l->uninit;
110 filter->ctl    = l->ctl;
111
112 if ( filter->channels < 3 )
113  calc = l->calc[bytes][filter->channels];
114
115 if ( calc == NULL )
116  calc = l->calc[bytes][0]; // for n channels
117
118 if ( calc == NULL ) {
119  ROAR_DBG("roardsp_filter_init(*) = -1 // no calc code");
120  return -1;
121 }
122
123 filter->calc = calc;
124
125 if ( l->init ) {
126  ROAR_DBG("roardsp_filter_init(*) = ? // execing init");
127  return l->init(filter, stream, id);
128 }
129
130 ROAR_DBG("roardsp_filter_init(*) = 0 // no init");
131 return 0;
132}
133
134int roardsp_filter_uninit(struct roardsp_filter * filter) {
135 int ret = 0;
136
137 if ( filter == NULL )
138  return -1;
139
140 if ( filter->uninit )
141  ret = filter->uninit(filter);
142
143 memset(filter, 0, sizeof(struct roardsp_filter));
144
145 return ret;
146}
147
148int roardsp_filter_calc  (struct roardsp_filter * filter, void * data, size_t len) {
149 int ret = 0;
150
151 if ( filter == NULL )
152  return -1;
153
154 if ( filter->calc )
155  ret = filter->calc(filter, data, len);
156
157 return ret;
158}
159
160int    roardsp_filter_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
161 if ( filter == NULL )
162  return -1;
163
164 if ( filter->ctl )
165  return filter->ctl(filter, cmd, data);
166
167 return -1;
168}
169
170//ll
Note: See TracBrowser for help on using the repository browser.