source: roaraudio/libroardsp/filter_amp.c @ 5961:06e7fd9e4c25

Last change on this file since 5961:06e7fd9e4c25 was 5961:06e7fd9e4c25, checked in by phi, 10 years ago

Updates of copyright and license headers

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