source: roaraudio/libroardsp/filter_dcblock.c @ 1131:bca464362519

Last change on this file since 1131:bca464362519 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: 3.0 KB
Line 
1//dcblock.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - December 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_dcblock_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
28 struct roardsp_dcblock * inst = malloc(sizeof(struct roardsp_dcblock));
29// roardsp_downmix_ctl(filter, ROARDSP_FCTL_MODE, &mode);
30
31 if ( inst == NULL ) {
32  ROAR_ERR("roardsp_dcblock_init(*): Can not alloc memory for filter dcblock: %s", strerror(errno));
33  filter->inst = NULL;
34  return -1;
35 }
36
37 memset(inst, 0, sizeof(struct roardsp_dcblock));
38
39 filter->inst = inst;
40
41 return 0;
42}
43
44int roardsp_dcblock_uninit (struct roardsp_filter * filter) {
45 if ( filter == NULL )
46  return -1;
47
48 if ( filter->inst == NULL )
49  return -1;
50
51 free(filter->inst);
52
53 return 0;
54}
55
56int roardsp_dcblock_reset  (struct roardsp_filter * filter, int what) {
57 if ( filter == NULL )
58  return -1;
59
60 if ( filter->inst == NULL )
61  return -1;
62
63 switch (what) {
64  case ROARDSP_RESET_NONE:
65    return  0;
66   break;
67  case ROARDSP_RESET_FULL:
68    memset(filter->inst, 0, sizeof(struct roardsp_dcblock));
69    return  0;
70   break;
71  case ROARDSP_RESET_STATE:
72    memset(((struct roardsp_dcblock*)filter->inst)->dc, 0, sizeof(int32_t)*ROARDSP_DCBLOCK_NUMBLOCKS);
73    return  0;
74   break;
75  default:
76    return -1;
77 }
78
79 return -1;
80}
81
82int roardsp_dcblock_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
83 struct roardsp_dcblock * inst = filter->inst;
84 int16_t * samp = (int16_t *) data;
85 register int64_t s = 0;
86 size_t i;
87
88 for (i = 0; i < samples; i++) {
89//  ROAR_WARN("roardsp_dcblock_calc16(*): s=%i, samp[i=%i]=%i", s, i, samp[i]);
90  s += samp[i];
91 }
92
93 ROAR_WARN("roardsp_dcblock_calc16(*): s=%i (current block of %i samples)", s, samples);
94
95 s = (float)(s / samples);
96
97 ROAR_WARN("roardsp_dcblock_calc16(*): inst=%p, inst->cur=%i", inst, inst->cur);
98 inst->dc[(inst->cur)++] = s;
99
100 if ( inst->cur == ROARDSP_DCBLOCK_NUMBLOCKS )
101  inst->cur = 0;
102
103 s = 0;
104
105 for (i = 0; i < ROARDSP_DCBLOCK_NUMBLOCKS; i++)
106  s += inst->dc[i];
107
108 s /= ROARDSP_DCBLOCK_NUMBLOCKS;
109
110// s += (ROAR_INSTINT)filter->inst;
111
112 ROAR_WARN("roardsp_dcblock_calc16(*): new DC value: %i", s);
113
114 for (i = 0; i < samples; i++)
115  samp[i] -= s;
116
117 ROAR_DBG("roardsp_downmix_calc16(*) = 0");
118 return 0;
119}
120
121
122
123//ll
Note: See TracBrowser for help on using the repository browser.