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"
34 #define ENDIAN_CONVERSION natural
35 #define ENDIAN_CONVERT(v) (v)
39 #define IN_MIN SCHAR_MIN
40 #define IN_MAX SCHAR_MAX
43 #include "mixeng_template.h"
53 #define IN_MAX UCHAR_MAX
55 #include "mixeng_template.h"
62 #undef ENDIAN_CONVERSION
66 #define IN_MIN SHRT_MIN
67 #define IN_MAX SHRT_MAX
70 #define ENDIAN_CONVERSION natural
71 #define ENDIAN_CONVERT(v) (v)
72 #include "mixeng_template.h"
74 #undef ENDIAN_CONVERSION
75 #define ENDIAN_CONVERSION swap
76 #define ENDIAN_CONVERT(v) bswap16 (v)
77 #include "mixeng_template.h"
79 #undef ENDIAN_CONVERSION
89 #define IN_MAX USHRT_MAX
91 #define ENDIAN_CONVERSION natural
92 #define ENDIAN_CONVERT(v) (v)
93 #include "mixeng_template.h"
95 #undef ENDIAN_CONVERSION
96 #define ENDIAN_CONVERSION swap
97 #define ENDIAN_CONVERT(v) bswap16 (v)
98 #include "mixeng_template.h"
100 #undef ENDIAN_CONVERSION
108 #define IN_MIN INT32_MIN
109 #define IN_MAX INT32_MAX
112 #define ENDIAN_CONVERSION natural
113 #define ENDIAN_CONVERT(v) (v)
114 #include "mixeng_template.h"
115 #undef ENDIAN_CONVERT
116 #undef ENDIAN_CONVERSION
117 #define ENDIAN_CONVERSION swap
118 #define ENDIAN_CONVERT(v) bswap32 (v)
119 #include "mixeng_template.h"
120 #undef ENDIAN_CONVERT
121 #undef ENDIAN_CONVERSION
128 /* Unsigned 16 bit */
129 #define IN_T uint32_t
131 #define IN_MAX UINT32_MAX
133 #define ENDIAN_CONVERSION natural
134 #define ENDIAN_CONVERT(v) (v)
135 #include "mixeng_template.h"
136 #undef ENDIAN_CONVERT
137 #undef ENDIAN_CONVERSION
138 #define ENDIAN_CONVERSION swap
139 #define ENDIAN_CONVERT(v) bswap32 (v)
140 #include "mixeng_template.h"
141 #undef ENDIAN_CONVERT
142 #undef ENDIAN_CONVERSION
148 t_sample
*mixeng_conv
[2][2][2][3] = {
152 conv_natural_uint8_t_to_mono
,
153 conv_natural_uint16_t_to_mono
,
154 conv_natural_uint32_t_to_mono
157 conv_natural_uint8_t_to_mono
,
158 conv_swap_uint16_t_to_mono
,
159 conv_swap_uint32_t_to_mono
,
164 conv_natural_int8_t_to_mono
,
165 conv_natural_int16_t_to_mono
,
166 conv_natural_int32_t_to_mono
169 conv_natural_int8_t_to_mono
,
170 conv_swap_int16_t_to_mono
,
171 conv_swap_int32_t_to_mono
178 conv_natural_uint8_t_to_stereo
,
179 conv_natural_uint16_t_to_stereo
,
180 conv_natural_uint32_t_to_stereo
183 conv_natural_uint8_t_to_stereo
,
184 conv_swap_uint16_t_to_stereo
,
185 conv_swap_uint32_t_to_stereo
190 conv_natural_int8_t_to_stereo
,
191 conv_natural_int16_t_to_stereo
,
192 conv_natural_int32_t_to_stereo
195 conv_natural_int8_t_to_stereo
,
196 conv_swap_int16_t_to_stereo
,
197 conv_swap_int32_t_to_stereo
,
203 f_sample
*mixeng_clip
[2][2][2][3] = {
207 clip_natural_uint8_t_from_mono
,
208 clip_natural_uint16_t_from_mono
,
209 clip_natural_uint32_t_from_mono
212 clip_natural_uint8_t_from_mono
,
213 clip_swap_uint16_t_from_mono
,
214 clip_swap_uint32_t_from_mono
219 clip_natural_int8_t_from_mono
,
220 clip_natural_int16_t_from_mono
,
221 clip_natural_int32_t_from_mono
224 clip_natural_int8_t_from_mono
,
225 clip_swap_int16_t_from_mono
,
226 clip_swap_int32_t_from_mono
233 clip_natural_uint8_t_from_stereo
,
234 clip_natural_uint16_t_from_stereo
,
235 clip_natural_uint32_t_from_stereo
238 clip_natural_uint8_t_from_stereo
,
239 clip_swap_uint16_t_from_stereo
,
240 clip_swap_uint32_t_from_stereo
245 clip_natural_int8_t_from_stereo
,
246 clip_natural_int16_t_from_stereo
,
247 clip_natural_int32_t_from_stereo
250 clip_natural_int8_t_from_stereo
,
251 clip_swap_int16_t_from_stereo
,
252 clip_swap_int32_t_from_stereo
260 * Copyright 1998 Fabrice Bellard.
262 * [Rewrote completly the code of Lance Norskog And Sundry
263 * Contributors with a more efficient algorithm.]
265 * This source code is freely redistributable and may be used for
266 * any purpose. This copyright notice must be maintained.
267 * Lance Norskog And Sundry Contributors are not responsible for
268 * the consequences of using this software.
272 * Sound Tools rate change effect file.
275 * Linear Interpolation.
277 * The use of fractional increment allows us to use no buffer. It
278 * avoid the problems at the end of the buffer we had with the old
279 * method which stored a possibly big buffer of size
280 * lcm(in_rate,out_rate).
282 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
283 * the input & output frequencies are equal, a delay of one sample is
284 * introduced. Limited to processing 32-bit count worth of samples.
286 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
287 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
294 uint32_t ipos
; /* position in the input stream (integer) */
295 st_sample_t ilast
; /* last sample in the input stream */
299 * Prepare processing.
301 void *st_rate_start (int inrate
, int outrate
)
303 struct rate
*rate
= audio_calloc (AUDIO_FUNC
, 1, sizeof (*rate
));
306 dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate
));
313 rate
->opos_inc
= ((uint64_t) inrate
<< 32) / outrate
;
321 #define NAME st_rate_flow_mix
322 #define OP(a, b) a += b
323 #include "rate_template.h"
325 #define NAME st_rate_flow
326 #define OP(a, b) a = b
327 #include "rate_template.h"
329 void st_rate_stop (void *opaque
)
334 void mixeng_clear (st_sample_t
*buf
, int len
)
336 memset (buf
, 0, len
* sizeof (st_sample_t
));