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