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, 51 Franklin Street, Fifth Floor, |
---|
22 | * Boston, MA 02110-1301, USA. |
---|
23 | * |
---|
24 | */ |
---|
25 | |
---|
26 | #include "libroardsp.h" |
---|
27 | |
---|
28 | int 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 | |
---|
43 | int roardsp_amp_uninit(struct roardsp_filter * filter) { |
---|
44 | |
---|
45 | roar_mm_free(filter->inst); |
---|
46 | return 0; |
---|
47 | } |
---|
48 | |
---|
49 | int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
50 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
51 | int8_t * samp = (int8_t *) data; |
---|
52 | register int_least32_t s; |
---|
53 | size_t i; |
---|
54 | |
---|
55 | for (i = 0; i < samples; i++) { |
---|
56 | s = samp[i]; |
---|
57 | s *= self->mul; |
---|
58 | s /= self->div; |
---|
59 | samp[i] = s; |
---|
60 | }; |
---|
61 | |
---|
62 | return 0; |
---|
63 | } |
---|
64 | |
---|
65 | int roardsp_amp_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
66 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
67 | int16_t * samp = (int16_t *) data; |
---|
68 | register int_least32_t s; |
---|
69 | size_t i; |
---|
70 | |
---|
71 | for (i = 0; i < samples; i++) { |
---|
72 | s = samp[i]; |
---|
73 | s *= self->mul; |
---|
74 | s /= self->div; |
---|
75 | // 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); |
---|
76 | samp[i] = s; |
---|
77 | }; |
---|
78 | |
---|
79 | return 0; |
---|
80 | } |
---|
81 | |
---|
82 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
83 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
84 | int32_t old; |
---|
85 | |
---|
86 | if ( cmd == ROARDSP_FCTL_MUL ) { |
---|
87 | old = self->div; |
---|
88 | self->mul = *(int32_t*)data; |
---|
89 | *(int32_t*)data = old; |
---|
90 | } else if ( cmd == ROARDSP_FCTL_DIV ) { |
---|
91 | old = self->div; |
---|
92 | self->div = *(int32_t*)data; |
---|
93 | *(int32_t*)data = old; |
---|
94 | } else { |
---|
95 | return -1; |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | return 0; |
---|
100 | } |
---|
101 | |
---|
102 | int roardsp_amp_reset (struct roardsp_filter * filter, int what) { |
---|
103 | struct roardsp_amp * self; |
---|
104 | |
---|
105 | if ( filter == NULL ) |
---|
106 | return -1; |
---|
107 | |
---|
108 | if ( filter->inst == NULL ) |
---|
109 | return -1; |
---|
110 | |
---|
111 | self = filter->inst; |
---|
112 | |
---|
113 | switch (what) { |
---|
114 | case ROARDSP_RESET_NONE: |
---|
115 | case ROARDSP_RESET_STATE: |
---|
116 | return 0; |
---|
117 | break; |
---|
118 | case ROARDSP_RESET_FULL: |
---|
119 | self->mul = 1; |
---|
120 | self->div = 1; |
---|
121 | return 0; |
---|
122 | break; |
---|
123 | default: |
---|
124 | return -1; |
---|
125 | } |
---|
126 | |
---|
127 | return -1; |
---|
128 | } |
---|
129 | |
---|
130 | //ll |
---|