source: roaraudio/roard/mixer.c @ 856:b61f10a34036

Last change on this file since 856:b61f10a34036 was 856:b61f10a34036, checked in by phi, 16 years ago

got 32 bit mode working, yey! :)

File size: 5.2 KB
Line 
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
27int mix_clients (void * output, int bits, void ** input, int samples) {
28 if ( bits == 8 ) {
29  return mix_clients_8bit(output, input, samples);
30 } else if ( bits == 16 ) {
31  return mix_clients_16bit(output, input, samples);
32 } else if ( bits == 24 ) {
33  return mix_clients_24bit(output, input, samples);
34 } else if ( bits == 32 ) {
35  return mix_clients_32bit(output, input, samples);
36 } else {
37  return -1;
38 }
39}
40
41int mix_clients_8bit (void * output, void ** input, int samples) {
42 int i, s;
43 register int c;
44
45 for (s = 0; s < samples; s++) {
46  c = 0;
47
48  for (i = 0; input[i] != NULL; i++)
49   c += ((char**)input)[i][s];
50
51  if ( c > 127 )
52   c = 127;
53  else if ( c < -128 )
54   c = -128;
55  ((char*)output)[s] = (char)c;
56 }
57
58 return 0;
59}
60
61int mix_clients_16bit (void * output, void ** input, int samples) {
62 int i, s;
63 register int c;
64 int16_t ** in  = (int16_t**) input;
65 int16_t *  out = output;
66
67#ifdef DEBUG
68 for (i = 0; input[i] != NULL; i++)
69  ROAR_DBG("mix_clients_16bit(*): input[%i] = %p", i, input[i]);
70#endif
71
72/*
73 if ( input[0] != NULL )
74  write(1, input[0], samples*2);
75*/
76
77/*
78 if ( input[0] != NULL ) {
79  memcpy(output, input[0], samples*2);
80  return -1;
81 }
82*/
83
84 for (s = 0; s < samples; s++) {
85  c = 0;
86  for (i = 0; input[i] != NULL; i++) {
87//   printf("D: input[i=%i] = %p\n", i, input[i]);
88   c += in[i][s];
89  }
90
91  if ( c > 32767 )
92   c = 32767;
93  else if ( c < -32768 )
94   c = -32768;
95
96  out[s] = c;
97 }
98
99 return 0;
100}
101
102int mix_clients_24bit (void * output, void ** input, int samples) {
103 return -1;
104}
105
106int mix_clients_32bit (void * output, void ** input, int samples) {
107#ifdef ROAR_NATIVE_INT64
108 int32_t ** in  = (int32_t**) input;
109 int32_t *  out = (int32_t**) output;
110 int i, s;
111 ROAR_NATIVE_INT64 c;
112
113 for (s = 0; s < samples; s++) {
114  c = 0;
115
116  for (i = 0; input[i]; i++)
117   c += in[i][s];
118
119  if ( c > 21474836487LL )
120   c = 2147483647LL;
121  else if ( c < -2147483648LL )
122   c = -2147483648LL;
123  out[s] = (int32_t)c;
124 }
125
126 return  0;
127#else
128 return -1;
129#endif
130}
131
132int change_vol (void * output, int bits, void * input, int samples, int channels, struct roar_mixer_settings * set) {
133
134 ROAR_DBG("change_vol(*): mixer at %p", set->mixer);
135
136 if ( bits == 8 ) {
137  return  change_vol_8bit(output, input, samples, channels, set);
138 } else if ( bits == 16 ) {
139  return  change_vol_16bit(output, input, samples, channels, set);
140 } else if ( bits == 24 ) {
141  return  change_vol_24bit(output, input, samples, channels, set);
142 } else if ( bits == 32 ) {
143  return  change_vol_32bit(output, input, samples, channels, set);
144 } else {
145  return -1;
146 }
147}
148
149int change_vol_8bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) {
150 char * in = input, * out = output;
151 int    i;
152 register int s;
153
154 if ( !(in && out) )
155  return -1;
156
157 if (set->rpg_mul == set->rpg_div) {
158  for (i = 0; i < samples; i++) {
159   s  = in[i];
160   s *= set->mixer[i % channels];
161   s /= set->scale;
162   out[i] = s;
163  }
164 } else {
165  for (i = 0; i < samples; i++) {
166   s  = in[i];
167   s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div;
168   s /= set->scale;
169   out[i] = s;
170  }
171 }
172
173 return 0;
174}
175
176int change_vol_16bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) {
177 int16_t * in = input, * out = output;
178 int       i;
179 register int s;
180
181 if ( !(in && out) )
182  return -1;
183
184 if (set->rpg_mul == set->rpg_div) {
185  for (i = 0; i < samples; i++) {
186   s  = in[i];
187   s *= set->mixer[i % channels];
188   s /= set->scale;
189   out[i] = s;
190  }
191 } else {
192  for (i = 0; i < samples; i++) {
193   s  = in[i];
194   s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div;
195   s /= set->scale;
196   out[i] = s;
197  }
198 }
199
200 return 0;
201}
202
203int change_vol_24bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) {
204 return -1;
205}
206
207int change_vol_32bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) {
208#ifdef ROAR_NATIVE_INT64
209 int32_t * in = input, * out = output;
210 int       i;
211 ROAR_NATIVE_INT64 s;
212
213 if ( !(in && out) )
214  return -1;
215
216 if (set->rpg_mul == set->rpg_div) {
217  for (i = 0; i < samples; i++) {
218   s  = in[i];
219   s *= set->mixer[i % channels];
220   s /= set->scale;
221   out[i] = s;
222  }
223 } else {
224  for (i = 0; i < samples; i++) {
225   s  = in[i];
226   s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div;
227   s /= set->scale;
228   out[i] = s;
229  }
230 }
231
232 return 0;
233#else
234 return -1;
235#endif
236}
237
238
239//ll
Note: See TracBrowser for help on using the repository browser.