|
|
1.1 root 1: /*
2: * QEMU Mixing engine
3: *
1.1.1.2 root 4: * Copyright (c) 2004-2005 Vassili Karpov (malc)
1.1 root 5: * Copyright (c) 1998 Fabrice Bellard
6: *
7: * Permission is hereby granted, free of charge, to any person obtaining a copy
8: * of this software and associated documentation files (the "Software"), to deal
9: * in the Software without restriction, including without limitation the rights
10: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11: * copies of the Software, and to permit persons to whom the Software is
12: * furnished to do so, subject to the following conditions:
13: *
14: * The above copyright notice and this permission notice shall be included in
15: * all copies or substantial portions of the Software.
16: *
17: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20: * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23: * THE SOFTWARE.
24: */
1.1.1.3 ! root 25: #include "qemu-common.h"
! 26: #include "audio.h"
1.1 root 27:
1.1.1.2 root 28: #define AUDIO_CAP "mixeng"
29: #include "audio_int.h"
30:
31: #define NOVOL
32:
33: /* 8 bit */
34: #define ENDIAN_CONVERSION natural
35: #define ENDIAN_CONVERT(v) (v)
36:
37: /* Signed 8 bit */
1.1 root 38: #define IN_T int8_t
1.1.1.2 root 39: #define IN_MIN SCHAR_MIN
40: #define IN_MAX SCHAR_MAX
1.1 root 41: #define SIGNED
1.1.1.2 root 42: #define SHIFT 8
1.1 root 43: #include "mixeng_template.h"
44: #undef SIGNED
45: #undef IN_MAX
46: #undef IN_MIN
47: #undef IN_T
1.1.1.2 root 48: #undef SHIFT
1.1 root 49:
1.1.1.2 root 50: /* Unsigned 8 bit */
1.1 root 51: #define IN_T uint8_t
52: #define IN_MIN 0
53: #define IN_MAX UCHAR_MAX
1.1.1.2 root 54: #define SHIFT 8
1.1 root 55: #include "mixeng_template.h"
56: #undef IN_MAX
57: #undef IN_MIN
58: #undef IN_T
1.1.1.2 root 59: #undef SHIFT
60:
61: #undef ENDIAN_CONVERT
62: #undef ENDIAN_CONVERSION
1.1 root 63:
1.1.1.2 root 64: /* Signed 16 bit */
1.1 root 65: #define IN_T int16_t
66: #define IN_MIN SHRT_MIN
67: #define IN_MAX SHRT_MAX
68: #define SIGNED
1.1.1.2 root 69: #define SHIFT 16
70: #define ENDIAN_CONVERSION natural
71: #define ENDIAN_CONVERT(v) (v)
1.1 root 72: #include "mixeng_template.h"
1.1.1.2 root 73: #undef ENDIAN_CONVERT
74: #undef ENDIAN_CONVERSION
75: #define ENDIAN_CONVERSION swap
76: #define ENDIAN_CONVERT(v) bswap16 (v)
77: #include "mixeng_template.h"
78: #undef ENDIAN_CONVERT
79: #undef ENDIAN_CONVERSION
1.1 root 80: #undef SIGNED
81: #undef IN_MAX
82: #undef IN_MIN
83: #undef IN_T
1.1.1.2 root 84: #undef SHIFT
1.1 root 85:
1.1.1.3 ! root 86: /* Unsigned 16 bit */
1.1 root 87: #define IN_T uint16_t
88: #define IN_MIN 0
89: #define IN_MAX USHRT_MAX
1.1.1.2 root 90: #define SHIFT 16
91: #define ENDIAN_CONVERSION natural
92: #define ENDIAN_CONVERT(v) (v)
93: #include "mixeng_template.h"
94: #undef ENDIAN_CONVERT
95: #undef ENDIAN_CONVERSION
96: #define ENDIAN_CONVERSION swap
97: #define ENDIAN_CONVERT(v) bswap16 (v)
1.1 root 98: #include "mixeng_template.h"
1.1.1.2 root 99: #undef ENDIAN_CONVERT
100: #undef ENDIAN_CONVERSION
1.1 root 101: #undef IN_MAX
102: #undef IN_MIN
103: #undef IN_T
1.1.1.2 root 104: #undef SHIFT
1.1 root 105:
1.1.1.3 ! root 106: /* Signed 32 bit */
! 107: #define IN_T int32_t
! 108: #define IN_MIN INT32_MIN
! 109: #define IN_MAX INT32_MAX
! 110: #define SIGNED
! 111: #define SHIFT 32
! 112: #define ENDIAN_CONVERSION natural
! 113: #define ENDIAN_CONVERT(v) (v)
! 114: #include "mixeng_template.h"
! 115: #undef ENDIAN_CONVERT
! 116: #undef ENDIAN_CONVERSION
! 117: #define ENDIAN_CONVERSION swap
! 118: #define ENDIAN_CONVERT(v) bswap32 (v)
! 119: #include "mixeng_template.h"
! 120: #undef ENDIAN_CONVERT
! 121: #undef ENDIAN_CONVERSION
! 122: #undef SIGNED
! 123: #undef IN_MAX
! 124: #undef IN_MIN
! 125: #undef IN_T
! 126: #undef SHIFT
! 127:
! 128: /* Unsigned 16 bit */
! 129: #define IN_T uint32_t
! 130: #define IN_MIN 0
! 131: #define IN_MAX UINT32_MAX
! 132: #define SHIFT 32
! 133: #define ENDIAN_CONVERSION natural
! 134: #define ENDIAN_CONVERT(v) (v)
! 135: #include "mixeng_template.h"
! 136: #undef ENDIAN_CONVERT
! 137: #undef ENDIAN_CONVERSION
! 138: #define ENDIAN_CONVERSION swap
! 139: #define ENDIAN_CONVERT(v) bswap32 (v)
! 140: #include "mixeng_template.h"
! 141: #undef ENDIAN_CONVERT
! 142: #undef ENDIAN_CONVERSION
! 143: #undef IN_MAX
! 144: #undef IN_MIN
! 145: #undef IN_T
! 146: #undef SHIFT
! 147:
! 148: t_sample *mixeng_conv[2][2][2][3] = {
1.1 root 149: {
150: {
1.1.1.2 root 151: {
152: conv_natural_uint8_t_to_mono,
1.1.1.3 ! root 153: conv_natural_uint16_t_to_mono,
! 154: conv_natural_uint32_t_to_mono
1.1.1.2 root 155: },
156: {
157: conv_natural_uint8_t_to_mono,
1.1.1.3 ! root 158: conv_swap_uint16_t_to_mono,
! 159: conv_swap_uint32_t_to_mono,
1.1.1.2 root 160: }
1.1 root 161: },
162: {
1.1.1.2 root 163: {
164: conv_natural_int8_t_to_mono,
1.1.1.3 ! root 165: conv_natural_int16_t_to_mono,
! 166: conv_natural_int32_t_to_mono
1.1.1.2 root 167: },
168: {
169: conv_natural_int8_t_to_mono,
1.1.1.3 ! root 170: conv_swap_int16_t_to_mono,
! 171: conv_swap_int32_t_to_mono
1.1.1.2 root 172: }
1.1 root 173: }
174: },
175: {
176: {
1.1.1.2 root 177: {
178: conv_natural_uint8_t_to_stereo,
1.1.1.3 ! root 179: conv_natural_uint16_t_to_stereo,
! 180: conv_natural_uint32_t_to_stereo
1.1.1.2 root 181: },
182: {
183: conv_natural_uint8_t_to_stereo,
1.1.1.3 ! root 184: conv_swap_uint16_t_to_stereo,
! 185: conv_swap_uint32_t_to_stereo
1.1.1.2 root 186: }
1.1 root 187: },
188: {
1.1.1.2 root 189: {
190: conv_natural_int8_t_to_stereo,
1.1.1.3 ! root 191: conv_natural_int16_t_to_stereo,
! 192: conv_natural_int32_t_to_stereo
1.1.1.2 root 193: },
194: {
195: conv_natural_int8_t_to_stereo,
1.1.1.3 ! root 196: conv_swap_int16_t_to_stereo,
! 197: conv_swap_int32_t_to_stereo,
1.1.1.2 root 198: }
1.1 root 199: }
200: }
201: };
202:
1.1.1.3 ! root 203: f_sample *mixeng_clip[2][2][2][3] = {
1.1 root 204: {
205: {
1.1.1.2 root 206: {
207: clip_natural_uint8_t_from_mono,
1.1.1.3 ! root 208: clip_natural_uint16_t_from_mono,
! 209: clip_natural_uint32_t_from_mono
1.1.1.2 root 210: },
211: {
212: clip_natural_uint8_t_from_mono,
1.1.1.3 ! root 213: clip_swap_uint16_t_from_mono,
! 214: clip_swap_uint32_t_from_mono
1.1.1.2 root 215: }
1.1 root 216: },
217: {
1.1.1.2 root 218: {
219: clip_natural_int8_t_from_mono,
1.1.1.3 ! root 220: clip_natural_int16_t_from_mono,
! 221: clip_natural_int32_t_from_mono
1.1.1.2 root 222: },
223: {
224: clip_natural_int8_t_from_mono,
1.1.1.3 ! root 225: clip_swap_int16_t_from_mono,
! 226: clip_swap_int32_t_from_mono
1.1.1.2 root 227: }
1.1 root 228: }
229: },
230: {
231: {
1.1.1.2 root 232: {
233: clip_natural_uint8_t_from_stereo,
1.1.1.3 ! root 234: clip_natural_uint16_t_from_stereo,
! 235: clip_natural_uint32_t_from_stereo
1.1.1.2 root 236: },
237: {
238: clip_natural_uint8_t_from_stereo,
1.1.1.3 ! root 239: clip_swap_uint16_t_from_stereo,
! 240: clip_swap_uint32_t_from_stereo
1.1.1.2 root 241: }
1.1 root 242: },
243: {
1.1.1.2 root 244: {
245: clip_natural_int8_t_from_stereo,
1.1.1.3 ! root 246: clip_natural_int16_t_from_stereo,
! 247: clip_natural_int32_t_from_stereo
1.1.1.2 root 248: },
249: {
250: clip_natural_int8_t_from_stereo,
1.1.1.3 ! root 251: clip_swap_int16_t_from_stereo,
! 252: clip_swap_int32_t_from_stereo
1.1.1.2 root 253: }
1.1 root 254: }
255: }
256: };
257:
258: /*
259: * August 21, 1998
260: * Copyright 1998 Fabrice Bellard.
261: *
262: * [Rewrote completly the code of Lance Norskog And Sundry
263: * Contributors with a more efficient algorithm.]
264: *
265: * This source code is freely redistributable and may be used for
1.1.1.2 root 266: * any purpose. This copyright notice must be maintained.
267: * Lance Norskog And Sundry Contributors are not responsible for
268: * the consequences of using this software.
1.1 root 269: */
270:
271: /*
272: * Sound Tools rate change effect file.
273: */
274: /*
275: * Linear Interpolation.
276: *
277: * The use of fractional increment allows us to use no buffer. It
278: * avoid the problems at the end of the buffer we had with the old
279: * method which stored a possibly big buffer of size
280: * lcm(in_rate,out_rate).
281: *
282: * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
283: * the input & output frequencies are equal, a delay of one sample is
284: * introduced. Limited to processing 32-bit count worth of samples.
285: *
286: * 1 << FRAC_BITS evaluating to zero in several places. Changed with
287: * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
288: */
289:
290: /* Private data */
1.1.1.2 root 291: struct rate {
1.1 root 292: uint64_t opos;
293: uint64_t opos_inc;
294: uint32_t ipos; /* position in the input stream (integer) */
295: st_sample_t ilast; /* last sample in the input stream */
1.1.1.2 root 296: };
1.1 root 297:
298: /*
299: * Prepare processing.
300: */
301: void *st_rate_start (int inrate, int outrate)
302: {
1.1.1.2 root 303: struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
1.1 root 304:
305: if (!rate) {
1.1.1.2 root 306: dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate));
307: return NULL;
1.1 root 308: }
309:
310: rate->opos = 0;
311:
312: /* increment */
1.1.1.2 root 313: rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
1.1 root 314:
315: rate->ipos = 0;
316: rate->ilast.l = 0;
317: rate->ilast.r = 0;
318: return rate;
319: }
320:
1.1.1.2 root 321: #define NAME st_rate_flow_mix
322: #define OP(a, b) a += b
323: #include "rate_template.h"
324:
325: #define NAME st_rate_flow
326: #define OP(a, b) a = b
327: #include "rate_template.h"
1.1 root 328:
329: void st_rate_stop (void *opaque)
330: {
331: qemu_free (opaque);
332: }
1.1.1.2 root 333:
334: void mixeng_clear (st_sample_t *buf, int len)
335: {
336: memset (buf, 0, len * sizeof (st_sample_t));
337: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.