Mercurial > hg > xmms-sid
annotate src/xs_filter.c @ 312:7a5dc6898659
Fixed filter signedness bugs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 30 Dec 2004 12:29:02 +0000 |
parents | d5c79d5a0b60 |
children | dd201740a720 |
rev | line source |
---|---|
278 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Audio rate-conversion filter | |
5 | |
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org> | |
7 | |
8 This program is free software; you can redistribute it and/or modify | |
9 it under the terms of the GNU General Public License as published by | |
10 the Free Software Foundation; either version 2 of the License, or | |
11 (at your option) any later version. | |
12 | |
13 This program is distributed in the hope that it will be useful, | |
14 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 GNU General Public License for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
19 along with this program; if not, write to the Free Software | |
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
21 */ | |
22 #include "xmms-sid.h" | |
23 | |
24 /* Let's do some preprocessor magic :) */ | |
25 #define XS_FVAR(T, P, K) g ## K ## int ## P *sp_ ## T ## P , *dp_ ## T ## P | |
26 | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
27 #define XS_FILTER1(T, P, K, Q) \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
28 dataSize /= sizeof(g ## K ## int ## P); tmpo = 0; \ |
278 | 29 sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \ |
30 dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \ | |
280 | 31 while (dataSize-- > 0) { \ |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
32 for (tmp = 0, i = 0; i < oversampleFactor; i++) \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
33 tmp += (gint32) ((gint ## P) (*(sp_ ## T ## P ++) Q)); \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
34 tmpo = (tmp + tmpo) / (oversampleFactor + 1); \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
35 *(dp_ ## T ## P ++) = ((g ## K ## int ## P) tmpo) Q ; \ |
278 | 36 } |
37 | |
295 | 38 gint xs_rateconv_filter(void *destBuf, void *srcBuf, AFormat audioFormat, gint oversampleFactor, gint dataSize) |
278 | 39 { |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
40 gint32 tmp, tmpo; |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
41 XS_FVAR(s,8,); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
42 XS_FVAR(u,8,u); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
43 XS_FVAR(s,16,); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
44 XS_FVAR(u,16,u); |
278 | 45 gint i; |
46 | |
47 if (dataSize <= 0) | |
48 return dataSize; | |
49 | |
50 switch (audioFormat) { | |
51 case FMT_U8: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
52 XS_FILTER1(u,8,u, ^ 0x80) |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
53 break; |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
54 |
278 | 55 case FMT_S8: |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
56 XS_FILTER1(s,8,,) |
278 | 57 break; |
58 | |
59 | |
60 case FMT_U16_BE: | |
61 case FMT_U16_LE: | |
62 case FMT_U16_NE: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
63 XS_FILTER1(u,16,u, ^ 0x8000) |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
64 break; |
278 | 65 |
66 case FMT_S16_BE: | |
67 case FMT_S16_LE: | |
68 case FMT_S16_NE: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
69 XS_FILTER1(s,16,,) |
278 | 70 break; |
71 | |
72 default: | |
73 return -1; | |
74 } | |
75 | |
76 return 0; | |
77 } | |
78 |