source: roaraudio/libroardsp/filter.c @ 677:82e4908ecadf

Last change on this file since 677:82e4908ecadf was 677:82e4908ecadf, checked in by phi, 16 years ago

added some simple lagend, added links to lowp_*

File size: 4.0 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", NULL, NULL, NULL, {
40           {NULL, NULL, NULL},{NULL, NULL, NULL},{NULL, 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 }
54
55 return -1;
56}
57
58char * roardsp_filter_id2str(int id) {
59 struct _roardsp_filterlist * l = _roardsp_filterlist;
60
61 while ( l->id != -1 ) {
62  if ( l->id == id )
63   return l->name;
64 }
65
66 return NULL;
67}
68
69int roardsp_filter_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
70 struct _roardsp_filterlist * l = _roardsp_filterlist;
71 int bytes;
72 int (*calc)(struct roardsp_filter * filter, void * data, size_t samples) = NULL;
73
74 if ( filter == NULL )
75  return -1;
76
77 memset(filter, 0, sizeof(struct roardsp_filter));
78
79 filter->channels = stream->info.channels;
80 filter->bits     = stream->info.bits;
81 filter->rate     = stream->info.rate;
82
83 bytes            = stream->info.bits / 8;
84
85 while ( l->id != id )
86  if ( l->id == -1 )
87   return -1;
88
89 filter->uninit = l->uninit;
90 filter->ctl    = l->ctl;
91
92 if ( filter->channels < 3 )
93  calc = l->calc[bytes][filter->channels];
94
95 if ( calc == NULL )
96  calc = l->calc[bytes][0]; // for n channels
97
98 if ( calc == NULL )
99  return -1;
100
101 if ( l->init )
102  return l->init(filter, stream, id);
103
104 return 0;
105}
106
107int roardsp_filter_uninit(struct roardsp_filter * filter) {
108 int ret = 0;
109
110 if ( filter == NULL )
111  return -1;
112
113 if ( filter->uninit )
114  ret = filter->uninit(filter);
115
116 memset(filter, 0, sizeof(struct roardsp_filter));
117
118 return ret;
119}
120
121int roardsp_filter_calc  (struct roardsp_filter * filter, void * data, size_t len) {
122 int ret = 0;
123
124 if ( filter == NULL )
125  return -1;
126
127 if ( filter->calc )
128  ret = filter->calc(filter, data, len);
129
130 return ret;
131}
132
133int    roardsp_filter_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
134 if ( filter == NULL )
135  return -1;
136
137 if ( filter->ctl )
138  return filter->ctl(filter, cmd, data);
139
140 return -1;
141}
142
143//ll
Note: See TracBrowser for help on using the repository browser.