source: roaraudio/libroardsp/amp.c @ 5439:7950543cabbc

Last change on this file since 5439:7950543cabbc was 5418:6abd8904a8c8, checked in by phi, 12 years ago

updated API for roar_amp_pcm*()

File size: 3.0 KB
Line 
1//amp.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2008-2012
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, 51 Franklin Street, Fifth Floor,
22 *  Boston, MA 02110-1301, USA.
23 *
24 */
25
26#include "libroardsp.h"
27
28int roar_amp_pcm(void * output, int bits, void * input, size_t samples, int channels, struct roar_mixer_settings * set) {
29 switch (bits) {
30  case  8: return roar_amp_pcm_8bit (output, input, samples, channels, set); break;
31  case 16: return roar_amp_pcm_16bit(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
37int roar_amp_pcm_8bit  (int8_t  * output, int8_t  * input, size_t samples, int channels, struct roar_mixer_settings * set) {
38 size_t   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
63int roar_amp_pcm_16bit (int16_t * output, int16_t * input, size_t samples, int channels, struct roar_mixer_settings * set) {
64 size_t    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
89int roar_amp_pcm_32bit (int32_t * output, int32_t * input, size_t samples, int channels, struct roar_mixer_settings * set) {
90#ifdef ROAR_NATIVE_INT64
91 size_t      i;
92 ROAR_NATIVE_INT64 s;
93
94 if ( !(input && output) )
95  return -1;
96
97 if (set->rpg_mul == set->rpg_div) {
98  for (i = 0; i < samples; i++) {
99   s  = input[i];
100   s *= set->mixer[i % channels];
101   s /= set->scale;
102   output[i] = s;
103  }
104 } else {
105  for (i = 0; i < samples; i++) {
106   s  = input[i];
107   s *= (set->mixer[i % channels] * set->rpg_mul) / set->rpg_div;
108   s /= set->scale;
109   output[i] = s;
110  }
111 }
112
113 return 0;
114#else
115 return -1;
116#endif
117}
118
119//ll
Note: See TracBrowser for help on using the repository browser.