source: roaraudio/libroardsp/filter_dcblock.c @ 5270:e25346c13638

Last change on this file since 5270:e25346c13638 was 5270:e25346c13638, checked in by phi, 12 years ago

fixed some gcc -Wextra warnings

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