annotate Plugins/Output/sun/resample.h @ 1562:71c91ebdb55c trunk

[svn] - further progress
author nenolod
date Thu, 10 Aug 2006 20:20:39 -0700
parents 705d4c089fce
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
758
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
1 /* XMMS - Cross-platform multimedia player
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
2 * Copyright (C) 1998-2001 Peter Alm, Mikael Alm, Olle Hallnas,
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
3 * Thomas Nilsson and 4Front Technologies
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
4 * Copyright (C) 1999-2001 Haavard Kvaalen
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
5 *
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
9 * (at your option) any later version.
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
10 *
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
14 * GNU General Public License for more details.
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
15 *
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
1459
705d4c089fce [svn] Fix postal code.
chainsaw
parents: 1458
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
758
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
19 */
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
20
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
21 #define NOT_NATIVE_ENDIAN \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
22 ((IS_BIG_ENDIAN && \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
23 (output.format.sun == AUDIO_ENCODING_SLINEAR_LE || \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
24 output.format.sun == AUDIO_ENCODING_ULINEAR_LE))|| \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
25 (!IS_BIG_ENDIAN && \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
26 (output.format.sun == AUDIO_ENCODING_SLINEAR_BE || \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
27 output.format.sun == AUDIO_ENCODING_ULINEAR_BE)))
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
28
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
29 #define RESAMPLE_STEREO(sample_type) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
30 do { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
31 const int shift = sizeof (sample_type); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
32 int i, in_samples, out_samples, x, delta; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
33 sample_type *inptr = (sample_type *)ob, *outptr; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
34 guint nlen = (((length >> shift) * espeed) / speed); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
35 \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
36 if (nlen == 0) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
37 break; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
38 nlen <<= shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
39 if (NOT_NATIVE_ENDIAN) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
40 sun_bswap16(ob, length); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
41 if (nlen > nbuffer_size) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
42 { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
43 nbuffer = g_realloc(nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
44 nbuffer_size = nlen; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
45 } \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
46 outptr = (sample_type *)nbuffer; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
47 in_samples = length >> shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
48 out_samples = nlen >> shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
49 delta = (in_samples << 12) / out_samples; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
50 for (x = 0, i = 0; i < out_samples; i++) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
51 { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
52 int x1, frac; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
53 x1 = (x >> 12) << 12; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
54 frac = x - x1; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
55 *outptr++ = \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
56 (sample_type) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
57 ((inptr[(x1 >> 12) << 1] * \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
58 ((1<<12) - frac) + \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
59 inptr[((x1 >> 12) + 1) << 1] * \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
60 frac) >> 12); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
61 *outptr++ = \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
62 (sample_type) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
63 ((inptr[((x1 >> 12) << 1) + 1] * \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
64 ((1<<12) - frac) + \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
65 inptr[(((x1 >> 12) + 1) << 1) + 1] * \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
66 frac) >> 12); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
67 x += delta; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
68 } \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
69 if (NOT_NATIVE_ENDIAN) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
70 sun_bswap16(nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
71 w = write_all(audio.fd, nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
72 } while (0)
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
73
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
74 #define RESAMPLE_MONO(sample_type) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
75 do { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
76 const int shift = sizeof (sample_type) - 1; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
77 int i, x, delta, in_samples, out_samples; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
78 sample_type *inptr = (sample_type *)ob, *outptr; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
79 guint nlen = (((length >> shift) * espeed) / speed); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
80 \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
81 if (nlen == 0) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
82 break; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
83 nlen <<= shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
84 if (NOT_NATIVE_ENDIAN) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
85 sun_bswap16(ob, length); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
86 if (nlen > nbuffer_size) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
87 { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
88 nbuffer = g_realloc(nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
89 nbuffer_size = nlen; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
90 } \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
91 outptr = (sample_type *)nbuffer; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
92 in_samples = length >> shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
93 out_samples = nlen >> shift; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
94 delta = ((length >> shift) << 12) / out_samples; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
95 for (x = 0, i = 0; i < out_samples; i++) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
96 { \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
97 int x1, frac; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
98 x1 = (x >> 12) << 12; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
99 frac = x - x1; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
100 *outptr++ = \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
101 (sample_type) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
102 ((inptr[x1 >> 12] * ((1<<12) - frac) + \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
103 inptr[(x1 >> 12) + 1] * frac) >> 12); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
104 x += delta; \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
105 } \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
106 if (NOT_NATIVE_ENDIAN) \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
107 sun_bswap16(nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
108 w = write_all(audio.fd, nbuffer, nlen); \
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
109 } while (0)
f9e8807ea6e5 [svn] - Initial port of the bsd/sun audio output plugin from XMMS. Needs testing.
nenolod
parents:
diff changeset
110