1 | //mixer.c: |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008 |
---|
5 | * |
---|
6 | * This file is part of roard 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 | * RoarAudio 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 "roard.h" |
---|
26 | |
---|
27 | int change_vol (void * output, int bits, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
28 | |
---|
29 | ROAR_DBG("change_vol(*): mixer at %p", set->mixer); |
---|
30 | |
---|
31 | if ( bits == 8 ) { |
---|
32 | return change_vol_8bit(output, input, samples, channels, set); |
---|
33 | } else if ( bits == 16 ) { |
---|
34 | return change_vol_16bit(output, input, samples, channels, set); |
---|
35 | } else if ( bits == 24 ) { |
---|
36 | return change_vol_24bit(output, input, samples, channels, set); |
---|
37 | } else if ( bits == 32 ) { |
---|
38 | return change_vol_32bit(output, input, samples, channels, set); |
---|
39 | } else { |
---|
40 | return -1; |
---|
41 | } |
---|
42 | } |
---|
43 | |
---|
44 | int change_vol_8bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
45 | char * in = input, * out = output; |
---|
46 | int i; |
---|
47 | register int s; |
---|
48 | |
---|
49 | if ( !(in && out) ) |
---|
50 | return -1; |
---|
51 | |
---|
52 | if (set->rpg_mul == set->rpg_div) { |
---|
53 | for (i = 0; i < samples; i++) { |
---|
54 | s = in[i]; |
---|
55 | s *= set->mixer[i % channels]; |
---|
56 | s /= set->scale; |
---|
57 | out[i] = s; |
---|
58 | } |
---|
59 | } else { |
---|
60 | for (i = 0; i < samples; i++) { |
---|
61 | s = in[i]; |
---|
62 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
63 | s /= set->scale; |
---|
64 | out[i] = s; |
---|
65 | } |
---|
66 | } |
---|
67 | |
---|
68 | return 0; |
---|
69 | } |
---|
70 | |
---|
71 | int change_vol_16bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
72 | int16_t * in = input, * out = output; |
---|
73 | int i; |
---|
74 | register int s; |
---|
75 | |
---|
76 | if ( !(in && out) ) |
---|
77 | return -1; |
---|
78 | |
---|
79 | if (set->rpg_mul == set->rpg_div) { |
---|
80 | for (i = 0; i < samples; i++) { |
---|
81 | s = in[i]; |
---|
82 | s *= set->mixer[i % channels]; |
---|
83 | s /= set->scale; |
---|
84 | out[i] = s; |
---|
85 | } |
---|
86 | } else { |
---|
87 | for (i = 0; i < samples; i++) { |
---|
88 | s = in[i]; |
---|
89 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
90 | s /= set->scale; |
---|
91 | out[i] = s; |
---|
92 | } |
---|
93 | } |
---|
94 | |
---|
95 | return 0; |
---|
96 | } |
---|
97 | |
---|
98 | int change_vol_24bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
99 | return -1; |
---|
100 | } |
---|
101 | |
---|
102 | int change_vol_32bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
103 | #ifdef ROAR_NATIVE_INT64 |
---|
104 | int32_t * in = input, * out = output; |
---|
105 | int i; |
---|
106 | ROAR_NATIVE_INT64 s; |
---|
107 | |
---|
108 | if ( !(in && out) ) |
---|
109 | return -1; |
---|
110 | |
---|
111 | if (set->rpg_mul == set->rpg_div) { |
---|
112 | for (i = 0; i < samples; i++) { |
---|
113 | s = in[i]; |
---|
114 | s *= set->mixer[i % channels]; |
---|
115 | s /= set->scale; |
---|
116 | out[i] = s; |
---|
117 | } |
---|
118 | } else { |
---|
119 | for (i = 0; i < samples; i++) { |
---|
120 | s = in[i]; |
---|
121 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
122 | s /= set->scale; |
---|
123 | out[i] = s; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | return 0; |
---|
128 | #else |
---|
129 | return -1; |
---|
130 | #endif |
---|
131 | } |
---|
132 | |
---|
133 | int need_vol_change (int channels, struct roar_mixer_settings * set) { |
---|
134 | int i; |
---|
135 | |
---|
136 | if ( set == NULL || channels < 1 || channels > ROAR_MAX_CHANNELS ) |
---|
137 | return -1; |
---|
138 | |
---|
139 | if ( set->rpg_mul != set->rpg_div ) |
---|
140 | return 1; |
---|
141 | |
---|
142 | for (i = 0; i < channels; i++) |
---|
143 | if ( set->mixer[i] != set->scale ) |
---|
144 | return 1; |
---|
145 | |
---|
146 | return 0; |
---|
147 | } |
---|
148 | |
---|
149 | //ll |
---|