VirtualBox

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

Last change on this file since 400 was 355, checked in by vboxsync, 18 years ago

activated soft volume mixing

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 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 "Builtins.h"
27#include "../../vl_vbox.h"
28#include "audio.h"
29#include <iprt/alloc.h>
30#ifdef VBOX
31#include <iprt/asm.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#define IN_T uint16_t
95#define IN_MIN 0
96#define IN_MAX USHRT_MAX
97#define SHIFT 16
98#define ENDIAN_CONVERSION natural
99#define ENDIAN_CONVERT(v) (v)
100#include "mixeng_template.h"
101#undef ENDIAN_CONVERT
102#undef ENDIAN_CONVERSION
103#define ENDIAN_CONVERSION swap
104#define ENDIAN_CONVERT(v) bswap16 (v)
105#include "mixeng_template.h"
106#undef ENDIAN_CONVERT
107#undef ENDIAN_CONVERSION
108#undef IN_MAX
109#undef IN_MIN
110#undef IN_T
111#undef SHIFT
112
113t_sample *mixeng_conv[2][2][2][2] = {
114 {
115 {
116 {
117 conv_natural_uint8_t_to_mono,
118 conv_natural_uint16_t_to_mono
119 },
120 {
121 conv_natural_uint8_t_to_mono,
122 conv_swap_uint16_t_to_mono
123 }
124 },
125 {
126 {
127 conv_natural_int8_t_to_mono,
128 conv_natural_int16_t_to_mono
129 },
130 {
131 conv_natural_int8_t_to_mono,
132 conv_swap_int16_t_to_mono
133 }
134 }
135 },
136 {
137 {
138 {
139 conv_natural_uint8_t_to_stereo,
140 conv_natural_uint16_t_to_stereo
141 },
142 {
143 conv_natural_uint8_t_to_stereo,
144 conv_swap_uint16_t_to_stereo
145 }
146 },
147 {
148 {
149 conv_natural_int8_t_to_stereo,
150 conv_natural_int16_t_to_stereo
151 },
152 {
153 conv_natural_int8_t_to_stereo,
154 conv_swap_int16_t_to_stereo
155 }
156 }
157 }
158};
159
160f_sample *mixeng_clip[2][2][2][2] = {
161 {
162 {
163 {
164 clip_natural_uint8_t_from_mono,
165 clip_natural_uint16_t_from_mono
166 },
167 {
168 clip_natural_uint8_t_from_mono,
169 clip_swap_uint16_t_from_mono
170 }
171 },
172 {
173 {
174 clip_natural_int8_t_from_mono,
175 clip_natural_int16_t_from_mono
176 },
177 {
178 clip_natural_int8_t_from_mono,
179 clip_swap_int16_t_from_mono
180 }
181 }
182 },
183 {
184 {
185 {
186 clip_natural_uint8_t_from_stereo,
187 clip_natural_uint16_t_from_stereo
188 },
189 {
190 clip_natural_uint8_t_from_stereo,
191 clip_swap_uint16_t_from_stereo
192 }
193 },
194 {
195 {
196 clip_natural_int8_t_from_stereo,
197 clip_natural_int16_t_from_stereo
198 },
199 {
200 clip_natural_int8_t_from_stereo,
201 clip_swap_int16_t_from_stereo
202 }
203 }
204 }
205};
206
207/*
208 * August 21, 1998
209 * Copyright 1998 Fabrice Bellard.
210 *
211 * [Rewrote completly the code of Lance Norskog And Sundry
212 * Contributors with a more efficient algorithm.]
213 *
214 * This source code is freely redistributable and may be used for
215 * any purpose. This copyright notice must be maintained.
216 * Lance Norskog And Sundry Contributors are not responsible for
217 * the consequences of using this software.
218 */
219
220/*
221 * Sound Tools rate change effect file.
222 */
223/*
224 * Linear Interpolation.
225 *
226 * The use of fractional increment allows us to use no buffer. It
227 * avoid the problems at the end of the buffer we had with the old
228 * method which stored a possibly big buffer of size
229 * lcm(in_rate,out_rate).
230 *
231 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
232 * the input & output frequencies are equal, a delay of one sample is
233 * introduced. Limited to processing 32-bit count worth of samples.
234 *
235 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
236 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
237 */
238
239/* Private data */
240struct rate {
241 uint64_t opos;
242 uint64_t opos_inc;
243 uint32_t ipos; /* position in the input stream (integer) */
244 st_sample_t ilast; /* last sample in the input stream */
245};
246
247/*
248 * Prepare processing.
249 */
250void *st_rate_start (int inrate, int outrate)
251{
252 struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate));
253
254 if (!rate) {
255 dolog ("Could not allocate resampler (%" FMTZ "u bytes)\n",
256 sizeof (*rate));
257 return NULL;
258 }
259
260 rate->opos = 0;
261
262 /* increment */
263 rate->opos_inc = ((uint64_t) inrate << 32) / outrate;
264
265 rate->ipos = 0;
266 rate->ilast.l = 0;
267 rate->ilast.r = 0;
268 return rate;
269}
270
271#define NAME st_rate_flow_mix
272#define OP(a, b) a += b
273#include "rate_template.h"
274
275#define NAME st_rate_flow
276#define OP(a, b) a = b
277#include "rate_template.h"
278
279void st_rate_stop (void *opaque)
280{
281 qemu_free (opaque);
282}
283
284void mixeng_clear (st_sample_t *buf, int len)
285{
286 memset (buf, 0, len * sizeof (st_sample_t));
287}
288
289void mixeng_sniff_and_clear (HWVoiceOut *hw, st_sample_t *src, int len)
290{
291 sniffer_run_out (hw, src, len);
292 mixeng_clear (src, len);
293}
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