1 | //mixer.c: |
---|
2 | |
---|
3 | #include "roard.h" |
---|
4 | |
---|
5 | int mix_clients (void * output, int bits, void ** input, int samples) { |
---|
6 | if ( bits == 8 ) { |
---|
7 | return mix_clients_8bit(output, input, samples); |
---|
8 | } else if ( bits == 16 ) { |
---|
9 | return mix_clients_16bit(output, input, samples); |
---|
10 | } else if ( bits == 24 ) { |
---|
11 | return mix_clients_24bit(output, input, samples); |
---|
12 | } else if ( bits == 32 ) { |
---|
13 | return mix_clients_32bit(output, input, samples); |
---|
14 | } else { |
---|
15 | return -1; |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | int mix_clients_8bit (void * output, void ** input, int samples) { |
---|
20 | int i, s; |
---|
21 | int c; |
---|
22 | |
---|
23 | for (s = 0; s < samples; s++) { |
---|
24 | c = 0; |
---|
25 | |
---|
26 | for (i = 0; input[i] != NULL; i++) |
---|
27 | c += ((char**)input)[i][s]; |
---|
28 | |
---|
29 | if ( c > 127 ) |
---|
30 | c = 127; |
---|
31 | else if ( c < -128 ) |
---|
32 | c = -128; |
---|
33 | ((char*)output)[s] = (char)c; |
---|
34 | } |
---|
35 | |
---|
36 | return 0; |
---|
37 | } |
---|
38 | |
---|
39 | int mix_clients_16bit (void * output, void ** input, int samples) { |
---|
40 | int i, s; |
---|
41 | int c; |
---|
42 | int16_t ** in = (int16_t**) input; |
---|
43 | int16_t * out = output; |
---|
44 | |
---|
45 | #ifdef DEBUG |
---|
46 | for (i = 0; input[i] != NULL; i++) |
---|
47 | ROAR_DBG("mix_clients_16bit(*): input[%i] = %p", i, input[i]); |
---|
48 | #endif |
---|
49 | |
---|
50 | /* |
---|
51 | if ( input[0] != NULL ) |
---|
52 | write(1, input[0], samples*2); |
---|
53 | */ |
---|
54 | |
---|
55 | /* |
---|
56 | if ( input[0] != NULL ) { |
---|
57 | memcpy(output, input[0], samples*2); |
---|
58 | return -1; |
---|
59 | } |
---|
60 | */ |
---|
61 | |
---|
62 | for (s = 0; s < samples; s++) { |
---|
63 | c = 0; |
---|
64 | for (i = 0; input[i] != NULL; i++) |
---|
65 | c += in[i][s]; |
---|
66 | |
---|
67 | if ( c > 32767 ) |
---|
68 | c = 32767; |
---|
69 | else if ( c < -32768 ) |
---|
70 | c = -32768; |
---|
71 | |
---|
72 | out[s] = c; |
---|
73 | } |
---|
74 | |
---|
75 | return 0; |
---|
76 | } |
---|
77 | |
---|
78 | int mix_clients_24bit (void * output, void ** input, int samples) { |
---|
79 | return -1; |
---|
80 | } |
---|
81 | |
---|
82 | int mix_clients_32bit (void * output, void ** input, int samples) { |
---|
83 | /* |
---|
84 | int i, s; |
---|
85 | int c; |
---|
86 | |
---|
87 | for (s = 0; s < samples; s++) { |
---|
88 | c = 0; |
---|
89 | |
---|
90 | for (i = 0; input[i]; i++) |
---|
91 | c += ((int**)input)[i][s]; |
---|
92 | |
---|
93 | if ( c > 127 ) |
---|
94 | c = 127; |
---|
95 | else if ( c < -128 ) |
---|
96 | c = -128; |
---|
97 | ((int*)output)[s] = (char)c; |
---|
98 | } |
---|
99 | |
---|
100 | return 0; |
---|
101 | */ |
---|
102 | return 1; |
---|
103 | } |
---|
104 | |
---|
105 | //ll |
---|