1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "qemu/osdep.h"
26#include "qemu-common.h"
27#include "audio.h"
28
29#define AUDIO_CAP "mixeng"
30#include "audio_int.h"
31
32
33#define ENDIAN_CONVERSION natural
34#define ENDIAN_CONVERT(v) (v)
35
36
37#define BSIZE 8
38#define ITYPE int
39#define IN_MIN SCHAR_MIN
40#define IN_MAX SCHAR_MAX
41#define SIGNED
42#define SHIFT 8
43#include "mixeng_template.h"
44#undef SIGNED
45#undef IN_MAX
46#undef IN_MIN
47#undef BSIZE
48#undef ITYPE
49#undef SHIFT
50
51
52#define BSIZE 8
53#define ITYPE uint
54#define IN_MIN 0
55#define IN_MAX UCHAR_MAX
56#define SHIFT 8
57#include "mixeng_template.h"
58#undef IN_MAX
59#undef IN_MIN
60#undef BSIZE
61#undef ITYPE
62#undef SHIFT
63
64#undef ENDIAN_CONVERT
65#undef ENDIAN_CONVERSION
66
67
68#define BSIZE 16
69#define ITYPE int
70#define IN_MIN SHRT_MIN
71#define IN_MAX SHRT_MAX
72#define SIGNED
73#define SHIFT 16
74#define ENDIAN_CONVERSION natural
75#define ENDIAN_CONVERT(v) (v)
76#include "mixeng_template.h"
77#undef ENDIAN_CONVERT
78#undef ENDIAN_CONVERSION
79#define ENDIAN_CONVERSION swap
80#define ENDIAN_CONVERT(v) bswap16 (v)
81#include "mixeng_template.h"
82#undef ENDIAN_CONVERT
83#undef ENDIAN_CONVERSION
84#undef SIGNED
85#undef IN_MAX
86#undef IN_MIN
87#undef BSIZE
88#undef ITYPE
89#undef SHIFT
90
91
92#define BSIZE 16
93#define ITYPE uint
94#define IN_MIN 0
95#define IN_MAX USHRT_MAX
96#define SHIFT 16
97#define ENDIAN_CONVERSION natural
98#define ENDIAN_CONVERT(v) (v)
99#include "mixeng_template.h"
100#undef ENDIAN_CONVERT
101#undef ENDIAN_CONVERSION
102#define ENDIAN_CONVERSION swap
103#define ENDIAN_CONVERT(v) bswap16 (v)
104#include "mixeng_template.h"
105#undef ENDIAN_CONVERT
106#undef ENDIAN_CONVERSION
107#undef IN_MAX
108#undef IN_MIN
109#undef BSIZE
110#undef ITYPE
111#undef SHIFT
112
113
114#define BSIZE 32
115#define ITYPE int
116#define IN_MIN INT32_MIN
117#define IN_MAX INT32_MAX
118#define SIGNED
119#define SHIFT 32
120#define ENDIAN_CONVERSION natural
121#define ENDIAN_CONVERT(v) (v)
122#include "mixeng_template.h"
123#undef ENDIAN_CONVERT
124#undef ENDIAN_CONVERSION
125#define ENDIAN_CONVERSION swap
126#define ENDIAN_CONVERT(v) bswap32 (v)
127#include "mixeng_template.h"
128#undef ENDIAN_CONVERT
129#undef ENDIAN_CONVERSION
130#undef SIGNED
131#undef IN_MAX
132#undef IN_MIN
133#undef BSIZE
134#undef ITYPE
135#undef SHIFT
136
137
138#define BSIZE 32
139#define ITYPE uint
140#define IN_MIN 0
141#define IN_MAX UINT32_MAX
142#define SHIFT 32
143#define ENDIAN_CONVERSION natural
144#define ENDIAN_CONVERT(v) (v)
145#include "mixeng_template.h"
146#undef ENDIAN_CONVERT
147#undef ENDIAN_CONVERSION
148#define ENDIAN_CONVERSION swap
149#define ENDIAN_CONVERT(v) bswap32 (v)
150#include "mixeng_template.h"
151#undef ENDIAN_CONVERT
152#undef ENDIAN_CONVERSION
153#undef IN_MAX
154#undef IN_MIN
155#undef BSIZE
156#undef ITYPE
157#undef SHIFT
158
159t_sample *mixeng_conv[2][2][2][3] = {
160 {
161 {
162 {
163 conv_natural_uint8_t_to_mono,
164 conv_natural_uint16_t_to_mono,
165 conv_natural_uint32_t_to_mono
166 },
167 {
168 conv_natural_uint8_t_to_mono,
169 conv_swap_uint16_t_to_mono,
170 conv_swap_uint32_t_to_mono,
171 }
172 },
173 {
174 {
175 conv_natural_int8_t_to_mono,
176 conv_natural_int16_t_to_mono,
177 conv_natural_int32_t_to_mono
178 },
179 {
180 conv_natural_int8_t_to_mono,
181 conv_swap_int16_t_to_mono,
182 conv_swap_int32_t_to_mono
183 }
184 }
185 },
186 {
187 {
188 {
189 conv_natural_uint8_t_to_stereo,
190 conv_natural_uint16_t_to_stereo,
191 conv_natural_uint32_t_to_stereo
192 },
193 {
194 conv_natural_uint8_t_to_stereo,
195 conv_swap_uint16_t_to_stereo,
196 conv_swap_uint32_t_to_stereo
197 }
198 },
199 {
200 {
201 conv_natural_int8_t_to_stereo,
202 conv_natural_int16_t_to_stereo,
203 conv_natural_int32_t_to_stereo
204 },
205 {
206 conv_natural_int8_t_to_stereo,
207 conv_swap_int16_t_to_stereo,
208 conv_swap_int32_t_to_stereo,
209 }
210 }
211 }
212};
213
214f_sample *mixeng_clip[2][2][2][3] = {
215 {
216 {
217 {
218 clip_natural_uint8_t_from_mono,
219 clip_natural_uint16_t_from_mono,
220 clip_natural_uint32_t_from_mono
221 },
222 {
223 clip_natural_uint8_t_from_mono,
224 clip_swap_uint16_t_from_mono,
225 clip_swap_uint32_t_from_mono
226 }
227 },
228 {
229 {
230 clip_natural_int8_t_from_mono,
231 clip_natural_int16_t_from_mono,
232 clip_natural_int32_t_from_mono
233 },
234 {
235 clip_natural_int8_t_from_mono,
236 clip_swap_int16_t_from_mono,
237 clip_swap_int32_t_from_mono
238 }
239 }
240 },
241 {
242 {
243 {
244 clip_natural_uint8_t_from_stereo,
245 clip_natural_uint16_t_from_stereo,
246 clip_natural_uint32_t_from_stereo
247 },
248 {
249 clip_natural_uint8_t_from_stereo,
250 clip_swap_uint16_t_from_stereo,
251 clip_swap_uint32_t_from_stereo
252 }
253 },
254 {
255 {
256 clip_natural_int8_t_from_stereo,
257 clip_natural_int16_t_from_stereo,
258 clip_natural_int32_t_from_stereo
259 },
260 {
261 clip_natural_int8_t_from_stereo,
262 clip_swap_int16_t_from_stereo,
263 clip_swap_int32_t_from_stereo
264 }
265 }
266 }
267};
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302struct rate {
303 uint64_t opos;
304 uint64_t opos_inc;
305 uint32_t ipos;
306 struct st_sample ilast;
307};
308
309
310
311
312void *st_rate_start (int inrate, int outrate)
313{
314 struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
315
316 if (!rate) {
317 dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate));
318 return NULL;
319 }
320
321 rate->opos = 0;
322
323
324 rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
325
326 rate->ipos = 0;
327 rate->ilast.l = 0;
328 rate->ilast.r = 0;
329 return rate;
330}
331
332#define NAME st_rate_flow_mix
333#define OP(a, b) a += b
334#include "rate_template.h"
335
336#define NAME st_rate_flow
337#define OP(a, b) a = b
338#include "rate_template.h"
339
340void st_rate_stop (void *opaque)
341{
342 g_free (opaque);
343}
344
345void mixeng_clear (struct st_sample *buf, int len)
346{
347 memset (buf, 0, len * sizeof (struct st_sample));
348}
349
350void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol)
351{
352 if (vol->mute) {
353 mixeng_clear (buf, len);
354 return;
355 }
356
357 while (len--) {
358#ifdef FLOAT_MIXENG
359 buf->l = buf->l * vol->l;
360 buf->r = buf->r * vol->r;
361#else
362 buf->l = (buf->l * vol->l) >> 32;
363 buf->r = (buf->r * vol->r) >> 32;
364#endif
365 buf += 1;
366 }
367}
368