source: roaraudio/libroardsp/filter_amp.c @ 5181:ca57e34b2a35

Last change on this file since 5181:ca57e34b2a35 was 5181:ca57e34b2a35, checked in by phi, 13 years ago

updated filters to support 8 and 32 bit as well as 16 bit

File size: 2.7 KB
Line 
1//filter_amp.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_amp_init  (struct roardsp_filter * filter, struct roar_stream * stream, int id) {
29 struct roardsp_amp * self = roar_mm_malloc(sizeof(struct roardsp_amp));
30
31 if ( self == NULL )
32  return -1;
33
34 memset(self, 0, sizeof(struct roardsp_amp));
35
36 filter->inst = (void*) self;
37
38 roardsp_filter_reset(filter, ROARDSP_RESET_FULL);
39
40 return 0;
41}
42
43int roardsp_amp_uninit(struct roardsp_filter * filter) {
44
45 roar_mm_free(filter->inst);
46 return 0;
47}
48
49#define _calcX(bits,twobits) \
50int roardsp_amp_calc##bits  (struct roardsp_filter * filter, void * data, size_t samples) { \
51 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; \
52 int##bits##_t * samp = (int##bits##_t *) data; \
53 register int##twobits##_t s; \
54 size_t i; \
55\
56 for (i = 0; i < samples; i++) { \
57  s        = samp[i]; \
58  s       *= self->mul; \
59  s       /= self->div; \
60  samp[i]  = s; \
61 }; \
62\
63 return 0; \
64}
65
66_calcX(8,16)
67_calcX(16,32)
68_calcX(32,64)
69
70int roardsp_amp_ctl   (struct roardsp_filter * filter, int cmd, void * data) {
71 struct roardsp_amp * self = (struct roardsp_amp *) filter->inst;
72 int32_t old;
73
74 if ( cmd == ROARDSP_FCTL_MUL ) {
75  old = self->div;
76  self->mul = *(int32_t*)data;
77  *(int32_t*)data = old;
78 } else if ( cmd == ROARDSP_FCTL_DIV ) {
79  old = self->div;
80  self->div = *(int32_t*)data;
81  *(int32_t*)data = old;
82 } else {
83  return -1;
84 }
85
86
87 return 0;
88}
89
90int roardsp_amp_reset (struct roardsp_filter * filter, int what) {
91 struct roardsp_amp * self;
92
93 if ( filter == NULL )
94  return -1;
95
96 if ( filter->inst == NULL )
97  return -1;
98
99 self = filter->inst;
100
101 switch (what) {
102  case ROARDSP_RESET_NONE:
103  case ROARDSP_RESET_STATE:
104    return  0;
105   break;
106  case ROARDSP_RESET_FULL:
107    self->mul = 1;
108    self->div = 1;
109    return  0;
110   break;
111  default:
112    return -1;
113 }
114
115 return -1;
116}
117
118//ll
Note: See TracBrowser for help on using the repository browser.