VirtualBox

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

Last change on this file since 54153 was 50686, checked in by vboxsync, 11 years ago

src/VBox/Devices/Audio, src/VBox/Main/src-client, include/VBox/vmm:

src/VBox/Devices/Audio: part of restructuring of audio code. Devices files correspondin to Hda, AC97 and SB16 audio. The structure of files have been modifed as per PDM specs. The modified code is under #ifdef VBOX_WITH_PDM_AUDIO_DRIVER

src/VBox/Main/src-client: Driver for the VRDE that interacts with DrvAudio. Enhancement of the CFGM tree for audio.

Config.kmk : addition of one configuration parameter that will control whether new audio code is disabled or enabled. "VBOX_WITH_PDM_AUDIO_DRIVER"

pdmaudioifs.h: common header file between Device , Intermediate audio driver and Backends specific to audio.

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

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