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 | |
---|
30 | if ( self == NULL ) |
---|
31 | return -1; |
---|
32 | |
---|
33 | memset(self, 0, sizeof(struct roardsp_amp)); |
---|
34 | |
---|
35 | filter->inst = (void*) self; |
---|
36 | |
---|
37 | roardsp_filter_reset(filter, ROARDSP_RESET_FULL); |
---|
38 | |
---|
39 | return 0; |
---|
40 | } |
---|
41 | |
---|
42 | int roardsp_amp_uninit(struct roardsp_filter * filter) { |
---|
43 | |
---|
44 | free(filter->inst); |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | int roardsp_amp_calc8 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
49 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
50 | int8_t * samp = (int8_t *) data; |
---|
51 | register int_least32_t s; |
---|
52 | size_t i; |
---|
53 | |
---|
54 | for (i = 0; i < samples; i++) { |
---|
55 | s = samp[i]; |
---|
56 | s *= self->mul; |
---|
57 | s /= self->div; |
---|
58 | samp[i] = s; |
---|
59 | }; |
---|
60 | |
---|
61 | return 0; |
---|
62 | } |
---|
63 | |
---|
64 | int roardsp_amp_calc16 (struct roardsp_filter * filter, void * data, size_t samples) { |
---|
65 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
66 | int16_t * samp = (int16_t *) data; |
---|
67 | register int_least32_t s; |
---|
68 | size_t i; |
---|
69 | |
---|
70 | for (i = 0; i < samples; i++) { |
---|
71 | s = samp[i]; |
---|
72 | s *= self->mul; |
---|
73 | s /= self->div; |
---|
74 | // 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); |
---|
75 | samp[i] = s; |
---|
76 | }; |
---|
77 | |
---|
78 | return 0; |
---|
79 | } |
---|
80 | |
---|
81 | int roardsp_amp_ctl (struct roardsp_filter * filter, int cmd, void * data) { |
---|
82 | struct roardsp_amp * self = (struct roardsp_amp *) filter->inst; |
---|
83 | int32_t old; |
---|
84 | |
---|
85 | if ( cmd == ROARDSP_FCTL_MUL ) { |
---|
86 | old = self->div; |
---|
87 | self->mul = *(int32_t*)data; |
---|
88 | *(int32_t*)data = old; |
---|
89 | } else if ( cmd == ROARDSP_FCTL_DIV ) { |
---|
90 | old = self->div; |
---|
91 | self->div = *(int32_t*)data; |
---|
92 | *(int32_t*)data = old; |
---|
93 | } else { |
---|
94 | return -1; |
---|
95 | } |
---|
96 | |
---|
97 | |
---|
98 | return 0; |
---|
99 | } |
---|
100 | |
---|
101 | int roardsp_amp_reset (struct roardsp_filter * filter, int what) { |
---|
102 | struct roardsp_amp * self; |
---|
103 | |
---|
104 | if ( filter == NULL ) |
---|
105 | return -1; |
---|
106 | |
---|
107 | if ( filter->inst == NULL ) |
---|
108 | return -1; |
---|
109 | |
---|
110 | self = filter->inst; |
---|
111 | |
---|
112 | switch (what) { |
---|
113 | case ROARDSP_RESET_NONE: |
---|
114 | case ROARDSP_RESET_STATE: |
---|
115 | return 0; |
---|
116 | break; |
---|
117 | case ROARDSP_RESET_FULL: |
---|
118 | self->mul = 1; |
---|
119 | self->div = 1; |
---|
120 | return 0; |
---|
121 | break; |
---|
122 | default: |
---|
123 | return -1; |
---|
124 | } |
---|
125 | |
---|
126 | return -1; |
---|
127 | } |
---|
128 | |
---|
129 | //ll |
---|