VirtualBox

source: vbox/trunk/src/VBox/Devices/Audio/mixeng.c@ 36993

最後變更 在這個檔案從36993是 35353,由 vboxsync 提交於 14 年 前

Move the misc files the in src/VBox/Devices/ directory into a build/ subdirectory, changing their names to match the target module.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.8 KB
 
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 "VBoxDD.h"
27#include "vl_vbox.h"
28#include "audio.h"
29#ifdef VBOX
30# include <iprt/asm-math.h>
31# include <iprt/mem.h>
32#endif
33
34#define AUDIO_CAP "mixeng"
35#include "audio_int.h"
36
37#ifndef VBOX
38#define NOVOL
39#endif
40
41/* 8 bit */
42#define ENDIAN_CONVERSION natural
43#define ENDIAN_CONVERT(v) (v)
44
45/* Signed 8 bit */
46#define IN_T int8_t
47#define IN_MIN SCHAR_MIN
48#define IN_MAX SCHAR_MAX
49#define SIGNED
50#define SHIFT 8
51#include "mixeng_template.h"
52#undef SIGNED
53#undef IN_MAX
54#undef IN_MIN
55#undef IN_T
56#undef SHIFT
57
58/* Unsigned 8 bit */
59#define IN_T uint8_t
60#define IN_MIN 0
61#define IN_MAX UCHAR_MAX
62#define SHIFT 8
63#include "mixeng_template.h"
64#undef IN_MAX
65#undef IN_MIN
66#undef IN_T
67#undef SHIFT
68
69#undef ENDIAN_CONVERT
70#undef ENDIAN_CONVERSION
71
72/* Signed 16 bit */
73#define IN_T int16_t
74#define IN_MIN SHRT_MIN
75#define IN_MAX SHRT_MAX
76#define SIGNED
77#define SHIFT 16
78#define ENDIAN_CONVERSION natural
79#define ENDIAN_CONVERT(v) (v)
80#include "mixeng_template.h"
81#undef ENDIAN_CONVERT
82#undef ENDIAN_CONVERSION
83#define ENDIAN_CONVERSION swap
84#define ENDIAN_CONVERT(v) bswap16 (v)
85#include "mixeng_template.h"
86#undef ENDIAN_CONVERT
87#undef ENDIAN_CONVERSION
88#undef SIGNED
89#undef IN_MAX
90#undef IN_MIN
91#undef IN_T
92#undef SHIFT
93
94/* Unsigned 16 bit */
95#define IN_T uint16_t
96#define IN_MIN 0
97#define IN_MAX USHRT_MAX
98#define SHIFT 16
99#define ENDIAN_CONVERSION natural
100#define ENDIAN_CONVERT(v) (v)
101#include "mixeng_template.h"
102#undef ENDIAN_CONVERT
103#undef ENDIAN_CONVERSION
104#define ENDIAN_CONVERSION swap
105#define ENDIAN_CONVERT(v) bswap16 (v)
106#include "mixeng_template.h"
107#undef ENDIAN_CONVERT
108#undef ENDIAN_CONVERSION
109#undef IN_MAX
110#undef IN_MIN
111#undef IN_T
112#undef SHIFT
113
114/* Signed 32 bit */
115#define IN_T int32_t
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 IN_T
134#undef SHIFT
135
136/* Unsigned 32 bit */
137#define IN_T uint32_t
138#define IN_MIN 0
139#define IN_MAX UINT32_MAX
140#define SHIFT 32
141#define ENDIAN_CONVERSION natural
142#define ENDIAN_CONVERT(v) (v)
143#include "mixeng_template.h"
144#undef ENDIAN_CONVERT
145#undef ENDIAN_CONVERSION
146#define ENDIAN_CONVERSION swap
147#define ENDIAN_CONVERT(v) bswap32 (v)
148#include "mixeng_template.h"
149#undef ENDIAN_CONVERT
150#undef ENDIAN_CONVERSION
151#undef IN_MAX
152#undef IN_MIN
153#undef IN_T
154#undef SHIFT
155
156t_sample *mixeng_conv[2][2][2][3] = {
157 {
158 {
159 {
160 conv_natural_uint8_t_to_mono,
161 conv_natural_uint16_t_to_mono,
162 conv_natural_uint32_t_to_mono
163 },
164 {
165 conv_natural_uint8_t_to_mono,
166 conv_swap_uint16_t_to_mono,
167 conv_swap_uint32_t_to_mono,
168 }
169 },
170 {
171 {
172 conv_natural_int8_t_to_mono,
173 conv_natural_int16_t_to_mono,
174 conv_natural_int32_t_to_mono
175 },
176 {
177 conv_natural_int8_t_to_mono,
178 conv_swap_int16_t_to_mono,
179 conv_swap_int32_t_to_mono
180 }
181 }
182 },
183 {
184 {
185 {
186 conv_natural_uint8_t_to_stereo,
187 conv_natural_uint16_t_to_stereo,
188 conv_natural_uint32_t_to_stereo
189 },
190 {
191 conv_natural_uint8_t_to_stereo,
192 conv_swap_uint16_t_to_stereo,
193 conv_swap_uint32_t_to_stereo
194 }
195 },
196 {
197 {
198 conv_natural_int8_t_to_stereo,
199 conv_natural_int16_t_to_stereo,
200 conv_natural_int32_t_to_stereo
201 },
202 {
203 conv_natural_int8_t_to_stereo,
204 conv_swap_int16_t_to_stereo,
205 conv_swap_int32_t_to_stereo,
206 }
207 }
208 }
209};
210
211f_sample *mixeng_clip[2][2][2][3] = {
212 {
213 {
214 {
215 clip_natural_uint8_t_from_mono,
216 clip_natural_uint16_t_from_mono,
217 clip_natural_uint32_t_from_mono
218 },
219 {
220 clip_natural_uint8_t_from_mono,
221 clip_swap_uint16_t_from_mono,
222 clip_swap_uint32_t_from_mono
223 }
224 },
225 {
226 {
227 clip_natural_int8_t_from_mono,
228 clip_natural_int16_t_from_mono,
229 clip_natural_int32_t_from_mono
230 },
231 {
232 clip_natural_int8_t_from_mono,
233 clip_swap_int16_t_from_mono,
234 clip_swap_int32_t_from_mono
235 }
236 }
237 },
238 {
239 {
240 {
241 clip_natural_uint8_t_from_stereo,
242 clip_natural_uint16_t_from_stereo,
243 clip_natural_uint32_t_from_stereo
244 },
245 {
246 clip_natural_uint8_t_from_stereo,
247 clip_swap_uint16_t_from_stereo,
248 clip_swap_uint32_t_from_stereo
249 }
250 },
251 {
252 {
253 clip_natural_int8_t_from_stereo,
254 clip_natural_int16_t_from_stereo,
255 clip_natural_int32_t_from_stereo
256 },
257 {
258 clip_natural_int8_t_from_stereo,
259 clip_swap_int16_t_from_stereo,
260 clip_swap_int32_t_from_stereo
261 }
262 }
263 }
264};
265
266/*
267 * August 21, 1998
268 * Copyright 1998 Fabrice Bellard.
269 *
270 * [Rewrote completely the code of Lance Norskog And Sundry
271 * Contributors with a more efficient algorithm.]
272 *
273 * This source code is freely redistributable and may be used for
274 * any purpose. This copyright notice must be maintained.
275 * Lance Norskog And Sundry Contributors are not responsible for
276 * the consequences of using this software.
277 */
278
279/*
280 * Sound Tools rate change effect file.
281 */
282/*
283 * Linear Interpolation.
284 *
285 * The use of fractional increment allows us to use no buffer. It
286 * avoid the problems at the end of the buffer we had with the old
287 * method which stored a possibly big buffer of size
288 * lcm(in_rate,out_rate).
289 *
290 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
291 * the input & output frequencies are equal, a delay of one sample is
292 * introduced. Limited to processing 32-bit count worth of samples.
293 *
294 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
295 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
296 */
297
298/* Private data */
299struct rate {
300 uint64_t opos;
301 uint64_t opos_inc;
302 uint32_t ipos; /* position in the input stream (integer) */
303 st_sample_t ilast; /* last sample in the input stream */
304};
305
306/*
307 * Prepare processing.
308 */
309void *st_rate_start (int inrate, int outrate)
310{
311 struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
312
313 if (!rate) {
314 dolog ("Could not allocate resampler (%" FMTZ "u bytes)\n",
315 sizeof (*rate));
316 return NULL;
317 }
318
319 rate->opos = 0;
320
321 /* increment */
322 rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
323
324 rate->ipos = 0;
325 rate->ilast.l = 0;
326 rate->ilast.r = 0;
327 return rate;
328}
329
330#define NAME st_rate_flow_mix
331#define OP(a, b) a += b
332#include "rate_template.h"
333
334#define NAME st_rate_flow
335#define OP(a, b) a = b
336#include "rate_template.h"
337
338void st_rate_stop (void *opaque)
339{
340 qemu_free (opaque);
341}
342
343void mixeng_clear (st_sample_t *buf, int len)
344{
345 memset (buf, 0, len * sizeof (st_sample_t));
346}
347
348void mixeng_sniff_and_clear (HWVoiceOut *hw, st_sample_t *src, int len)
349{
350 sniffer_run_out (hw, src, len);
351 mixeng_clear (src, len);
352}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette