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-common.h"
28 #define AUDIO_CAP "mixeng"
29 #include "audio_int.h"
32 #define ENDIAN_CONVERSION natural
33 #define ENDIAN_CONVERT(v) (v)
37 #define IN_MIN SCHAR_MIN
38 #define IN_MAX SCHAR_MAX
41 #include "mixeng_template.h"
51 #define IN_MAX UCHAR_MAX
53 #include "mixeng_template.h"
60 #undef ENDIAN_CONVERSION
64 #define IN_MIN SHRT_MIN
65 #define IN_MAX SHRT_MAX
68 #define ENDIAN_CONVERSION natural
69 #define ENDIAN_CONVERT(v) (v)
70 #include "mixeng_template.h"
72 #undef ENDIAN_CONVERSION
73 #define ENDIAN_CONVERSION swap
74 #define ENDIAN_CONVERT(v) bswap16 (v)
75 #include "mixeng_template.h"
77 #undef ENDIAN_CONVERSION
87 #define IN_MAX USHRT_MAX
89 #define ENDIAN_CONVERSION natural
90 #define ENDIAN_CONVERT(v) (v)
91 #include "mixeng_template.h"
93 #undef ENDIAN_CONVERSION
94 #define ENDIAN_CONVERSION swap
95 #define ENDIAN_CONVERT(v) bswap16 (v)
96 #include "mixeng_template.h"
98 #undef ENDIAN_CONVERSION
106 #define IN_MIN INT32_MIN
107 #define IN_MAX INT32_MAX
110 #define ENDIAN_CONVERSION natural
111 #define ENDIAN_CONVERT(v) (v)
112 #include "mixeng_template.h"
113 #undef ENDIAN_CONVERT
114 #undef ENDIAN_CONVERSION
115 #define ENDIAN_CONVERSION swap
116 #define ENDIAN_CONVERT(v) bswap32 (v)
117 #include "mixeng_template.h"
118 #undef ENDIAN_CONVERT
119 #undef ENDIAN_CONVERSION
126 /* Unsigned 32 bit */
127 #define IN_T uint32_t
129 #define IN_MAX UINT32_MAX
131 #define ENDIAN_CONVERSION natural
132 #define ENDIAN_CONVERT(v) (v)
133 #include "mixeng_template.h"
134 #undef ENDIAN_CONVERT
135 #undef ENDIAN_CONVERSION
136 #define ENDIAN_CONVERSION swap
137 #define ENDIAN_CONVERT(v) bswap32 (v)
138 #include "mixeng_template.h"
139 #undef ENDIAN_CONVERT
140 #undef ENDIAN_CONVERSION
146 t_sample
*mixeng_conv
[2][2][2][3] = {
150 conv_natural_uint8_t_to_mono
,
151 conv_natural_uint16_t_to_mono
,
152 conv_natural_uint32_t_to_mono
155 conv_natural_uint8_t_to_mono
,
156 conv_swap_uint16_t_to_mono
,
157 conv_swap_uint32_t_to_mono
,
162 conv_natural_int8_t_to_mono
,
163 conv_natural_int16_t_to_mono
,
164 conv_natural_int32_t_to_mono
167 conv_natural_int8_t_to_mono
,
168 conv_swap_int16_t_to_mono
,
169 conv_swap_int32_t_to_mono
176 conv_natural_uint8_t_to_stereo
,
177 conv_natural_uint16_t_to_stereo
,
178 conv_natural_uint32_t_to_stereo
181 conv_natural_uint8_t_to_stereo
,
182 conv_swap_uint16_t_to_stereo
,
183 conv_swap_uint32_t_to_stereo
188 conv_natural_int8_t_to_stereo
,
189 conv_natural_int16_t_to_stereo
,
190 conv_natural_int32_t_to_stereo
193 conv_natural_int8_t_to_stereo
,
194 conv_swap_int16_t_to_stereo
,
195 conv_swap_int32_t_to_stereo
,
201 f_sample
*mixeng_clip
[2][2][2][3] = {
205 clip_natural_uint8_t_from_mono
,
206 clip_natural_uint16_t_from_mono
,
207 clip_natural_uint32_t_from_mono
210 clip_natural_uint8_t_from_mono
,
211 clip_swap_uint16_t_from_mono
,
212 clip_swap_uint32_t_from_mono
217 clip_natural_int8_t_from_mono
,
218 clip_natural_int16_t_from_mono
,
219 clip_natural_int32_t_from_mono
222 clip_natural_int8_t_from_mono
,
223 clip_swap_int16_t_from_mono
,
224 clip_swap_int32_t_from_mono
231 clip_natural_uint8_t_from_stereo
,
232 clip_natural_uint16_t_from_stereo
,
233 clip_natural_uint32_t_from_stereo
236 clip_natural_uint8_t_from_stereo
,
237 clip_swap_uint16_t_from_stereo
,
238 clip_swap_uint32_t_from_stereo
243 clip_natural_int8_t_from_stereo
,
244 clip_natural_int16_t_from_stereo
,
245 clip_natural_int32_t_from_stereo
248 clip_natural_int8_t_from_stereo
,
249 clip_swap_int16_t_from_stereo
,
250 clip_swap_int32_t_from_stereo
258 * Copyright 1998 Fabrice Bellard.
260 * [Rewrote completly the code of Lance Norskog And Sundry
261 * Contributors with a more efficient algorithm.]
263 * This source code is freely redistributable and may be used for
264 * any purpose. This copyright notice must be maintained.
265 * Lance Norskog And Sundry Contributors are not responsible for
266 * the consequences of using this software.
270 * Sound Tools rate change effect file.
273 * Linear Interpolation.
275 * The use of fractional increment allows us to use no buffer. It
276 * avoid the problems at the end of the buffer we had with the old
277 * method which stored a possibly big buffer of size
278 * lcm(in_rate,out_rate).
280 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
281 * the input & output frequencies are equal, a delay of one sample is
282 * introduced. Limited to processing 32-bit count worth of samples.
284 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
285 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
292 uint32_t ipos
; /* position in the input stream (integer) */
293 struct st_sample ilast
; /* last sample in the input stream */
297 * Prepare processing.
299 void *st_rate_start (int inrate
, int outrate
)
301 struct rate
*rate
= audio_calloc (AUDIO_FUNC
, 1, sizeof (*rate
));
304 dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate
));
311 rate
->opos_inc
= ((uint64_t) inrate
<< 32) / outrate
;
319 #define NAME st_rate_flow_mix
320 #define OP(a, b) a += b
321 #include "rate_template.h"
323 #define NAME st_rate_flow
324 #define OP(a, b) a = b
325 #include "rate_template.h"
327 void st_rate_stop (void *opaque
)
332 void mixeng_clear (struct st_sample
*buf
, int len
)
334 memset (buf
, 0, len
* sizeof (struct st_sample
));
337 void mixeng_volume (struct st_sample
*buf
, int len
, struct mixeng_volume
*vol
)
341 mixeng_clear (buf
, len
);
347 buf
->l
= buf
->l
* vol
->l
;
348 buf
->r
= buf
->r
* vol
->r
;
350 buf
->l
= (buf
->l
* vol
->l
) >> 32;
351 buf
->r
= (buf
->r
* vol
->r
) >> 32;