source: roaraudio/libroardsp/filter_dcblock.c @ 1100:aac17d20aea1

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

added DC block with f_e=~5Hz

File size: 2.5 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_calc16  (struct roardsp_filter * filter, void * data, size_t samples) {
57 struct roardsp_dcblock * inst = filter->inst;
58 int16_t * samp = (int16_t *) data;
59 register int64_t s = 0;
60 size_t i;
61
62 for (i = 0; i < samples; i++) {
63//  ROAR_WARN("roardsp_dcblock_calc16(*): s=%i, samp[i=%i]=%i", s, i, samp[i]);
64  s += samp[i];
65 }
66
67 ROAR_WARN("roardsp_dcblock_calc16(*): s=%i (current block of %i samples)", s, samples);
68
69 s = (float)(s / samples);
70
71 ROAR_WARN("roardsp_dcblock_calc16(*): inst=%p, inst->cur=%i", inst, inst->cur);
72 inst->dc[(inst->cur)++] = s;
73
74 if ( inst->cur == ROARDSP_DCBLOCK_NUMBLOCKS )
75  inst->cur = 0;
76
77 s = 0;
78
79 for (i = 0; i < ROARDSP_DCBLOCK_NUMBLOCKS; i++)
80  s += inst->dc[i];
81
82 s /= ROARDSP_DCBLOCK_NUMBLOCKS;
83
84// s += (ROAR_INSTINT)filter->inst;
85
86 ROAR_WARN("roardsp_dcblock_calc16(*): new DC value: %i", s);
87
88 for (i = 0; i < samples; i++)
89  samp[i] -= s;
90
91 ROAR_DBG("roardsp_downmix_calc16(*) = 0");
92 return 0;
93}
94
95
96
97//ll
Note: See TracBrowser for help on using the repository browser.