Mercurial > hg > xmms-sid
annotate src/xs_filter.c @ 328:7888e5d973b9
Minor cleanups
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 18 Jan 2005 06:30:03 +0000 |
parents | dd201740a720 |
children | 5e82b21d1914 |
rev | line source |
---|---|
278 | 1 /* |
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS) | |
3 | |
4 Audio rate-conversion filter | |
5 | |
324 | 6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org> |
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP) | |
278 | 8 |
9 This program is free software; you can redistribute it and/or modify | |
10 it under the terms of the GNU General Public License as published by | |
11 the Free Software Foundation; either version 2 of the License, or | |
12 (at your option) any later version. | |
13 | |
14 This program 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 program; if not, write to the Free Software | |
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
22 */ | |
324 | 23 #include "xs_filter.h" |
278 | 24 |
25 /* Let's do some preprocessor magic :) */ | |
26 #define XS_FVAR(T, P, K) g ## K ## int ## P *sp_ ## T ## P , *dp_ ## T ## P | |
27 | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
28 #define XS_FILTER1(T, P, K, Q) \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
29 dataSize /= sizeof(g ## K ## int ## P); tmpo = 0; \ |
278 | 30 sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \ |
31 dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \ | |
280 | 32 while (dataSize-- > 0) { \ |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
33 for (tmp = 0, i = 0; i < oversampleFactor; i++) \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
34 tmp += (gint32) ((gint ## P) (*(sp_ ## T ## P ++) Q)); \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
35 tmpo = (tmp + tmpo) / (oversampleFactor + 1); \ |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
36 *(dp_ ## T ## P ++) = ((g ## K ## int ## P) tmpo) Q ; \ |
278 | 37 } |
38 | |
328 | 39 gint xs_filter_rateconv(void *destBuf, void *srcBuf, const AFormat audioFormat, const gint oversampleFactor, const gint bufSize) |
278 | 40 { |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
41 gint32 tmp, tmpo; |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
42 XS_FVAR(s,8,); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
43 XS_FVAR(u,8,u); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
44 XS_FVAR(s,16,); |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
45 XS_FVAR(u,16,u); |
278 | 46 gint i; |
328 | 47 gint dataSize = bufSize; |
278 | 48 |
49 if (dataSize <= 0) | |
50 return dataSize; | |
51 | |
52 switch (audioFormat) { | |
53 case FMT_U8: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
54 XS_FILTER1(u,8,u, ^ 0x80) |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
55 break; |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
56 |
278 | 57 case FMT_S8: |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
58 XS_FILTER1(s,8,,) |
278 | 59 break; |
60 | |
61 | |
62 case FMT_U16_BE: | |
63 case FMT_U16_LE: | |
64 case FMT_U16_NE: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
65 XS_FILTER1(u,16,u, ^ 0x8000) |
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
66 break; |
278 | 67 |
68 case FMT_S16_BE: | |
69 case FMT_S16_LE: | |
70 case FMT_S16_NE: | |
312
7a5dc6898659
Fixed filter signedness bugs.
Matti Hamalainen <ccr@tnsp.org>
parents:
295
diff
changeset
|
71 XS_FILTER1(s,16,,) |
278 | 72 break; |
73 | |
74 default: | |
75 return -1; | |
76 } | |
77 | |
78 return 0; | |
79 } | |
80 |