[2935] | 1 | //amp.c: |
---|
| 2 | |
---|
| 3 | /* |
---|
[2937] | 4 | * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008, 2009 |
---|
[2935] | 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 |
---|
| 21 | * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 22 | * |
---|
| 23 | */ |
---|
| 24 | |
---|
| 25 | #include "libroardsp.h" |
---|
| 26 | |
---|
[2937] | 27 | int roar_amp_pcm(void * output, int bits, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 28 | switch (bits) { |
---|
| 29 | case 8: return roar_amp_pcm_8bit (output, input, samples, channels, set); break; |
---|
| 30 | case 16: return roar_amp_pcm_16bit(output, input, samples, channels, set); break; |
---|
| 31 | case 24: return roar_amp_pcm_24bit(output, input, samples, channels, set); break; |
---|
| 32 | case 32: return roar_amp_pcm_32bit(output, input, samples, channels, set); break; |
---|
| 33 | default: return -1; |
---|
| 34 | } |
---|
| 35 | } |
---|
| 36 | |
---|
| 37 | int roar_amp_pcm_8bit (int8_t * output, int8_t * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 38 | int i; |
---|
| 39 | register int s; |
---|
| 40 | |
---|
| 41 | if ( !(input && output) ) |
---|
| 42 | return -1; |
---|
| 43 | |
---|
| 44 | if (set->rpg_mul == set->rpg_div) { |
---|
| 45 | for (i = 0; i < samples; i++) { |
---|
| 46 | s = input[i]; |
---|
| 47 | s *= set->mixer[i % channels]; |
---|
| 48 | s /= set->scale; |
---|
| 49 | output[i] = s; |
---|
| 50 | } |
---|
| 51 | } else { |
---|
| 52 | for (i = 0; i < samples; i++) { |
---|
| 53 | s = input[i]; |
---|
| 54 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
| 55 | s /= set->scale; |
---|
| 56 | output[i] = s; |
---|
| 57 | } |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | return 0; |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | int roar_amp_pcm_16bit (int16_t * output, int16_t * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 64 | int i; |
---|
| 65 | register int s; |
---|
| 66 | |
---|
| 67 | if ( !(input && output) ) |
---|
| 68 | return -1; |
---|
| 69 | |
---|
| 70 | if (set->rpg_mul == set->rpg_div) { |
---|
| 71 | for (i = 0; i < samples; i++) { |
---|
| 72 | s = input[i]; |
---|
| 73 | s *= set->mixer[i % channels]; |
---|
| 74 | s /= set->scale; |
---|
| 75 | output[i] = s; |
---|
| 76 | } |
---|
| 77 | } else { |
---|
| 78 | for (i = 0; i < samples; i++) { |
---|
| 79 | s = input[i]; |
---|
| 80 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
| 81 | s /= set->scale; |
---|
| 82 | output[i] = s; |
---|
| 83 | } |
---|
| 84 | } |
---|
| 85 | |
---|
| 86 | return 0; |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | int roar_amp_pcm_24bit (void * output, void * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 90 | return -1; |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | int roar_amp_pcm_32bit (int32_t * output, int32_t * input, int samples, int channels, struct roar_mixer_settings * set) { |
---|
| 94 | #ifdef ROAR_NATIVE_INT64 |
---|
| 95 | int i; |
---|
| 96 | ROAR_NATIVE_INT64 s; |
---|
| 97 | |
---|
| 98 | if ( !(input && output) ) |
---|
| 99 | return -1; |
---|
| 100 | |
---|
| 101 | if (set->rpg_mul == set->rpg_div) { |
---|
| 102 | for (i = 0; i < samples; i++) { |
---|
| 103 | s = input[i]; |
---|
| 104 | s *= set->mixer[i % channels]; |
---|
| 105 | s /= set->scale; |
---|
| 106 | output[i] = s; |
---|
| 107 | } |
---|
| 108 | } else { |
---|
| 109 | for (i = 0; i < samples; i++) { |
---|
| 110 | s = input[i]; |
---|
| 111 | s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div; |
---|
| 112 | s /= set->scale; |
---|
| 113 | output[i] = s; |
---|
| 114 | } |
---|
| 115 | } |
---|
| 116 | |
---|
| 117 | return 0; |
---|
| 118 | #else |
---|
| 119 | return -1; |
---|
| 120 | #endif |
---|
| 121 | } |
---|
[2935] | 122 | |
---|
| 123 | //ll |
---|