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