source: roaraudio/libroardsp/filter_lowp.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: 2.7 KB
Line 
1//lowp.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
27#ifdef ROAR_HAVE_LIBM
28
29int roardsp_lowp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
30 struct roardsp_lowp * self = malloc(sizeof(struct roardsp_lowp));
31 float freq = filter->rate/2;
32
33 ROAR_DBG("roardsp_lowp_init(*): self=%p", self);
34
35 if ( self == NULL )
36  return -1;
37
38 memset(self, 0, sizeof(struct roardsp_lowp));
39
40 filter->inst = (void*) self;
41
42 roardsp_lowp_ctl(filter, ROARDSP_FCTL_FREQ, &freq);
43
44 return 0;
45}
46
47int roardsp_lowp_uninit(struct roardsp_filter * filter) {
48
49 free(filter->inst);
50 return 0;
51}
52
53int roardsp_lowp_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
54 struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst;
55 int16_t * samp = (int16_t *) data;
56 register int32_t s;
57 int i, c;
58 int channels = filter->channels;
59
60 if ( channels > ROAR_MAX_CHANNELS )
61  return -1;
62
63 samples /= channels;
64
65 ROAR_DBG("roardsp_lowp_calc16(*): filtering %i frames of %i channels...", samples, channels);
66
67//  *      output[N] = input[N] * A + output[N-1] * B
68
69 for (i = 0; i < samples; i++) {
70  for (c = 0; c < channels; c++) {
71   s = samp[i*channels + c] * self->a + self->old[c] * self->b;
72
73   s /= 65536;
74
75   samp[i*channels + c] = s;
76   self->old[        c] = s;
77  }
78 }
79
80 return 0;
81}
82
83int roardsp_lowp_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
84 struct roardsp_lowp * self = (struct roardsp_lowp *) filter->inst;
85 float lp;
86 float oldfreq;
87 float newfreq;
88
89 if ( cmd != ROARDSP_FCTL_FREQ )
90  return -1;
91
92 newfreq = *(float*)data;
93
94 lp = exp(-2 * M_PI * newfreq / filter->rate) * 65536;
95
96 self->b = lp;
97 self->a = 65536 - lp;
98
99 oldfreq = self->freq / 1000;
100 self->freq = newfreq * 1000;
101
102 *(float*)data = oldfreq;
103
104 ROAR_DBG("roardsp_lowp_ctl(*): oldfreq=%f, newfreq=%f", oldfreq, newfreq);
105
106 return 0;
107}
108
109#endif
110
111//ll
Note: See TracBrowser for help on using the repository browser.