aboutsummaryrefslogtreecommitdiffstats
path: root/sound/core
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2007-08-08 09:50:58 -0400
committerJaroslav Kysela <perex@perex.cz>2007-10-16 09:58:31 -0400
commit9390ec85c0ab98444140190f936a37fa4eb945a2 (patch)
treee5b464f2462335399e8e59203617439fb77ff51e /sound/core
parent887f9f0253ba4a52f38810f3056cdf040a6157b3 (diff)
[ALSA] Simplify the format conversion in PCM OSS emulation
Simplify the format conversion code in PCM OSS emulation. This patch also adds the support of 3bytes 24bit formats with linear and mulaw, but they are not enabled in pcm_plugin.c yet. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/core')
-rw-r--r--sound/core/oss/linear.c80
-rw-r--r--sound/core/oss/mulaw.c83
-rw-r--r--sound/core/oss/plugin_ops.h370
3 files changed, 97 insertions, 436 deletions
diff --git a/sound/core/oss/linear.c b/sound/core/oss/linear.c
index a3cfe7cb5873..41b2885d0903 100644
--- a/sound/core/oss/linear.c
+++ b/sound/core/oss/linear.c
@@ -31,19 +31,34 @@
31 */ 31 */
32 32
33struct linear_priv { 33struct linear_priv {
34 int conv; 34 int cvt_endian; /* need endian conversion? */
35 unsigned int src_ofs; /* byte offset in source format */
36 unsigned int dst_ofs; /* byte soffset in destination format */
37 unsigned int copy_ofs; /* byte offset in temporary u32 data */
38 unsigned int dst_bytes; /* byte size of destination format */
39 unsigned int copy_bytes; /* bytes to copy per conversion */
40 unsigned int flip; /* MSB flip for signeness, done after endian conv */
35}; 41};
36 42
43static inline void do_convert(struct linear_priv *data,
44 unsigned char *dst, unsigned char *src)
45{
46 unsigned int tmp = 0;
47 unsigned char *p = (unsigned char *)&tmp;
48
49 memcpy(p + data->copy_ofs, src + data->src_ofs, data->copy_bytes);
50 if (data->cvt_endian)
51 tmp = swab32(tmp);
52 tmp ^= data->flip;
53 memcpy(dst, p + data->dst_ofs, data->dst_bytes);
54}
55
37static void convert(struct snd_pcm_plugin *plugin, 56static void convert(struct snd_pcm_plugin *plugin,
38 const struct snd_pcm_plugin_channel *src_channels, 57 const struct snd_pcm_plugin_channel *src_channels,
39 struct snd_pcm_plugin_channel *dst_channels, 58 struct snd_pcm_plugin_channel *dst_channels,
40 snd_pcm_uframes_t frames) 59 snd_pcm_uframes_t frames)
41{ 60{
42#define CONV_LABELS
43#include "plugin_ops.h"
44#undef CONV_LABELS
45 struct linear_priv *data = (struct linear_priv *)plugin->extra_data; 61 struct linear_priv *data = (struct linear_priv *)plugin->extra_data;
46 void *conv = conv_labels[data->conv];
47 int channel; 62 int channel;
48 int nchannels = plugin->src_format.channels; 63 int nchannels = plugin->src_format.channels;
49 for (channel = 0; channel < nchannels; ++channel) { 64 for (channel = 0; channel < nchannels; ++channel) {
@@ -64,11 +79,7 @@ static void convert(struct snd_pcm_plugin *plugin,
64 dst_step = dst_channels[channel].area.step / 8; 79 dst_step = dst_channels[channel].area.step / 8;
65 frames1 = frames; 80 frames1 = frames;
66 while (frames1-- > 0) { 81 while (frames1-- > 0) {
67 goto *conv; 82 do_convert(data, dst, src);
68#define CONV_END after
69#include "plugin_ops.h"
70#undef CONV_END
71 after:
72 src += src_step; 83 src += src_step;
73 dst += dst_step; 84 dst += dst_step;
74 } 85 }
@@ -103,29 +114,36 @@ static snd_pcm_sframes_t linear_transfer(struct snd_pcm_plugin *plugin,
103 return frames; 114 return frames;
104} 115}
105 116
106static int conv_index(int src_format, int dst_format) 117static void init_data(struct linear_priv *data, int src_format, int dst_format)
107{ 118{
108 int src_endian, dst_endian, sign, src_width, dst_width; 119 int src_le, dst_le, src_bytes, dst_bytes;
109 120
110 sign = (snd_pcm_format_signed(src_format) != 121 src_bytes = snd_pcm_format_width(src_format) / 8;
111 snd_pcm_format_signed(dst_format)); 122 dst_bytes = snd_pcm_format_width(dst_format) / 8;
112#ifdef SNDRV_LITTLE_ENDIAN 123 src_le = snd_pcm_format_little_endian(src_format) > 0;
113 src_endian = snd_pcm_format_big_endian(src_format); 124 dst_le = snd_pcm_format_little_endian(dst_format) > 0;
114 dst_endian = snd_pcm_format_big_endian(dst_format);
115#else
116 src_endian = snd_pcm_format_little_endian(src_format);
117 dst_endian = snd_pcm_format_little_endian(dst_format);
118#endif
119
120 if (src_endian < 0)
121 src_endian = 0;
122 if (dst_endian < 0)
123 dst_endian = 0;
124 125
125 src_width = snd_pcm_format_width(src_format) / 8 - 1; 126 data->dst_bytes = dst_bytes;
126 dst_width = snd_pcm_format_width(dst_format) / 8 - 1; 127 data->cvt_endian = src_le != dst_le;
127 128 data->copy_bytes = src_bytes < dst_bytes ? src_bytes : dst_bytes;
128 return src_width * 32 + src_endian * 16 + sign * 8 + dst_width * 2 + dst_endian; 129 if (src_le) {
130 data->copy_ofs = 4 - data->copy_bytes;
131 data->src_ofs = src_bytes - data->copy_bytes;
132 } else
133 data->src_ofs = snd_pcm_format_physical_width(src_format) / 8 -
134 src_bytes;
135 if (dst_le)
136 data->dst_ofs = 4 - data->dst_bytes;
137 else
138 data->dst_ofs = snd_pcm_format_physical_width(dst_format) / 8 -
139 dst_bytes;
140 if (snd_pcm_format_signed(src_format) !=
141 snd_pcm_format_signed(dst_format)) {
142 if (dst_le)
143 data->flip = cpu_to_le32(0x80000000);
144 else
145 data->flip = cpu_to_be32(0x80000000);
146 }
129} 147}
130 148
131int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug, 149int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
@@ -151,7 +169,7 @@ int snd_pcm_plugin_build_linear(struct snd_pcm_substream *plug,
151 if (err < 0) 169 if (err < 0)
152 return err; 170 return err;
153 data = (struct linear_priv *)plugin->extra_data; 171 data = (struct linear_priv *)plugin->extra_data;
154 data->conv = conv_index(src_format->format, dst_format->format); 172 init_data(data, src_format->format, dst_format->format);
155 plugin->transfer = linear_transfer; 173 plugin->transfer = linear_transfer;
156 *r_plugin = plugin; 174 *r_plugin = plugin;
157 return 0; 175 return 0;
diff --git a/sound/core/oss/mulaw.c b/sound/core/oss/mulaw.c
index 91b62429b323..3da3b81626d3 100644
--- a/sound/core/oss/mulaw.c
+++ b/sound/core/oss/mulaw.c
@@ -146,19 +146,32 @@ typedef void (*mulaw_f)(struct snd_pcm_plugin *plugin,
146 146
147struct mulaw_priv { 147struct mulaw_priv {
148 mulaw_f func; 148 mulaw_f func;
149 int conv; 149 int cvt_endian; /* need endian conversion? */
150 unsigned int native_ofs; /* byte offset in native format */
151 unsigned int copy_ofs; /* byte offset in s16 format */
152 unsigned int native_bytes; /* byte size of the native format */
153 unsigned int copy_bytes; /* bytes to copy per conversion */
154 u16 flip; /* MSB flip for signedness, done after endian conversion */
150}; 155};
151 156
157static inline void cvt_s16_to_native(struct mulaw_priv *data,
158 unsigned char *dst, u16 sample)
159{
160 sample ^= data->flip;
161 if (data->cvt_endian)
162 sample = swab16(sample);
163 if (data->native_bytes > data->copy_bytes)
164 memset(dst, 0, data->native_bytes);
165 memcpy(dst + data->native_ofs, (char *)&sample + data->copy_ofs,
166 data->copy_bytes);
167}
168
152static void mulaw_decode(struct snd_pcm_plugin *plugin, 169static void mulaw_decode(struct snd_pcm_plugin *plugin,
153 const struct snd_pcm_plugin_channel *src_channels, 170 const struct snd_pcm_plugin_channel *src_channels,
154 struct snd_pcm_plugin_channel *dst_channels, 171 struct snd_pcm_plugin_channel *dst_channels,
155 snd_pcm_uframes_t frames) 172 snd_pcm_uframes_t frames)
156{ 173{
157#define PUT_S16_LABELS
158#include "plugin_ops.h"
159#undef PUT_S16_LABELS
160 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data; 174 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data;
161 void *put = put_s16_labels[data->conv];
162 int channel; 175 int channel;
163 int nchannels = plugin->src_format.channels; 176 int nchannels = plugin->src_format.channels;
164 for (channel = 0; channel < nchannels; ++channel) { 177 for (channel = 0; channel < nchannels; ++channel) {
@@ -180,30 +193,33 @@ static void mulaw_decode(struct snd_pcm_plugin *plugin,
180 frames1 = frames; 193 frames1 = frames;
181 while (frames1-- > 0) { 194 while (frames1-- > 0) {
182 signed short sample = ulaw2linear(*src); 195 signed short sample = ulaw2linear(*src);
183 goto *put; 196 cvt_s16_to_native(data, dst, sample);
184#define PUT_S16_END after
185#include "plugin_ops.h"
186#undef PUT_S16_END
187 after:
188 src += src_step; 197 src += src_step;
189 dst += dst_step; 198 dst += dst_step;
190 } 199 }
191 } 200 }
192} 201}
193 202
203static inline signed short cvt_native_to_s16(struct mulaw_priv *data,
204 unsigned char *src)
205{
206 u16 sample = 0;
207 memcpy((char *)&sample + data->copy_ofs, src + data->native_ofs,
208 data->copy_bytes);
209 if (data->cvt_endian)
210 sample = swab16(sample);
211 sample ^= data->flip;
212 return (signed short)sample;
213}
214
194static void mulaw_encode(struct snd_pcm_plugin *plugin, 215static void mulaw_encode(struct snd_pcm_plugin *plugin,
195 const struct snd_pcm_plugin_channel *src_channels, 216 const struct snd_pcm_plugin_channel *src_channels,
196 struct snd_pcm_plugin_channel *dst_channels, 217 struct snd_pcm_plugin_channel *dst_channels,
197 snd_pcm_uframes_t frames) 218 snd_pcm_uframes_t frames)
198{ 219{
199#define GET_S16_LABELS
200#include "plugin_ops.h"
201#undef GET_S16_LABELS
202 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data; 220 struct mulaw_priv *data = (struct mulaw_priv *)plugin->extra_data;
203 void *get = get_s16_labels[data->conv];
204 int channel; 221 int channel;
205 int nchannels = plugin->src_format.channels; 222 int nchannels = plugin->src_format.channels;
206 signed short sample = 0;
207 for (channel = 0; channel < nchannels; ++channel) { 223 for (channel = 0; channel < nchannels; ++channel) {
208 char *src; 224 char *src;
209 char *dst; 225 char *dst;
@@ -222,11 +238,7 @@ static void mulaw_encode(struct snd_pcm_plugin *plugin,
222 dst_step = dst_channels[channel].area.step / 8; 238 dst_step = dst_channels[channel].area.step / 8;
223 frames1 = frames; 239 frames1 = frames;
224 while (frames1-- > 0) { 240 while (frames1-- > 0) {
225 goto *get; 241 signed short sample = cvt_native_to_s16(data, src);
226#define GET_S16_END after
227#include "plugin_ops.h"
228#undef GET_S16_END
229 after:
230 *dst = linear2ulaw(sample); 242 *dst = linear2ulaw(sample);
231 src += src_step; 243 src += src_step;
232 dst += dst_step; 244 dst += dst_step;
@@ -262,23 +274,25 @@ static snd_pcm_sframes_t mulaw_transfer(struct snd_pcm_plugin *plugin,
262 return frames; 274 return frames;
263} 275}
264 276
265static int getput_index(int format) 277static void init_data(struct mulaw_priv *data, int format)
266{ 278{
267 int sign, width, endian;
268 sign = !snd_pcm_format_signed(format);
269 width = snd_pcm_format_width(format) / 8 - 1;
270 if (width < 0 || width > 3) {
271 snd_printk(KERN_ERR "snd-pcm-oss: invalid format %d\n", format);
272 width = 0;
273 }
274#ifdef SNDRV_LITTLE_ENDIAN 279#ifdef SNDRV_LITTLE_ENDIAN
275 endian = snd_pcm_format_big_endian(format); 280 data->cvt_endian = snd_pcm_format_big_endian(format) > 0;
276#else 281#else
277 endian = snd_pcm_format_little_endian(format); 282 data->cvt_endian = snd_pcm_format_little_endian(format) > 0;
278#endif 283#endif
279 if (endian < 0) 284 if (!snd_pcm_format_signed(format))
280 endian = 0; 285 data->flip = 0x8000;
281 return width * 4 + endian * 2 + sign; 286 data->native_bytes = snd_pcm_format_physical_width(format) / 8;
287 data->copy_bytes = data->native_bytes < 2 ? 1 : 2;
288 if (snd_pcm_format_little_endian(format)) {
289 data->native_ofs = data->native_bytes - data->copy_bytes;
290 data->copy_ofs = 2 - data->copy_bytes;
291 } else {
292 /* S24 in 4bytes need an 1 byte offset */
293 data->native_ofs = data->native_bytes -
294 snd_pcm_format_width(format) / 8;
295 }
282} 296}
283 297
284int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug, 298int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
@@ -319,8 +333,7 @@ int snd_pcm_plugin_build_mulaw(struct snd_pcm_substream *plug,
319 return err; 333 return err;
320 data = (struct mulaw_priv *)plugin->extra_data; 334 data = (struct mulaw_priv *)plugin->extra_data;
321 data->func = func; 335 data->func = func;
322 data->conv = getput_index(format->format); 336 init_data(data, format->format);
323 snd_assert(data->conv >= 0 && data->conv < 4*2*2, return -EINVAL);
324 plugin->transfer = mulaw_transfer; 337 plugin->transfer = mulaw_transfer;
325 *r_plugin = plugin; 338 *r_plugin = plugin;
326 return 0; 339 return 0;
diff --git a/sound/core/oss/plugin_ops.h b/sound/core/oss/plugin_ops.h
deleted file mode 100644
index 1f5bde4631f1..000000000000
--- a/sound/core/oss/plugin_ops.h
+++ /dev/null
@@ -1,370 +0,0 @@
1/*
2 * Plugin sample operators with fast switch
3 * Copyright (c) 2000 by Jaroslav Kysela <perex@suse.cz>
4 *
5 *
6 * This library is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Library General Public License as
8 * published by the Free Software Foundation; either version 2 of
9 * the License, or (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 Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22
23#define as_u8(ptr) (*(u_int8_t*)(ptr))
24#define as_u16(ptr) (*(u_int16_t*)(ptr))
25#define as_u32(ptr) (*(u_int32_t*)(ptr))
26#define as_u64(ptr) (*(u_int64_t*)(ptr))
27#define as_s8(ptr) (*(int8_t*)(ptr))
28#define as_s16(ptr) (*(int16_t*)(ptr))
29#define as_s32(ptr) (*(int32_t*)(ptr))
30#define as_s64(ptr) (*(int64_t*)(ptr))
31
32#ifdef COPY_LABELS
33static void *copy_labels[4] = {
34 &&copy_8,
35 &&copy_16,
36 &&copy_32,
37 &&copy_64
38};
39#endif
40
41#ifdef COPY_END
42while(0) {
43copy_8: as_s8(dst) = as_s8(src); goto COPY_END;
44copy_16: as_s16(dst) = as_s16(src); goto COPY_END;
45copy_32: as_s32(dst) = as_s32(src); goto COPY_END;
46copy_64: as_s64(dst) = as_s64(src); goto COPY_END;
47}
48#endif
49
50#ifdef CONV_LABELS
51/* src_wid src_endswap sign_toggle dst_wid dst_endswap */
52static void *conv_labels[4 * 2 * 2 * 4 * 2] = {
53 &&conv_xxx1_xxx1, /* 8h -> 8h */
54 &&conv_xxx1_xxx1, /* 8h -> 8s */
55 &&conv_xxx1_xx10, /* 8h -> 16h */
56 &&conv_xxx1_xx01, /* 8h -> 16s */
57 &&conv_xxx1_x100, /* 8h -> 24h */
58 &&conv_xxx1_001x, /* 8h -> 24s */
59 &&conv_xxx1_1000, /* 8h -> 32h */
60 &&conv_xxx1_0001, /* 8h -> 32s */
61 &&conv_xxx1_xxx9, /* 8h ^> 8h */
62 &&conv_xxx1_xxx9, /* 8h ^> 8s */
63 &&conv_xxx1_xx90, /* 8h ^> 16h */
64 &&conv_xxx1_xx09, /* 8h ^> 16s */
65 &&conv_xxx1_x900, /* 8h ^> 24h */
66 &&conv_xxx1_009x, /* 8h ^> 24s */
67 &&conv_xxx1_9000, /* 8h ^> 32h */
68 &&conv_xxx1_0009, /* 8h ^> 32s */
69 &&conv_xxx1_xxx1, /* 8s -> 8h */
70 &&conv_xxx1_xxx1, /* 8s -> 8s */
71 &&conv_xxx1_xx10, /* 8s -> 16h */
72 &&conv_xxx1_xx01, /* 8s -> 16s */
73 &&conv_xxx1_x100, /* 8s -> 24h */
74 &&conv_xxx1_001x, /* 8s -> 24s */
75 &&conv_xxx1_1000, /* 8s -> 32h */
76 &&conv_xxx1_0001, /* 8s -> 32s */
77 &&conv_xxx1_xxx9, /* 8s ^> 8h */
78 &&conv_xxx1_xxx9, /* 8s ^> 8s */
79 &&conv_xxx1_xx90, /* 8s ^> 16h */
80 &&conv_xxx1_xx09, /* 8s ^> 16s */
81 &&conv_xxx1_x900, /* 8s ^> 24h */
82 &&conv_xxx1_009x, /* 8s ^> 24s */
83 &&conv_xxx1_9000, /* 8s ^> 32h */
84 &&conv_xxx1_0009, /* 8s ^> 32s */
85 &&conv_xx12_xxx1, /* 16h -> 8h */
86 &&conv_xx12_xxx1, /* 16h -> 8s */
87 &&conv_xx12_xx12, /* 16h -> 16h */
88 &&conv_xx12_xx21, /* 16h -> 16s */
89 &&conv_xx12_x120, /* 16h -> 24h */
90 &&conv_xx12_021x, /* 16h -> 24s */
91 &&conv_xx12_1200, /* 16h -> 32h */
92 &&conv_xx12_0021, /* 16h -> 32s */
93 &&conv_xx12_xxx9, /* 16h ^> 8h */
94 &&conv_xx12_xxx9, /* 16h ^> 8s */
95 &&conv_xx12_xx92, /* 16h ^> 16h */
96 &&conv_xx12_xx29, /* 16h ^> 16s */
97 &&conv_xx12_x920, /* 16h ^> 24h */
98 &&conv_xx12_029x, /* 16h ^> 24s */
99 &&conv_xx12_9200, /* 16h ^> 32h */
100 &&conv_xx12_0029, /* 16h ^> 32s */
101 &&conv_xx12_xxx2, /* 16s -> 8h */
102 &&conv_xx12_xxx2, /* 16s -> 8s */
103 &&conv_xx12_xx21, /* 16s -> 16h */
104 &&conv_xx12_xx12, /* 16s -> 16s */
105 &&conv_xx12_x210, /* 16s -> 24h */
106 &&conv_xx12_012x, /* 16s -> 24s */
107 &&conv_xx12_2100, /* 16s -> 32h */
108 &&conv_xx12_0012, /* 16s -> 32s */
109 &&conv_xx12_xxxA, /* 16s ^> 8h */
110 &&conv_xx12_xxxA, /* 16s ^> 8s */
111 &&conv_xx12_xxA1, /* 16s ^> 16h */
112 &&conv_xx12_xx1A, /* 16s ^> 16s */
113 &&conv_xx12_xA10, /* 16s ^> 24h */
114 &&conv_xx12_01Ax, /* 16s ^> 24s */
115 &&conv_xx12_A100, /* 16s ^> 32h */
116 &&conv_xx12_001A, /* 16s ^> 32s */
117 &&conv_x123_xxx1, /* 24h -> 8h */
118 &&conv_x123_xxx1, /* 24h -> 8s */
119 &&conv_x123_xx12, /* 24h -> 16h */
120 &&conv_x123_xx21, /* 24h -> 16s */
121 &&conv_x123_x123, /* 24h -> 24h */
122 &&conv_x123_321x, /* 24h -> 24s */
123 &&conv_x123_1230, /* 24h -> 32h */
124 &&conv_x123_0321, /* 24h -> 32s */
125 &&conv_x123_xxx9, /* 24h ^> 8h */
126 &&conv_x123_xxx9, /* 24h ^> 8s */
127 &&conv_x123_xx92, /* 24h ^> 16h */
128 &&conv_x123_xx29, /* 24h ^> 16s */
129 &&conv_x123_x923, /* 24h ^> 24h */
130 &&conv_x123_329x, /* 24h ^> 24s */
131 &&conv_x123_9230, /* 24h ^> 32h */
132 &&conv_x123_0329, /* 24h ^> 32s */
133 &&conv_123x_xxx3, /* 24s -> 8h */
134 &&conv_123x_xxx3, /* 24s -> 8s */
135 &&conv_123x_xx32, /* 24s -> 16h */
136 &&conv_123x_xx23, /* 24s -> 16s */
137 &&conv_123x_x321, /* 24s -> 24h */
138 &&conv_123x_123x, /* 24s -> 24s */
139 &&conv_123x_3210, /* 24s -> 32h */
140 &&conv_123x_0123, /* 24s -> 32s */
141 &&conv_123x_xxxB, /* 24s ^> 8h */
142 &&conv_123x_xxxB, /* 24s ^> 8s */
143 &&conv_123x_xxB2, /* 24s ^> 16h */
144 &&conv_123x_xx2B, /* 24s ^> 16s */
145 &&conv_123x_xB21, /* 24s ^> 24h */
146 &&conv_123x_12Bx, /* 24s ^> 24s */
147 &&conv_123x_B210, /* 24s ^> 32h */
148 &&conv_123x_012B, /* 24s ^> 32s */
149 &&conv_1234_xxx1, /* 32h -> 8h */
150 &&conv_1234_xxx1, /* 32h -> 8s */
151 &&conv_1234_xx12, /* 32h -> 16h */
152 &&conv_1234_xx21, /* 32h -> 16s */
153 &&conv_1234_x123, /* 32h -> 24h */
154 &&conv_1234_321x, /* 32h -> 24s */
155 &&conv_1234_1234, /* 32h -> 32h */
156 &&conv_1234_4321, /* 32h -> 32s */
157 &&conv_1234_xxx9, /* 32h ^> 8h */
158 &&conv_1234_xxx9, /* 32h ^> 8s */
159 &&conv_1234_xx92, /* 32h ^> 16h */
160 &&conv_1234_xx29, /* 32h ^> 16s */
161 &&conv_1234_x923, /* 32h ^> 24h */
162 &&conv_1234_329x, /* 32h ^> 24s */
163 &&conv_1234_9234, /* 32h ^> 32h */
164 &&conv_1234_4329, /* 32h ^> 32s */
165 &&conv_1234_xxx4, /* 32s -> 8h */
166 &&conv_1234_xxx4, /* 32s -> 8s */
167 &&conv_1234_xx43, /* 32s -> 16h */
168 &&conv_1234_xx34, /* 32s -> 16s */
169 &&conv_1234_x432, /* 32s -> 24h */
170 &&conv_1234_234x, /* 32s -> 24s */
171 &&conv_1234_4321, /* 32s -> 32h */
172 &&conv_1234_1234, /* 32s -> 32s */
173 &&conv_1234_xxxC, /* 32s ^> 8h */
174 &&conv_1234_xxxC, /* 32s ^> 8s */
175 &&conv_1234_xxC3, /* 32s ^> 16h */
176 &&conv_1234_xx3C, /* 32s ^> 16s */
177 &&conv_1234_xC32, /* 32s ^> 24h */
178 &&conv_1234_23Cx, /* 32s ^> 24s */
179 &&conv_1234_C321, /* 32s ^> 32h */
180 &&conv_1234_123C, /* 32s ^> 32s */
181};
182#endif
183
184#ifdef CONV_END
185while(0) {
186conv_xxx1_xxx1: as_u8(dst) = as_u8(src); goto CONV_END;
187conv_xxx1_xx10: as_u16(dst) = (u_int16_t)as_u8(src) << 8; goto CONV_END;
188conv_xxx1_xx01: as_u16(dst) = (u_int16_t)as_u8(src); goto CONV_END;
189conv_xxx1_x100: as_u32(dst) = (u_int32_t)as_u8(src) << 16; goto CONV_END;
190conv_xxx1_001x: as_u32(dst) = (u_int32_t)as_u8(src) << 8; goto CONV_END;
191conv_xxx1_1000: as_u32(dst) = (u_int32_t)as_u8(src) << 24; goto CONV_END;
192conv_xxx1_0001: as_u32(dst) = (u_int32_t)as_u8(src); goto CONV_END;
193conv_xxx1_xxx9: as_u8(dst) = as_u8(src) ^ 0x80; goto CONV_END;
194conv_xxx1_xx90: as_u16(dst) = (u_int16_t)(as_u8(src) ^ 0x80) << 8; goto CONV_END;
195conv_xxx1_xx09: as_u16(dst) = (u_int16_t)(as_u8(src) ^ 0x80); goto CONV_END;
196conv_xxx1_x900: as_u32(dst) = (u_int32_t)(as_u8(src) ^ 0x80) << 16; goto CONV_END;
197conv_xxx1_009x: as_u32(dst) = (u_int32_t)(as_u8(src) ^ 0x80) << 8; goto CONV_END;
198conv_xxx1_9000: as_u32(dst) = (u_int32_t)(as_u8(src) ^ 0x80) << 24; goto CONV_END;
199conv_xxx1_0009: as_u32(dst) = (u_int32_t)(as_u8(src) ^ 0x80); goto CONV_END;
200conv_xx12_xxx1: as_u8(dst) = as_u16(src) >> 8; goto CONV_END;
201conv_xx12_xx12: as_u16(dst) = as_u16(src); goto CONV_END;
202conv_xx12_xx21: as_u16(dst) = swab16(as_u16(src)); goto CONV_END;
203conv_xx12_x120: as_u32(dst) = (u_int32_t)as_u16(src) << 8; goto CONV_END;
204conv_xx12_021x: as_u32(dst) = (u_int32_t)swab16(as_u16(src)) << 8; goto CONV_END;
205conv_xx12_1200: as_u32(dst) = (u_int32_t)as_u16(src) << 16; goto CONV_END;
206conv_xx12_0021: as_u32(dst) = (u_int32_t)swab16(as_u16(src)); goto CONV_END;
207conv_xx12_xxx9: as_u8(dst) = (as_u16(src) >> 8) ^ 0x80; goto CONV_END;
208conv_xx12_xx92: as_u16(dst) = as_u16(src) ^ 0x8000; goto CONV_END;
209conv_xx12_xx29: as_u16(dst) = swab16(as_u16(src)) ^ 0x80; goto CONV_END;
210conv_xx12_x920: as_u32(dst) = (u_int32_t)(as_u16(src) ^ 0x8000) << 8; goto CONV_END;
211conv_xx12_029x: as_u32(dst) = (u_int32_t)(swab16(as_u16(src)) ^ 0x80) << 8; goto CONV_END;
212conv_xx12_9200: as_u32(dst) = (u_int32_t)(as_u16(src) ^ 0x8000) << 16; goto CONV_END;
213conv_xx12_0029: as_u32(dst) = (u_int32_t)(swab16(as_u16(src)) ^ 0x80); goto CONV_END;
214conv_xx12_xxx2: as_u8(dst) = as_u16(src) & 0xff; goto CONV_END;
215conv_xx12_x210: as_u32(dst) = (u_int32_t)swab16(as_u16(src)) << 8; goto CONV_END;
216conv_xx12_012x: as_u32(dst) = (u_int32_t)as_u16(src) << 8; goto CONV_END;
217conv_xx12_2100: as_u32(dst) = (u_int32_t)swab16(as_u16(src)) << 16; goto CONV_END;
218conv_xx12_0012: as_u32(dst) = (u_int32_t)as_u16(src); goto CONV_END;
219conv_xx12_xxxA: as_u8(dst) = (as_u16(src) ^ 0x80) & 0xff; goto CONV_END;
220conv_xx12_xxA1: as_u16(dst) = swab16(as_u16(src) ^ 0x80); goto CONV_END;
221conv_xx12_xx1A: as_u16(dst) = as_u16(src) ^ 0x80; goto CONV_END;
222conv_xx12_xA10: as_u32(dst) = (u_int32_t)swab16(as_u16(src) ^ 0x80) << 8; goto CONV_END;
223conv_xx12_01Ax: as_u32(dst) = (u_int32_t)(as_u16(src) ^ 0x80) << 8; goto CONV_END;
224conv_xx12_A100: as_u32(dst) = (u_int32_t)swab16(as_u16(src) ^ 0x80) << 16; goto CONV_END;
225conv_xx12_001A: as_u32(dst) = (u_int32_t)(as_u16(src) ^ 0x80); goto CONV_END;
226conv_x123_xxx1: as_u8(dst) = as_u32(src) >> 16; goto CONV_END;
227conv_x123_xx12: as_u16(dst) = as_u32(src) >> 8; goto CONV_END;
228conv_x123_xx21: as_u16(dst) = swab16(as_u32(src) >> 8); goto CONV_END;
229conv_x123_x123: as_u32(dst) = as_u32(src); goto CONV_END;
230conv_x123_321x: as_u32(dst) = swab32(as_u32(src)); goto CONV_END;
231conv_x123_1230: as_u32(dst) = as_u32(src) << 8; goto CONV_END;
232conv_x123_0321: as_u32(dst) = swab32(as_u32(src)) >> 8; goto CONV_END;
233conv_x123_xxx9: as_u8(dst) = (as_u32(src) >> 16) ^ 0x80; goto CONV_END;
234conv_x123_xx92: as_u16(dst) = (as_u32(src) >> 8) ^ 0x8000; goto CONV_END;
235conv_x123_xx29: as_u16(dst) = swab16(as_u32(src) >> 8) ^ 0x80; goto CONV_END;
236conv_x123_x923: as_u32(dst) = as_u32(src) ^ 0x800000; goto CONV_END;
237conv_x123_329x: as_u32(dst) = swab32(as_u32(src)) ^ 0x8000; goto CONV_END;
238conv_x123_9230: as_u32(dst) = (as_u32(src) ^ 0x800000) << 8; goto CONV_END;
239conv_x123_0329: as_u32(dst) = (swab32(as_u32(src)) >> 8) ^ 0x80; goto CONV_END;
240conv_123x_xxx3: as_u8(dst) = (as_u32(src) >> 8) & 0xff; goto CONV_END;
241conv_123x_xx32: as_u16(dst) = swab16(as_u32(src) >> 8); goto CONV_END;
242conv_123x_xx23: as_u16(dst) = (as_u32(src) >> 8) & 0xffff; goto CONV_END;
243conv_123x_x321: as_u32(dst) = swab32(as_u32(src)); goto CONV_END;
244conv_123x_123x: as_u32(dst) = as_u32(src); goto CONV_END;
245conv_123x_3210: as_u32(dst) = swab32(as_u32(src)) << 8; goto CONV_END;
246conv_123x_0123: as_u32(dst) = as_u32(src) >> 8; goto CONV_END;
247conv_123x_xxxB: as_u8(dst) = ((as_u32(src) >> 8) & 0xff) ^ 0x80; goto CONV_END;
248conv_123x_xxB2: as_u16(dst) = swab16((as_u32(src) >> 8) ^ 0x80); goto CONV_END;
249conv_123x_xx2B: as_u16(dst) = ((as_u32(src) >> 8) & 0xffff) ^ 0x80; goto CONV_END;
250conv_123x_xB21: as_u32(dst) = swab32(as_u32(src)) ^ 0x800000; goto CONV_END;
251conv_123x_12Bx: as_u32(dst) = as_u32(src) ^ 0x8000; goto CONV_END;
252conv_123x_B210: as_u32(dst) = swab32(as_u32(src) ^ 0x8000) << 8; goto CONV_END;
253conv_123x_012B: as_u32(dst) = (as_u32(src) >> 8) ^ 0x80; goto CONV_END;
254conv_1234_xxx1: as_u8(dst) = as_u32(src) >> 24; goto CONV_END;
255conv_1234_xx12: as_u16(dst) = as_u32(src) >> 16; goto CONV_END;
256conv_1234_xx21: as_u16(dst) = swab16(as_u32(src) >> 16); goto CONV_END;
257conv_1234_x123: as_u32(dst) = as_u32(src) >> 8; goto CONV_END;
258conv_1234_321x: as_u32(dst) = swab32(as_u32(src)) << 8; goto CONV_END;
259conv_1234_1234: as_u32(dst) = as_u32(src); goto CONV_END;
260conv_1234_4321: as_u32(dst) = swab32(as_u32(src)); goto CONV_END;
261conv_1234_xxx9: as_u8(dst) = (as_u32(src) >> 24) ^ 0x80; goto CONV_END;
262conv_1234_xx92: as_u16(dst) = (as_u32(src) >> 16) ^ 0x8000; goto CONV_END;
263conv_1234_xx29: as_u16(dst) = swab16(as_u32(src) >> 16) ^ 0x80; goto CONV_END;
264conv_1234_x923: as_u32(dst) = (as_u32(src) >> 8) ^ 0x800000; goto CONV_END;
265conv_1234_329x: as_u32(dst) = (swab32(as_u32(src)) ^ 0x80) << 8; goto CONV_END;
266conv_1234_9234: as_u32(dst) = as_u32(src) ^ 0x80000000; goto CONV_END;
267conv_1234_4329: as_u32(dst) = swab32(as_u32(src)) ^ 0x80; goto CONV_END;
268conv_1234_xxx4: as_u8(dst) = as_u32(src) & 0xff; goto CONV_END;
269conv_1234_xx43: as_u16(dst) = swab16(as_u32(src)); goto CONV_END;
270conv_1234_xx34: as_u16(dst) = as_u32(src) & 0xffff; goto CONV_END;
271conv_1234_x432: as_u32(dst) = swab32(as_u32(src)) >> 8; goto CONV_END;
272conv_1234_234x: as_u32(dst) = as_u32(src) << 8; goto CONV_END;
273conv_1234_xxxC: as_u8(dst) = (as_u32(src) & 0xff) ^ 0x80; goto CONV_END;
274conv_1234_xxC3: as_u16(dst) = swab16(as_u32(src) ^ 0x80); goto CONV_END;
275conv_1234_xx3C: as_u16(dst) = (as_u32(src) & 0xffff) ^ 0x80; goto CONV_END;
276conv_1234_xC32: as_u32(dst) = (swab32(as_u32(src)) >> 8) ^ 0x800000; goto CONV_END;
277conv_1234_23Cx: as_u32(dst) = (as_u32(src) ^ 0x80) << 8; goto CONV_END;
278conv_1234_C321: as_u32(dst) = swab32(as_u32(src) ^ 0x80); goto CONV_END;
279conv_1234_123C: as_u32(dst) = as_u32(src) ^ 0x80; goto CONV_END;
280}
281#endif
282
283#ifdef GET_S16_LABELS
284/* src_wid src_endswap unsigned */
285static void *get_s16_labels[4 * 2 * 2] = {
286 &&get_s16_xxx1_xx10, /* 8h -> 16h */
287 &&get_s16_xxx1_xx90, /* 8h ^> 16h */
288 &&get_s16_xxx1_xx10, /* 8s -> 16h */
289 &&get_s16_xxx1_xx90, /* 8s ^> 16h */
290 &&get_s16_xx12_xx12, /* 16h -> 16h */
291 &&get_s16_xx12_xx92, /* 16h ^> 16h */
292 &&get_s16_xx12_xx21, /* 16s -> 16h */
293 &&get_s16_xx12_xxA1, /* 16s ^> 16h */
294 &&get_s16_x123_xx12, /* 24h -> 16h */
295 &&get_s16_x123_xx92, /* 24h ^> 16h */
296 &&get_s16_123x_xx32, /* 24s -> 16h */
297 &&get_s16_123x_xxB2, /* 24s ^> 16h */
298 &&get_s16_1234_xx12, /* 32h -> 16h */
299 &&get_s16_1234_xx92, /* 32h ^> 16h */
300 &&get_s16_1234_xx43, /* 32s -> 16h */
301 &&get_s16_1234_xxC3, /* 32s ^> 16h */
302};
303#endif
304
305#ifdef GET_S16_END
306while(0) {
307get_s16_xxx1_xx10: sample = (u_int16_t)as_u8(src) << 8; goto GET_S16_END;
308get_s16_xxx1_xx90: sample = (u_int16_t)(as_u8(src) ^ 0x80) << 8; goto GET_S16_END;
309get_s16_xx12_xx12: sample = as_u16(src); goto GET_S16_END;
310get_s16_xx12_xx92: sample = as_u16(src) ^ 0x8000; goto GET_S16_END;
311get_s16_xx12_xx21: sample = swab16(as_u16(src)); goto GET_S16_END;
312get_s16_xx12_xxA1: sample = swab16(as_u16(src) ^ 0x80); goto GET_S16_END;
313get_s16_x123_xx12: sample = as_u32(src) >> 8; goto GET_S16_END;
314get_s16_x123_xx92: sample = (as_u32(src) >> 8) ^ 0x8000; goto GET_S16_END;
315get_s16_123x_xx32: sample = swab16(as_u32(src) >> 8); goto GET_S16_END;
316get_s16_123x_xxB2: sample = swab16((as_u32(src) >> 8) ^ 0x8000); goto GET_S16_END;
317get_s16_1234_xx12: sample = as_u32(src) >> 16; goto GET_S16_END;
318get_s16_1234_xx92: sample = (as_u32(src) >> 16) ^ 0x8000; goto GET_S16_END;
319get_s16_1234_xx43: sample = swab16(as_u32(src)); goto GET_S16_END;
320get_s16_1234_xxC3: sample = swab16(as_u32(src) ^ 0x80); goto GET_S16_END;
321}
322#endif
323
324#ifdef PUT_S16_LABELS
325/* dst_wid dst_endswap unsigned */
326static void *put_s16_labels[4 * 2 * 2] = {
327 &&put_s16_xx12_xxx1, /* 16h -> 8h */
328 &&put_s16_xx12_xxx9, /* 16h ^> 8h */
329 &&put_s16_xx12_xxx1, /* 16h -> 8s */
330 &&put_s16_xx12_xxx9, /* 16h ^> 8s */
331 &&put_s16_xx12_xx12, /* 16h -> 16h */
332 &&put_s16_xx12_xx92, /* 16h ^> 16h */
333 &&put_s16_xx12_xx21, /* 16h -> 16s */
334 &&put_s16_xx12_xx29, /* 16h ^> 16s */
335 &&put_s16_xx12_x120, /* 16h -> 24h */
336 &&put_s16_xx12_x920, /* 16h ^> 24h */
337 &&put_s16_xx12_021x, /* 16h -> 24s */
338 &&put_s16_xx12_029x, /* 16h ^> 24s */
339 &&put_s16_xx12_1200, /* 16h -> 32h */
340 &&put_s16_xx12_9200, /* 16h ^> 32h */
341 &&put_s16_xx12_0021, /* 16h -> 32s */
342 &&put_s16_xx12_0029, /* 16h ^> 32s */
343};
344#endif
345
346#ifdef PUT_S16_END
347while (0) {
348put_s16_xx12_xxx1: as_u8(dst) = sample >> 8; goto PUT_S16_END;
349put_s16_xx12_xxx9: as_u8(dst) = (sample >> 8) ^ 0x80; goto PUT_S16_END;
350put_s16_xx12_xx12: as_u16(dst) = sample; goto PUT_S16_END;
351put_s16_xx12_xx92: as_u16(dst) = sample ^ 0x8000; goto PUT_S16_END;
352put_s16_xx12_xx21: as_u16(dst) = swab16(sample); goto PUT_S16_END;
353put_s16_xx12_xx29: as_u16(dst) = swab16(sample) ^ 0x80; goto PUT_S16_END;
354put_s16_xx12_x120: as_u32(dst) = (u_int32_t)sample << 8; goto PUT_S16_END;
355put_s16_xx12_x920: as_u32(dst) = (u_int32_t)(sample ^ 0x8000) << 8; goto PUT_S16_END;
356put_s16_xx12_021x: as_u32(dst) = (u_int32_t)swab16(sample) << 8; goto PUT_S16_END;
357put_s16_xx12_029x: as_u32(dst) = (u_int32_t)(swab16(sample) ^ 0x80) << 8; goto PUT_S16_END;
358put_s16_xx12_1200: as_u32(dst) = (u_int32_t)sample << 16; goto PUT_S16_END;
359put_s16_xx12_9200: as_u32(dst) = (u_int32_t)(sample ^ 0x8000) << 16; goto PUT_S16_END;
360put_s16_xx12_0021: as_u32(dst) = (u_int32_t)swab16(sample); goto PUT_S16_END;
361put_s16_xx12_0029: as_u32(dst) = (u_int32_t)swab16(sample) ^ 0x80; goto PUT_S16_END;
362}
363#endif
364
365#undef as_u8
366#undef as_u16
367#undef as_u32
368#undef as_s8
369#undef as_s16
370#undef as_s32