[2930] | 1 | //mixer.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[5961] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2014 |
---|
[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 32: return roar_mix_pcm_32bit(output, (int32_t **)input, samples); break; |
---|
| 33 | default: return -1; |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int roar_mix_pcm_8bit (int8_t * output, int8_t ** input, int samples) { |
---|
| 38 | int i, s; |
---|
| 39 | register int c; |
---|
| 40 | |
---|
| 41 | for (s = 0; s < samples; s++) { |
---|
| 42 | c = 0; |
---|
| 43 | |
---|
| 44 | for (i = 0; input[i] != NULL; i++) |
---|
| 45 | c += input[i][s]; |
---|
| 46 | |
---|
| 47 | if ( c > 127 ) |
---|
| 48 | c = 127; |
---|
| 49 | else if ( c < -128 ) |
---|
| 50 | c = -128; |
---|
| 51 | output[s] = (char)c; |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | return 0; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | int roar_mix_pcm_16bit (int16_t * output, int16_t ** input, int samples) { |
---|
| 58 | int i, s; |
---|
| 59 | register int_least32_t c; |
---|
| 60 | |
---|
| 61 | #ifdef DEBUG |
---|
| 62 | for (i = 0; input[i] != NULL; i++) |
---|
| 63 | ROAR_DBG("mix_clients_16bit(*): input[%i] = %p", i, input[i]); |
---|
| 64 | #endif |
---|
| 65 | |
---|
| 66 | for (s = 0; s < samples; s++) { |
---|
| 67 | c = 0; |
---|
| 68 | for (i = 0; input[i] != NULL; i++) { |
---|
| 69 | c += input[i][s]; |
---|
| 70 | } |
---|
| 71 | |
---|
| 72 | if ( c > 32767 ) |
---|
| 73 | c = 32767; |
---|
| 74 | else if ( c < -32768 ) |
---|
| 75 | c = -32768; |
---|
| 76 | |
---|
| 77 | output[s] = c; |
---|
| 78 | } |
---|
| 79 | |
---|
| 80 | return 0; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | int roar_mix_pcm_32bit (int32_t * output, int32_t ** input, int samples) { |
---|
| 84 | #ifdef ROAR_NATIVE_INT64 |
---|
| 85 | int i, s; |
---|
| 86 | ROAR_NATIVE_INT64 c; |
---|
| 87 | |
---|
| 88 | for (s = 0; s < samples; s++) { |
---|
| 89 | c = 0; |
---|
| 90 | |
---|
| 91 | for (i = 0; input[i]; i++) |
---|
| 92 | c += input[i][s]; |
---|
| 93 | |
---|
| 94 | if ( c > 21474836487LL ) |
---|
| 95 | c = 2147483647LL; |
---|
| 96 | else if ( c < -2147483648LL ) |
---|
| 97 | c = -2147483648LL; |
---|
| 98 | output[s] = (int32_t)c; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | return 0; |
---|
| 102 | #else |
---|
| 103 | return -1; |
---|
| 104 | #endif |
---|
| 105 | } |
---|
| 106 | |
---|
[2930] | 107 | |
---|
| 108 | //ll |
---|