1 | //amp.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - August 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 | |
---|
27 | int roardsp_amp_init (struct roardsp_filter * filter, struct roar_stream * stream, int id) { |
---|
28 | struct roardsp_amp * self = malloc(sizeof(struct roardsp_amp)); |
---|
29 | int32_t fac; |
---|
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 | fac = 1; |
---|
39 | roardsp_amp_ctl(filter, ROARDSP_FCTL_MUL, &fac); |
---|
40 | fac = 1; |
---|
41 | roardsp_amp_ctl(filter, ROARDSP_FCTL_DIV, &fac); |
---|
42 | |
---|
43 | return 0; |
---|
44 | } |
---|
45 | |
---|
46 | int roardsp_amp_uninit(struct roardsp_filter * filter) { |
---|
47 | |
---|
48 | free(filter->inst); |
---|
49 | return 0; |
---|
50 | } |
---|
51 | |
---|
52 | int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
53 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
54 | int8_t * samp = (int8_t *) data; |
---|
55 | register int_least32_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 | int roardsp_amp_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
69 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
70 | int16_t * samp = (int16_t *) data; |
---|
71 | register int_least32_t s; |
---|
72 | size_t i; |
---|
73 | |
---|
74 | for (i = 0; i < samples; i++) { |
---|
75 | s = samp[i]; |
---|
76 | s *= self->mul; |
---|
77 | s /= self->div; |
---|
78 | // ROAR_DBG("roardsp_amp_calc16(*): samp[i=%u] = %i, s=%i, self->mul=%i, self->div=%i", i, samp[i], s, self->mul, self->div); |
---|
79 | samp[i] = s; |
---|
80 | }; |
---|
81 | |
---|
82 | return 0; |
---|
83 | } |
---|
84 | |
---|
85 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
86 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
87 | int32_t old; |
---|
88 | |
---|
89 | if ( cmd == ROARDSP_FCTL_MUL ) { |
---|
90 | old = self->div; |
---|
91 | self->mul = *(int32_t*)data; |
---|
92 | *(int32_t*)data = old; |
---|
93 | } else if ( cmd == ROARDSP_FCTL_DIV ) { |
---|
94 | old = self->div; |
---|
95 | self->div = *(int32_t*)data; |
---|
96 | *(int32_t*)data = old; |
---|
97 | } else { |
---|
98 | return -1; |
---|
99 | } |
---|
100 | |
---|
101 | |
---|
102 | return 0; |
---|
103 | } |
---|
104 | |
---|
105 | //ll |
---|