source: roaraudio/libroardsp/remove.c @ 2145:ad5260b8af44

Last change on this file since 2145:ad5260b8af44 was 2145:ad5260b8af44, checked in by phi, 15 years ago

updated structs and prototypes, implemented a first 16 bit version

File size: 2.3 KB
Line 
1//remove.c:
2
3/*
4 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009
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
27int roar_remove_init (struct roar_remove_state * state) {
28 if ( state == NULL )
29  return -1;
30
31 memset(state, 0, sizeof(struct roar_remove_state));
32
33 state->old = 65535;
34
35 return 0;
36}
37
38int roar_remove      (void * inout, void * subs, int samples, int bits, struct roar_remove_state * state) {
39 if ( inout == NULL || subs == NULL || samples < 0 )
40  return -1;
41
42 switch (bits) {
43  case 8:  return roar_remove_8 (inout, subs, samples, state); break;
44  case 16: return roar_remove_16(inout, subs, samples, state); break;
45  case 32: return roar_remove_32(inout, subs, samples, state); break;
46 }
47
48 return -1;
49}
50
51int roar_remove_8    (int8_t  * inout, int8_t  * subs, int samples, struct roar_remove_state * state) {
52 return -1;
53}
54int roar_remove_16   (int8_t  * inout, int8_t  * subs, int samples, struct roar_remove_state * state) {
55 int i;
56 register int32_t s;
57 register int32_t peak;
58
59 if ( state == NULL ) {
60  for (i = 0; i < samples; i++) {
61   s  = inout[i];
62   s -= subs[i];
63   inout[i] = s;
64  }
65 } else {
66  peak = 65535;
67  for (i = 0; i < samples; i++) {
68   s  = inout[i];
69   s -= subs[i];
70   s  = s < 0 ? -s : s; // we true 32 bit, not int operation here
71   if ( s > peak )
72    peak = s;
73  }
74
75  for (i = 0; i < samples; i++) {
76   s  = -subs[i];
77   s *=  65535;
78   s /=  peak;
79   s +=  inout[i];
80   inout[i] = s;
81  }
82 }
83
84 return 0;
85}
86int roar_remove_32   (int8_t  * inout, int8_t  * subs, int samples, struct roar_remove_state * state) {
87 return -1;
88}
89
90//ll
Note: See TracBrowser for help on using the repository browser.