annotate src/xs_filter.c @ 660:b0743dc9165d

Change tabs to 4 spaces, everywhere.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 02 Apr 2008 22:10:05 +0300
parents e5b302358312
children
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
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 312
diff changeset
6 Programmed and designed by Matti 'ccr' Hamalainen <ccr@tnsp.org>
422
d2e6682d3ef8 Copyright year update
Matti Hamalainen <ccr@tnsp.org>
parents: 412
diff changeset
7 (C) Copyright 1999-2007 Tecnic Software productions (TNSP)
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 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
10 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
11 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
12 (at your option) any later version.
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 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
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 GNU General Public License for more details.
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
412
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
19 You should have received a copy of the GNU General Public License along
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
20 with this program; if not, write to the Free Software Foundation, Inc.,
7f694e5a1493 Updated GNU GPL (new FSF address) and some cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 359
diff changeset
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
324
dd201740a720 Changed copyright text.
Matti Hamalainen <ccr@tnsp.org>
parents: 312
diff changeset
23 #include "xs_filter.h"
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 /* Let's do some preprocessor magic :) */
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 #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
27
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
28 #define XS_FILTER1(T, P, K, Q) \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
29 dataSize /= sizeof(g ## K ## int ## P); \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
30 sp_ ## T ## P = (g ## K ## int ## P *) srcBuf; \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
31 dp_ ## T ## P = (g ## K ## int ## P *) destBuf; \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
32 while (dataSize-- > 0) { \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
33 for (tmp = 0, i = 0; i < oversampleFactor; i++) \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
34 tmp += (gint32) ((gint ## P) (*(sp_ ## T ## P ++) Q)); \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
35 xs_filter_mbn = (tmp + xs_filter_mbn) / (oversampleFactor + 1); \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
36 *(dp_ ## T ## P ++) = ((g ## K ## int ## P) xs_filter_mbn) Q ; \
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
37 }
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
331
5e82b21d1914 Minor fix to filter (mean value does not get reset on every filtered audio block)
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
39
5e82b21d1914 Minor fix to filter (mean value does not get reset on every filtered audio block)
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
40 static gint32 xs_filter_mbn = 0;
5e82b21d1914 Minor fix to filter (mean value does not get reset on every filtered audio block)
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
41
5e82b21d1914 Minor fix to filter (mean value does not get reset on every filtered audio block)
Matti Hamalainen <ccr@tnsp.org>
parents: 328
diff changeset
42
513
e5b302358312 Cosmetics
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
43 gint xs_filter_rateconv(void *destBuf, void *srcBuf, const AFormat audioFormat,
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
44 const gint oversampleFactor, const gint bufSize)
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
46 static gint32 tmp;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
47 XS_FVAR(s, 8,);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
48 XS_FVAR(u, 8, u);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
49 XS_FVAR(s, 16,);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
50 XS_FVAR(u, 16, u);
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
51 gint i;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
52 gint dataSize = bufSize;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
53
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
54 if (dataSize <= 0)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
55 return dataSize;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
56
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
57 switch (audioFormat) {
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
58 case FMT_U8:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
59 XS_FILTER1(u, 8, u, ^0x80)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
60 break;
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
62 case FMT_S8:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
63 XS_FILTER1(s, 8,,)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
64 break;
359
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
65
b1a858b8cb1a Re-indentation all (non-generated) code.
Matti Hamalainen <ccr@tnsp.org>
parents: 331
diff changeset
66
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
67 case FMT_U16_BE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
68 case FMT_U16_LE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
69 case FMT_U16_NE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
70 XS_FILTER1(u, 16, u, ^0x8000)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
71 break;
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
73 case FMT_S16_BE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
74 case FMT_S16_LE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
75 case FMT_S16_NE:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
76 XS_FILTER1(s, 16,,)
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
77 break;
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
79 default:
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
80 return -1;
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
81 }
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
660
b0743dc9165d Change tabs to 4 spaces, everywhere.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
83 return 0;
278
69ec4290030c Added filtering code into CVS.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 }