[0] | 1 | //mixer.c: |
---|
| 2 | |
---|
[668] | 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 | |
---|
[0] | 25 | #include "roard.h" |
---|
| 26 | |
---|
| 27 | int 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 | |
---|
| 41 | int mix_clients_8bit (void * output, void ** input, int samples) { |
---|
| 42 | int i, s; |
---|
[423] | 43 | register int c; |
---|
[0] | 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 | |
---|
| 61 | int mix_clients_16bit (void * output, void ** input, int samples) { |
---|
| 62 | int i, s; |
---|
[423] | 63 | register int c; |
---|
[0] | 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; |
---|
[139] | 86 | for (i = 0; input[i] != NULL; i++) { |
---|
| 87 | // printf("D: input[i=%i] = %p\n", i, input[i]); |
---|
[0] | 88 | c += in[i][s]; |
---|
[139] | 89 | } |
---|
[0] | 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 | |
---|
| 102 | int mix_clients_24bit (void * output, void ** input, int samples) { |
---|
| 103 | return -1; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | int mix_clients_32bit (void * output, void ** input, int samples) { |
---|
| 107 | /* |
---|
| 108 | int i, s; |
---|
| 109 | int c; |
---|
| 110 | |
---|
| 111 | for (s = 0; s < samples; s++) { |
---|
| 112 | c = 0; |
---|
| 113 | |
---|
| 114 | for (i = 0; input[i]; i++) |
---|
| 115 | c += ((int**)input)[i][s]; |
---|
| 116 | |
---|
| 117 | if ( c > 127 ) |
---|
| 118 | c = 127; |
---|
| 119 | else if ( c < -128 ) |
---|
| 120 | c = -128; |
---|
| 121 | ((int*)output)[s] = (char)c; |
---|
| 122 | } |
---|
| 123 | |
---|
| 124 | return 0; |
---|
| 125 | */ |
---|
| 126 | return 1; |
---|
| 127 | } |
---|
| 128 | |
---|
[16] | 129 | int change_vol (void * output, int bits, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
[18] | 130 | |
---|
| 131 | ROAR_DBG("change_vol(*): mixer at %p", set->mixer); |
---|
| 132 | |
---|
[16] | 133 | if ( bits == 8 ) { |
---|
| 134 | return change_vol_8bit(output, input, samples, channels, set); |
---|
| 135 | } else if ( bits == 16 ) { |
---|
| 136 | return change_vol_16bit(output, input, samples, channels, set); |
---|
| 137 | } else if ( bits == 24 ) { |
---|
| 138 | return change_vol_24bit(output, input, samples, channels, set); |
---|
| 139 | } else if ( bits == 32 ) { |
---|
| 140 | return change_vol_32bit(output, input, samples, channels, set); |
---|
| 141 | } else { |
---|
| 142 | return -1; |
---|
| 143 | } |
---|
| 144 | } |
---|
| 145 | |
---|
| 146 | int change_vol_8bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
[17] | 147 | char * in = input, * out = output; |
---|
[16] | 148 | int i; |
---|
[423] | 149 | register int s; |
---|
[16] | 150 | |
---|
| 151 | if ( !(in && out) ) |
---|
| 152 | return -1; |
---|
| 153 | |
---|
[253] | 154 | if (set->rpg_mul == set->rpg_div) { |
---|
| 155 | for (i = 0; i < samples; i++) { |
---|
| 156 | s = in[i]; |
---|
| 157 | s *= set->mixer[i % channels]; |
---|
| 158 | s /= set->scale; |
---|
| 159 | out[i] = s; |
---|
| 160 | } |
---|
| 161 | } else { |
---|
| 162 | for (i = 0; i < samples; i++) { |
---|
| 163 | s = in[i]; |
---|
[254] | 164 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
| 165 | s /= set->scale; |
---|
[253] | 166 | out[i] = s; |
---|
| 167 | } |
---|
[16] | 168 | } |
---|
| 169 | |
---|
| 170 | return 0; |
---|
| 171 | } |
---|
| 172 | |
---|
| 173 | int change_vol_16bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
[17] | 174 | int16_t * in = input, * out = output; |
---|
[16] | 175 | int i; |
---|
[423] | 176 | register int s; |
---|
[16] | 177 | |
---|
| 178 | if ( !(in && out) ) |
---|
| 179 | return -1; |
---|
| 180 | |
---|
[253] | 181 | if (set->rpg_mul == set->rpg_div) { |
---|
| 182 | for (i = 0; i < samples; i++) { |
---|
| 183 | s = in[i]; |
---|
| 184 | s *= set->mixer[i % channels]; |
---|
| 185 | s /= set->scale; |
---|
| 186 | out[i] = s; |
---|
| 187 | } |
---|
| 188 | } else { |
---|
| 189 | for (i = 0; i < samples; i++) { |
---|
| 190 | s = in[i]; |
---|
[254] | 191 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
| 192 | s /= set->scale; |
---|
[253] | 193 | out[i] = s; |
---|
| 194 | } |
---|
[16] | 195 | } |
---|
| 196 | |
---|
| 197 | return 0; |
---|
| 198 | } |
---|
| 199 | |
---|
| 200 | int change_vol_24bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 201 | return -1; |
---|
| 202 | } |
---|
| 203 | |
---|
| 204 | int change_vol_32bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 205 | return -1; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
[0] | 209 | //ll |
---|