annotate src/xs_filter.c @ 280:b7e2938f2837

Changed method.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 25 Dec 2004 08:53:05 +0000
parents 69ec4290030c
children d5c79d5a0b60
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 #define XS_FILTER1(T, P, K) \
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 dataSize /= sizeof(g ## K ## int ## P); tmpo_ ## T = 0; \
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) { \
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 for (tmp_ ## T = 0, i = 0; i < oversampleFactor; i++) \
280
b7e2938f2837 Changed method.
Matti Hamalainen <ccr@tnsp.org>
parents: 278
diff changeset
33 tmp_ ## T += *(sp_ ## T ## P ++); \
b7e2938f2837 Changed method.
Matti Hamalainen <ccr@tnsp.org>
parents: 278
diff changeset
34 tmpo_ ## T = (tmp_ ## T + tmpo_ ## T ) / (oversampleFactor * 2); \
b7e2938f2837 Changed method.
Matti Hamalainen <ccr@tnsp.org>
parents: 278
diff changeset
35 *(dp_ ## T ## P ++) = tmpo_ ## T; \
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
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 gint xs_rateconv_filter(void *destBuf, void *srcBuf, gint audioFormat, gint oversampleFactor, gint dataSize)
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 guint32 tmp_u, tmpo_u;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 gint32 tmp_s, tmpo_s;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 XS_FVAR(u, 8, u);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 XS_FVAR(s, 8,);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 XS_FVAR(u, 16, u);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 XS_FVAR(s, 16,);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 gint i;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 if (dataSize <= 0)
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 return dataSize;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 switch (audioFormat) {
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 case FMT_U8:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 case FMT_S8:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 XS_FILTER1(s, 8,);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 break;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 case FMT_U16_BE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 case FMT_U16_LE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 case FMT_U16_NE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 case FMT_S16_BE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 case FMT_S16_LE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 case FMT_S16_NE:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 XS_FILTER1(s, 16,);
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 break;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 default:
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 return -1;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 }
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 return 0;
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 }
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74