source: roaraudio/libroardsp/filter.c @ 683:61cb5393b9a5

Last change on this file since 683:61cb5393b9a5 was 683:61cb5393b9a5, checked in by phi, 16 years ago

added code for highp, seem not to work

File size: 4.5 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", NULL, NULL, NULL, {
36           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
37 {ROARDSP_FILTER_LOWP, "Lowpass", roardsp_lowp_init, roardsp_lowp_uninit, roardsp_lowp_ctl, {
38           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_lowp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
39 {ROARDSP_FILTER_HIGHP, "Highpass", roardsp_highp_init, roardsp_highp_uninit, roardsp_highp_ctl, {
40           {NULL, NULL, NULL},{NULL, NULL, NULL},{roardsp_highp_calc16, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}},
41 {-1, NULL, NULL, NULL, NULL, {
42      // ?                  8Bit               16Bit              24Bit              32Bit
43      // 0B:n     1     2   1B:n     1     2   2B:n     1     2   3B:n     1    2    4B:n     1     2
44           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, NULL, NULL}}}
45};
46
47int    roardsp_filter_str2id(char * str) {
48 struct _roardsp_filterlist * l = _roardsp_filterlist;
49
50 while ( l->id != -1 ) {
51  if ( strcasecmp(l->name, str) == 0 )
52   return l->id;
53  l++;
54 }
55
56 return -1;
57}
58
59char * roardsp_filter_id2str(int id) {
60 struct _roardsp_filterlist * l = _roardsp_filterlist;
61
62 while ( l->id != -1 ) {
63  if ( l->id == id )
64   return l->name;
65  l++;
66 }
67
68 return NULL;
69}
70
71int roardsp_filter_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
72 struct _roardsp_filterlist * l = _roardsp_filterlist;
73 int bytes;
74 int (*calc)(struct roardsp_filter * filter, void * data, size_t samples) = NULL;
75
76 if ( filter == NULL || stream == NULL ) {
77  ROAR_DBG("roardsp_filter_init(*) = -1 // filter or stream is NULL");
78  return -1;
79 }
80
81 ROAR_DBG("roardsp_filter_init(filter=%p, stream=%p, id=%i) = ?", filter, stream, id);
82
83 memset(filter, 0, sizeof(struct roardsp_filter));
84
85 filter->channels = stream->info.channels;
86 filter->bits     = stream->info.bits;
87 filter->rate     = stream->info.rate;
88
89 bytes            = stream->info.bits / 8;
90
91 while ( l->id != id ) {
92  if ( l->id == -1 )
93   return -1;
94  l++;
95 }
96
97 filter->uninit = l->uninit;
98 filter->ctl    = l->ctl;
99
100 if ( filter->channels < 3 )
101  calc = l->calc[bytes][filter->channels];
102
103 if ( calc == NULL )
104  calc = l->calc[bytes][0]; // for n channels
105
106 if ( calc == NULL ) {
107  ROAR_DBG("roardsp_filter_init(*) = -1 // no calc code");
108  return -1;
109 }
110
111 filter->calc = calc;
112
113 if ( l->init ) {
114  ROAR_DBG("roardsp_filter_init(*) = ? // execing init");
115  return l->init(filter, stream, id);
116 }
117
118 ROAR_DBG("roardsp_filter_init(*) = 0 // no init");
119 return 0;
120}
121
122int roardsp_filter_uninit(struct roardsp_filter * filter) {
123 int ret = 0;
124
125 if ( filter == NULL )
126  return -1;
127
128 if ( filter->uninit )
129  ret = filter->uninit(filter);
130
131 memset(filter, 0, sizeof(struct roardsp_filter));
132
133 return ret;
134}
135
136int roardsp_filter_calc  (struct roardsp_filter * filter, void * data, size_t len) {
137 int ret = 0;
138
139 if ( filter == NULL )
140  return -1;
141
142 if ( filter->calc )
143  ret = filter->calc(filter, data, len);
144
145 return ret;
146}
147
148int    roardsp_filter_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
149 if ( filter == NULL )
150  return -1;
151
152 if ( filter->ctl )
153  return filter->ctl(filter, cmd, data);
154
155 return -1;
156}
157
158//ll
Note: See TracBrowser for help on using the repository browser.