comparison Plugins/Input/sid/xs_filter.c @ 269:1b82a9932b60 trunk

[svn] Import sid plugin. Ported from XMMS by giacomo.
author chainsaw
date Thu, 08 Dec 2005 15:12:12 -0800
parents
children f12d7e208b43
comparison
equal deleted inserted replaced
268:1368faba73c9 269:1b82a9932b60
1 /*
2 XMMS-SID - SIDPlay input plugin for X MultiMedia System (XMMS)
3
4 Audio rate-conversion filter
5
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
7 (C) Copyright 1999-2005 Tecnic Software productions (TNSP)
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 */
23 #include "xs_filter.h"
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
28 #define XS_FILTER1(T, P, K, Q) \
29 dataSize /= sizeof(g ## K ## int ## P); \
30 sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \
31 dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \
32 while (dataSize-- > 0) { \
33 for (tmp = 0, i = 0; i < oversampleFactor; i++) \
34 tmp += (gint32) ((gint ## P) (*(sp_ ## T ## P ++) Q)); \
35 xs_filter_mbn = (tmp + xs_filter_mbn) / (oversampleFactor + 1); \
36 *(dp_ ## T ## P ++) = ((g ## K ## int ## P) xs_filter_mbn) Q ; \
37 }
38
39
40 static gint32 xs_filter_mbn = 0;
41
42
43 gint xs_filter_rateconv(void *destBuf, void *srcBuf, const AFormat audioFormat, const gint oversampleFactor,
44 const gint bufSize)
45 {
46 static gint32 tmp;
47 XS_FVAR(s, 8,);
48 XS_FVAR(u, 8, u);
49 XS_FVAR(s, 16,);
50 XS_FVAR(u, 16, u);
51 gint i;
52 gint dataSize = bufSize;
53
54 if (dataSize <= 0)
55 return dataSize;
56
57 switch (audioFormat) {
58 case FMT_U8:
59 XS_FILTER1(u, 8, u, ^0x80)
60 break;
61
62 case FMT_S8:
63 XS_FILTER1(s, 8,,)
64 break;
65
66
67 case FMT_U16_BE:
68 case FMT_U16_LE:
69 case FMT_U16_NE:
70 XS_FILTER1(u, 16, u, ^0x8000)
71 break;
72
73 case FMT_S16_BE:
74 case FMT_S16_LE:
75 case FMT_S16_NE:
76 XS_FILTER1(s, 16,,)
77 break;
78
79 default:
80 return -1;
81 }
82
83 return 0;
84 }