4 * Copyright (c) 2004-2005 Vassili Karpov (malc)
5 * Copyright (c) 1998 Fabrice Bellard
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:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
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
25 #include "qemu/osdep.h"
26 #include "qemu-common.h"
29 #define AUDIO_CAP "mixeng"
30 #include "audio_int.h"
33 #define ENDIAN_CONVERSION natural
34 #define ENDIAN_CONVERT(v) (v)
39 #define IN_MIN SCHAR_MIN
40 #define IN_MAX SCHAR_MAX
43 #include "mixeng_template.h"
55 #define IN_MAX UCHAR_MAX
57 #include "mixeng_template.h"
65 #undef ENDIAN_CONVERSION
70 #define IN_MIN SHRT_MIN
71 #define IN_MAX SHRT_MAX
74 #define ENDIAN_CONVERSION natural
75 #define ENDIAN_CONVERT(v) (v)
76 #include "mixeng_template.h"
78 #undef ENDIAN_CONVERSION
79 #define ENDIAN_CONVERSION swap
80 #define ENDIAN_CONVERT(v) bswap16 (v)
81 #include "mixeng_template.h"
83 #undef ENDIAN_CONVERSION
95 #define IN_MAX USHRT_MAX
97 #define ENDIAN_CONVERSION natural
98 #define ENDIAN_CONVERT(v) (v)
99 #include "mixeng_template.h"
100 #undef ENDIAN_CONVERT
101 #undef ENDIAN_CONVERSION
102 #define ENDIAN_CONVERSION swap
103 #define ENDIAN_CONVERT(v) bswap16 (v)
104 #include "mixeng_template.h"
105 #undef ENDIAN_CONVERT
106 #undef ENDIAN_CONVERSION
116 #define IN_MIN INT32_MIN
117 #define IN_MAX INT32_MAX
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
137 /* Unsigned 32 bit */
141 #define IN_MAX UINT32_MAX
143 #define ENDIAN_CONVERSION natural
144 #define ENDIAN_CONVERT(v) (v)
145 #include "mixeng_template.h"
146 #undef ENDIAN_CONVERT
147 #undef ENDIAN_CONVERSION
148 #define ENDIAN_CONVERSION swap
149 #define ENDIAN_CONVERT(v) bswap32 (v)
150 #include "mixeng_template.h"
151 #undef ENDIAN_CONVERT
152 #undef ENDIAN_CONVERSION
159 t_sample
*mixeng_conv
[2][2][2][3] = {
163 conv_natural_uint8_t_to_mono
,
164 conv_natural_uint16_t_to_mono
,
165 conv_natural_uint32_t_to_mono
168 conv_natural_uint8_t_to_mono
,
169 conv_swap_uint16_t_to_mono
,
170 conv_swap_uint32_t_to_mono
,
175 conv_natural_int8_t_to_mono
,
176 conv_natural_int16_t_to_mono
,
177 conv_natural_int32_t_to_mono
180 conv_natural_int8_t_to_mono
,
181 conv_swap_int16_t_to_mono
,
182 conv_swap_int32_t_to_mono
189 conv_natural_uint8_t_to_stereo
,
190 conv_natural_uint16_t_to_stereo
,
191 conv_natural_uint32_t_to_stereo
194 conv_natural_uint8_t_to_stereo
,
195 conv_swap_uint16_t_to_stereo
,
196 conv_swap_uint32_t_to_stereo
201 conv_natural_int8_t_to_stereo
,
202 conv_natural_int16_t_to_stereo
,
203 conv_natural_int32_t_to_stereo
206 conv_natural_int8_t_to_stereo
,
207 conv_swap_int16_t_to_stereo
,
208 conv_swap_int32_t_to_stereo
,
214 f_sample
*mixeng_clip
[2][2][2][3] = {
218 clip_natural_uint8_t_from_mono
,
219 clip_natural_uint16_t_from_mono
,
220 clip_natural_uint32_t_from_mono
223 clip_natural_uint8_t_from_mono
,
224 clip_swap_uint16_t_from_mono
,
225 clip_swap_uint32_t_from_mono
230 clip_natural_int8_t_from_mono
,
231 clip_natural_int16_t_from_mono
,
232 clip_natural_int32_t_from_mono
235 clip_natural_int8_t_from_mono
,
236 clip_swap_int16_t_from_mono
,
237 clip_swap_int32_t_from_mono
244 clip_natural_uint8_t_from_stereo
,
245 clip_natural_uint16_t_from_stereo
,
246 clip_natural_uint32_t_from_stereo
249 clip_natural_uint8_t_from_stereo
,
250 clip_swap_uint16_t_from_stereo
,
251 clip_swap_uint32_t_from_stereo
256 clip_natural_int8_t_from_stereo
,
257 clip_natural_int16_t_from_stereo
,
258 clip_natural_int32_t_from_stereo
261 clip_natural_int8_t_from_stereo
,
262 clip_swap_int16_t_from_stereo
,
263 clip_swap_int32_t_from_stereo
271 * Copyright 1998 Fabrice Bellard.
273 * [Rewrote completly the code of Lance Norskog And Sundry
274 * Contributors with a more efficient algorithm.]
276 * This source code is freely redistributable and may be used for
277 * any purpose. This copyright notice must be maintained.
278 * Lance Norskog And Sundry Contributors are not responsible for
279 * the consequences of using this software.
283 * Sound Tools rate change effect file.
286 * Linear Interpolation.
288 * The use of fractional increment allows us to use no buffer. It
289 * avoid the problems at the end of the buffer we had with the old
290 * method which stored a possibly big buffer of size
291 * lcm(in_rate,out_rate).
293 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
294 * the input & output frequencies are equal, a delay of one sample is
295 * introduced. Limited to processing 32-bit count worth of samples.
297 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
298 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
305 uint32_t ipos
; /* position in the input stream (integer) */
306 struct st_sample ilast
; /* last sample in the input stream */
310 * Prepare processing.
312 void *st_rate_start (int inrate
, int outrate
)
314 struct rate
*rate
= audio_calloc (AUDIO_FUNC
, 1, sizeof (*rate
));
317 dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate
));
324 rate
->opos_inc
= ((uint64_t) inrate
<< 32) / outrate
;
332 #define NAME st_rate_flow_mix
333 #define OP(a, b) a += b
334 #include "rate_template.h"
336 #define NAME st_rate_flow
337 #define OP(a, b) a = b
338 #include "rate_template.h"
340 void st_rate_stop (void *opaque
)
345 void mixeng_clear (struct st_sample
*buf
, int len
)
347 memset (buf
, 0, len
* sizeof (struct st_sample
));
350 void mixeng_volume (struct st_sample
*buf
, int len
, struct mixeng_volume
*vol
)
353 mixeng_clear (buf
, len
);
359 buf
->l
= buf
->l
* vol
->l
;
360 buf
->r
= buf
->r
* vol
->r
;
362 buf
->l
= (buf
->l
* vol
->l
) >> 32;
363 buf
->r
= (buf
->r
* vol
->r
) >> 32;