|
|
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: */
25: #include "vl.h"
26:
1.1.1.2 ! root 27: #define AUDIO_CAP "mixeng"
! 28: #include "audio_int.h"
! 29:
! 30: #define NOVOL
! 31:
! 32: /* 8 bit */
! 33: #define ENDIAN_CONVERSION natural
! 34: #define ENDIAN_CONVERT(v) (v)
! 35:
! 36: /* Signed 8 bit */
1.1 root 37: #define IN_T int8_t
1.1.1.2 ! root 38: #define IN_MIN SCHAR_MIN
! 39: #define IN_MAX SCHAR_MAX
1.1 root 40: #define SIGNED
1.1.1.2 ! root 41: #define SHIFT 8
1.1 root 42: #include "mixeng_template.h"
43: #undef SIGNED
44: #undef IN_MAX
45: #undef IN_MIN
46: #undef IN_T
1.1.1.2 ! root 47: #undef SHIFT
1.1 root 48:
1.1.1.2 ! root 49: /* Unsigned 8 bit */
1.1 root 50: #define IN_T uint8_t
51: #define IN_MIN 0
52: #define IN_MAX UCHAR_MAX
1.1.1.2 ! root 53: #define SHIFT 8
1.1 root 54: #include "mixeng_template.h"
55: #undef IN_MAX
56: #undef IN_MIN
57: #undef IN_T
1.1.1.2 ! root 58: #undef SHIFT
! 59:
! 60: #undef ENDIAN_CONVERT
! 61: #undef ENDIAN_CONVERSION
1.1 root 62:
1.1.1.2 ! root 63: /* Signed 16 bit */
1.1 root 64: #define IN_T int16_t
65: #define IN_MIN SHRT_MIN
66: #define IN_MAX SHRT_MAX
67: #define SIGNED
1.1.1.2 ! root 68: #define SHIFT 16
! 69: #define ENDIAN_CONVERSION natural
! 70: #define ENDIAN_CONVERT(v) (v)
1.1 root 71: #include "mixeng_template.h"
1.1.1.2 ! root 72: #undef ENDIAN_CONVERT
! 73: #undef ENDIAN_CONVERSION
! 74: #define ENDIAN_CONVERSION swap
! 75: #define ENDIAN_CONVERT(v) bswap16 (v)
! 76: #include "mixeng_template.h"
! 77: #undef ENDIAN_CONVERT
! 78: #undef ENDIAN_CONVERSION
1.1 root 79: #undef SIGNED
80: #undef IN_MAX
81: #undef IN_MIN
82: #undef IN_T
1.1.1.2 ! root 83: #undef SHIFT
1.1 root 84:
85: #define IN_T uint16_t
86: #define IN_MIN 0
87: #define IN_MAX USHRT_MAX
1.1.1.2 ! root 88: #define SHIFT 16
! 89: #define ENDIAN_CONVERSION natural
! 90: #define ENDIAN_CONVERT(v) (v)
! 91: #include "mixeng_template.h"
! 92: #undef ENDIAN_CONVERT
! 93: #undef ENDIAN_CONVERSION
! 94: #define ENDIAN_CONVERSION swap
! 95: #define ENDIAN_CONVERT(v) bswap16 (v)
1.1 root 96: #include "mixeng_template.h"
1.1.1.2 ! root 97: #undef ENDIAN_CONVERT
! 98: #undef ENDIAN_CONVERSION
1.1 root 99: #undef IN_MAX
100: #undef IN_MIN
101: #undef IN_T
1.1.1.2 ! root 102: #undef SHIFT
1.1 root 103:
1.1.1.2 ! root 104: t_sample *mixeng_conv[2][2][2][2] = {
1.1 root 105: {
106: {
1.1.1.2 ! root 107: {
! 108: conv_natural_uint8_t_to_mono,
! 109: conv_natural_uint16_t_to_mono
! 110: },
! 111: {
! 112: conv_natural_uint8_t_to_mono,
! 113: conv_swap_uint16_t_to_mono
! 114: }
1.1 root 115: },
116: {
1.1.1.2 ! root 117: {
! 118: conv_natural_int8_t_to_mono,
! 119: conv_natural_int16_t_to_mono
! 120: },
! 121: {
! 122: conv_natural_int8_t_to_mono,
! 123: conv_swap_int16_t_to_mono
! 124: }
1.1 root 125: }
126: },
127: {
128: {
1.1.1.2 ! root 129: {
! 130: conv_natural_uint8_t_to_stereo,
! 131: conv_natural_uint16_t_to_stereo
! 132: },
! 133: {
! 134: conv_natural_uint8_t_to_stereo,
! 135: conv_swap_uint16_t_to_stereo
! 136: }
1.1 root 137: },
138: {
1.1.1.2 ! root 139: {
! 140: conv_natural_int8_t_to_stereo,
! 141: conv_natural_int16_t_to_stereo
! 142: },
! 143: {
! 144: conv_natural_int8_t_to_stereo,
! 145: conv_swap_int16_t_to_stereo
! 146: }
1.1 root 147: }
148: }
149: };
150:
1.1.1.2 ! root 151: f_sample *mixeng_clip[2][2][2][2] = {
1.1 root 152: {
153: {
1.1.1.2 ! root 154: {
! 155: clip_natural_uint8_t_from_mono,
! 156: clip_natural_uint16_t_from_mono
! 157: },
! 158: {
! 159: clip_natural_uint8_t_from_mono,
! 160: clip_swap_uint16_t_from_mono
! 161: }
1.1 root 162: },
163: {
1.1.1.2 ! root 164: {
! 165: clip_natural_int8_t_from_mono,
! 166: clip_natural_int16_t_from_mono
! 167: },
! 168: {
! 169: clip_natural_int8_t_from_mono,
! 170: clip_swap_int16_t_from_mono
! 171: }
1.1 root 172: }
173: },
174: {
175: {
1.1.1.2 ! root 176: {
! 177: clip_natural_uint8_t_from_stereo,
! 178: clip_natural_uint16_t_from_stereo
! 179: },
! 180: {
! 181: clip_natural_uint8_t_from_stereo,
! 182: clip_swap_uint16_t_from_stereo
! 183: }
1.1 root 184: },
185: {
1.1.1.2 ! root 186: {
! 187: clip_natural_int8_t_from_stereo,
! 188: clip_natural_int16_t_from_stereo
! 189: },
! 190: {
! 191: clip_natural_int8_t_from_stereo,
! 192: clip_swap_int16_t_from_stereo
! 193: }
1.1 root 194: }
195: }
196: };
197:
198: /*
199: * August 21, 1998
200: * Copyright 1998 Fabrice Bellard.
201: *
202: * [Rewrote completly the code of Lance Norskog And Sundry
203: * Contributors with a more efficient algorithm.]
204: *
205: * This source code is freely redistributable and may be used for
1.1.1.2 ! root 206: * any purpose. This copyright notice must be maintained.
! 207: * Lance Norskog And Sundry Contributors are not responsible for
! 208: * the consequences of using this software.
1.1 root 209: */
210:
211: /*
212: * Sound Tools rate change effect file.
213: */
214: /*
215: * Linear Interpolation.
216: *
217: * The use of fractional increment allows us to use no buffer. It
218: * avoid the problems at the end of the buffer we had with the old
219: * method which stored a possibly big buffer of size
220: * lcm(in_rate,out_rate).
221: *
222: * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
223: * the input & output frequencies are equal, a delay of one sample is
224: * introduced. Limited to processing 32-bit count worth of samples.
225: *
226: * 1 << FRAC_BITS evaluating to zero in several places. Changed with
227: * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
228: */
229:
230: /* Private data */
1.1.1.2 ! root 231: struct rate {
1.1 root 232: uint64_t opos;
233: uint64_t opos_inc;
234: uint32_t ipos; /* position in the input stream (integer) */
235: st_sample_t ilast; /* last sample in the input stream */
1.1.1.2 ! root 236: };
1.1 root 237:
238: /*
239: * Prepare processing.
240: */
241: void *st_rate_start (int inrate, int outrate)
242: {
1.1.1.2 ! root 243: struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
1.1 root 244:
245: if (!rate) {
1.1.1.2 ! root 246: dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate));
! 247: return NULL;
1.1 root 248: }
249:
250: rate->opos = 0;
251:
252: /* increment */
1.1.1.2 ! root 253: rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
1.1 root 254:
255: rate->ipos = 0;
256: rate->ilast.l = 0;
257: rate->ilast.r = 0;
258: return rate;
259: }
260:
1.1.1.2 ! root 261: #define NAME st_rate_flow_mix
! 262: #define OP(a, b) a += b
! 263: #include "rate_template.h"
! 264:
! 265: #define NAME st_rate_flow
! 266: #define OP(a, b) a = b
! 267: #include "rate_template.h"
1.1 root 268:
269: void st_rate_stop (void *opaque)
270: {
271: qemu_free (opaque);
272: }
1.1.1.2 ! root 273:
! 274: void mixeng_clear (st_sample_t *buf, int len)
! 275: {
! 276: memset (buf, 0, len * sizeof (st_sample_t));
! 277: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.