[2144] | 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 | |
---|
[2145] | 27 | int 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 | |
---|
| 38 | int 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 | |
---|
| 51 | int roar_remove_8 (int8_t * inout, int8_t * subs, int samples, struct roar_remove_state * state) { |
---|
| 52 | return -1; |
---|
| 53 | } |
---|
[2157] | 54 | int roar_remove_16 (int16_t * inout, int16_t * subs, int samples, struct roar_remove_state * state) { |
---|
[2145] | 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 | } |
---|
[2157] | 86 | int roar_remove_32 (int32_t * inout, int32_t * subs, int samples, struct roar_remove_state * state) { |
---|
[2145] | 87 | return -1; |
---|
| 88 | } |
---|
[2144] | 89 | |
---|
[2156] | 90 | int roar_remove_so (void * subout, void * in, int samples, int bits, struct roar_remove_state * state) { |
---|
| 91 | if ( subout == NULL || in == NULL || samples < 0 ) |
---|
| 92 | return -1; |
---|
| 93 | |
---|
| 94 | switch (bits) { |
---|
| 95 | case 16: return roar_remove_so16(subout, in, samples, state); break; |
---|
| 96 | } |
---|
| 97 | |
---|
| 98 | return -1; |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | int roar_remove_so16 (int16_t * subout, int16_t * in, int samples, struct roar_remove_state * state) { |
---|
| 102 | int i; |
---|
| 103 | register int32_t s; |
---|
| 104 | register int32_t peak; |
---|
| 105 | |
---|
| 106 | if ( state == NULL ) { |
---|
| 107 | for (i = 0; i < samples; i++) { |
---|
| 108 | s = -subout[i]; |
---|
| 109 | s += in[i]; |
---|
| 110 | subout[i] = s; |
---|
| 111 | } |
---|
| 112 | } else { |
---|
| 113 | peak = 65535; |
---|
| 114 | for (i = 0; i < samples; i++) { |
---|
| 115 | s = -subout[i]; |
---|
| 116 | s += in[i]; |
---|
| 117 | s = s < 0 ? -s : s; // we true 32 bit, not int operation here |
---|
| 118 | if ( s > peak ) |
---|
| 119 | peak = s; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | for (i = 0; i < samples; i++) { |
---|
| 123 | s = -subout[i]; |
---|
| 124 | s *= 65535; |
---|
| 125 | s /= peak; |
---|
| 126 | s += in[i]; |
---|
| 127 | subout[i] = s; |
---|
| 128 | } |
---|
| 129 | } |
---|
| 130 | |
---|
| 131 | return 0; |
---|
| 132 | } |
---|
| 133 | |
---|
[2144] | 134 | //ll |
---|