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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 Audio rate-conversion filter
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 Written by Matti "ccr" Hamalainen <ccr@tnsp.org>
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 This program is free software; you can redistribute it and/or modify
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 it under the terms of the GNU General Public License as published by
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 the Free Software Foundation; either version 2 of the License, or
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 (at your option) any later version.
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 This program is distributed in the hope that it will be useful,
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 GNU General Public License for more details.
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 along with this program; if not, write to the Free Software
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 */
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #include "xmms-sid.h"
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 /* Let's do some preprocessor magic :) */
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 #define XS_FVAR(T, P, K) g ## K ## int ## P *sp_ ## T ## P , *dp_ ## T ## P
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \
280
b7e2938f2837 Changed method.
Matti Hamalainen <ccr@tnsp.org>
parents: 278
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 }
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
295
d5c79d5a0b60 gint -> AFormat
Matti Hamalainen <ccr@tnsp.org>
parents: 280
diff changeset
38 gint xs_rateconv_filter(void *destBuf, void *srcBuf, AFormat audioFormat, gint oversampleFactor, gint dataSize)
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 gint i;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 if (dataSize <= 0)
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 return dataSize;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 switch (audioFormat) {
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 break;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 case FMT_U16_BE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 case FMT_U16_LE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 case FMT_S16_BE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 case FMT_S16_LE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 break;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 default:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 return -1;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 }
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 return 0;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 }
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78