[2930] | 1 | //mixer.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[3812] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2010 |
---|
[2930] | 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 |
---|
[3517] | 21 | * the Free Software Foundation, 51 Franklin Street, Fifth Floor, |
---|
| 22 | * Boston, MA 02110-1301, USA. |
---|
[2930] | 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include "libroardsp.h" |
---|
| 27 | |
---|
[2931] | 28 | int roar_mix_pcm (void * output, int bits, void ** input, int samples) { |
---|
| 29 | switch (bits) { |
---|
| 30 | case 8: return roar_mix_pcm_8bit (output, (int8_t **)input, samples); break; |
---|
| 31 | case 16: return roar_mix_pcm_16bit(output, (int16_t **)input, samples); break; |
---|
| 32 | case 24: return roar_mix_pcm_24bit(output, input, samples); break; |
---|
| 33 | case 32: return roar_mix_pcm_32bit(output, (int32_t **)input, samples); break; |
---|
| 34 | default: return -1; |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | int roar_mix_pcm_8bit (int8_t * output, int8_t ** input, int samples) { |
---|
| 39 | int i, s; |
---|
| 40 | register int c; |
---|
| 41 | |
---|
| 42 | for (s = 0; s < samples; s++) { |
---|
| 43 | c = 0; |
---|
| 44 | |
---|
| 45 | for (i = 0; input[i] != NULL; i++) |
---|
| 46 | c += input[i][s]; |
---|
| 47 | |
---|
| 48 | if ( c > 127 ) |
---|
| 49 | c = 127; |
---|
| 50 | else if ( c < -128 ) |
---|
| 51 | c = -128; |
---|
| 52 | output[s] = (char)c; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | return 0; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | int roar_mix_pcm_16bit (int16_t * output, int16_t ** input, int samples) { |
---|
| 59 | int i, s; |
---|
| 60 | register int_least32_t c; |
---|
| 61 | |
---|
| 62 | #ifdef DEBUG |
---|
| 63 | for (i = 0; input[i] != NULL; i++) |
---|
| 64 | ROAR_DBG("mix_clients_16bit(*): input[%i] = %p", i, input[i]); |
---|
| 65 | #endif |
---|
| 66 | |
---|
| 67 | for (s = 0; s < samples; s++) { |
---|
| 68 | c = 0; |
---|
| 69 | for (i = 0; input[i] != NULL; i++) { |
---|
| 70 | c += input[i][s]; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if ( c > 32767 ) |
---|
| 74 | c = 32767; |
---|
| 75 | else if ( c < -32768 ) |
---|
| 76 | c = -32768; |
---|
| 77 | |
---|
| 78 | output[s] = c; |
---|
| 79 | } |
---|
| 80 | |
---|
| 81 | return 0; |
---|
| 82 | } |
---|
| 83 | |
---|
| 84 | int roar_mix_pcm_24bit (void * output, void ** input, int samples) { |
---|
| 85 | return -1; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | int roar_mix_pcm_32bit (int32_t * output, int32_t ** input, int samples) { |
---|
| 89 | #ifdef ROAR_NATIVE_INT64 |
---|
| 90 | int i, s; |
---|
| 91 | ROAR_NATIVE_INT64 c; |
---|
| 92 | |
---|
| 93 | for (s = 0; s < samples; s++) { |
---|
| 94 | c = 0; |
---|
| 95 | |
---|
| 96 | for (i = 0; input[i]; i++) |
---|
| 97 | c += input[i][s]; |
---|
| 98 | |
---|
| 99 | if ( c > 21474836487LL ) |
---|
| 100 | c = 2147483647LL; |
---|
| 101 | else if ( c < -2147483648LL ) |
---|
| 102 | c = -2147483648LL; |
---|
| 103 | output[s] = (int32_t)c; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | return 0; |
---|
| 107 | #else |
---|
| 108 | return -1; |
---|
| 109 | #endif |
---|
| 110 | } |
---|
| 111 | |
---|
[2930] | 112 | |
---|
| 113 | //ll |
---|