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"
27 #include "qemu/bswap.h"
28 #include "qemu/error-report.h"
31 #define AUDIO_CAP "mixeng"
32 #include "audio_int.h"
35 #define ENDIAN_CONVERSION natural
36 #define ENDIAN_CONVERT(v) (v)
41 #define IN_MIN SCHAR_MIN
42 #define IN_MAX SCHAR_MAX
45 #include "mixeng_template.h"
57 #define IN_MAX UCHAR_MAX
59 #include "mixeng_template.h"
67 #undef ENDIAN_CONVERSION
72 #define IN_MIN SHRT_MIN
73 #define IN_MAX SHRT_MAX
76 #define ENDIAN_CONVERSION natural
77 #define ENDIAN_CONVERT(v) (v)
78 #include "mixeng_template.h"
80 #undef ENDIAN_CONVERSION
81 #define ENDIAN_CONVERSION swap
82 #define ENDIAN_CONVERT(v) bswap16 (v)
83 #include "mixeng_template.h"
85 #undef ENDIAN_CONVERSION
97 #define IN_MAX USHRT_MAX
99 #define ENDIAN_CONVERSION natural
100 #define ENDIAN_CONVERT(v) (v)
101 #include "mixeng_template.h"
102 #undef ENDIAN_CONVERT
103 #undef ENDIAN_CONVERSION
104 #define ENDIAN_CONVERSION swap
105 #define ENDIAN_CONVERT(v) bswap16 (v)
106 #include "mixeng_template.h"
107 #undef ENDIAN_CONVERT
108 #undef ENDIAN_CONVERSION
118 #define IN_MIN INT32_MIN
119 #define IN_MAX INT32_MAX
122 #define ENDIAN_CONVERSION natural
123 #define ENDIAN_CONVERT(v) (v)
124 #include "mixeng_template.h"
125 #undef ENDIAN_CONVERT
126 #undef ENDIAN_CONVERSION
127 #define ENDIAN_CONVERSION swap
128 #define ENDIAN_CONVERT(v) bswap32 (v)
129 #include "mixeng_template.h"
130 #undef ENDIAN_CONVERT
131 #undef ENDIAN_CONVERSION
139 /* Unsigned 32 bit */
143 #define IN_MAX UINT32_MAX
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
161 t_sample
*mixeng_conv
[2][2][2][3] = {
165 conv_natural_uint8_t_to_mono
,
166 conv_natural_uint16_t_to_mono
,
167 conv_natural_uint32_t_to_mono
170 conv_natural_uint8_t_to_mono
,
171 conv_swap_uint16_t_to_mono
,
172 conv_swap_uint32_t_to_mono
,
177 conv_natural_int8_t_to_mono
,
178 conv_natural_int16_t_to_mono
,
179 conv_natural_int32_t_to_mono
182 conv_natural_int8_t_to_mono
,
183 conv_swap_int16_t_to_mono
,
184 conv_swap_int32_t_to_mono
191 conv_natural_uint8_t_to_stereo
,
192 conv_natural_uint16_t_to_stereo
,
193 conv_natural_uint32_t_to_stereo
196 conv_natural_uint8_t_to_stereo
,
197 conv_swap_uint16_t_to_stereo
,
198 conv_swap_uint32_t_to_stereo
203 conv_natural_int8_t_to_stereo
,
204 conv_natural_int16_t_to_stereo
,
205 conv_natural_int32_t_to_stereo
208 conv_natural_int8_t_to_stereo
,
209 conv_swap_int16_t_to_stereo
,
210 conv_swap_int32_t_to_stereo
,
216 f_sample
*mixeng_clip
[2][2][2][3] = {
220 clip_natural_uint8_t_from_mono
,
221 clip_natural_uint16_t_from_mono
,
222 clip_natural_uint32_t_from_mono
225 clip_natural_uint8_t_from_mono
,
226 clip_swap_uint16_t_from_mono
,
227 clip_swap_uint32_t_from_mono
232 clip_natural_int8_t_from_mono
,
233 clip_natural_int16_t_from_mono
,
234 clip_natural_int32_t_from_mono
237 clip_natural_int8_t_from_mono
,
238 clip_swap_int16_t_from_mono
,
239 clip_swap_int32_t_from_mono
246 clip_natural_uint8_t_from_stereo
,
247 clip_natural_uint16_t_from_stereo
,
248 clip_natural_uint32_t_from_stereo
251 clip_natural_uint8_t_from_stereo
,
252 clip_swap_uint16_t_from_stereo
,
253 clip_swap_uint32_t_from_stereo
258 clip_natural_int8_t_from_stereo
,
259 clip_natural_int16_t_from_stereo
,
260 clip_natural_int32_t_from_stereo
263 clip_natural_int8_t_from_stereo
,
264 clip_swap_int16_t_from_stereo
,
265 clip_swap_int32_t_from_stereo
272 void audio_sample_to_uint64(void *samples
, int pos
,
273 uint64_t *left
, uint64_t *right
)
275 struct st_sample
*sample
= samples
;
279 "Coreaudio and floating point samples are not supported by replay yet");
287 void audio_sample_from_uint64(void *samples
, int pos
,
288 uint64_t left
, uint64_t right
)
290 struct st_sample
*sample
= samples
;
294 "Coreaudio and floating point samples are not supported by replay yet");
304 * Copyright 1998 Fabrice Bellard.
306 * [Rewrote completely the code of Lance Norskog And Sundry
307 * Contributors with a more efficient algorithm.]
309 * This source code is freely redistributable and may be used for
310 * any purpose. This copyright notice must be maintained.
311 * Lance Norskog And Sundry Contributors are not responsible for
312 * the consequences of using this software.
316 * Sound Tools rate change effect file.
319 * Linear Interpolation.
321 * The use of fractional increment allows us to use no buffer. It
322 * avoid the problems at the end of the buffer we had with the old
323 * method which stored a possibly big buffer of size
324 * lcm(in_rate,out_rate).
326 * Limited to 16 bit samples and sampling frequency <= 65535 Hz. If
327 * the input & output frequencies are equal, a delay of one sample is
328 * introduced. Limited to processing 32-bit count worth of samples.
330 * 1 << FRAC_BITS evaluating to zero in several places. Changed with
331 * an (unsigned long) cast to make it safe. MarkMLl 2/1/99
338 uint32_t ipos
; /* position in the input stream (integer) */
339 struct st_sample ilast
; /* last sample in the input stream */
343 * Prepare processing.
345 void *st_rate_start (int inrate
, int outrate
)
347 struct rate
*rate
= audio_calloc(__func__
, 1, sizeof(*rate
));
350 dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate
));
357 rate
->opos_inc
= ((uint64_t) inrate
<< 32) / outrate
;
365 #define NAME st_rate_flow_mix
366 #define OP(a, b) a += b
367 #include "rate_template.h"
369 #define NAME st_rate_flow
370 #define OP(a, b) a = b
371 #include "rate_template.h"
373 void st_rate_stop (void *opaque
)
378 void mixeng_clear (struct st_sample
*buf
, int len
)
380 memset (buf
, 0, len
* sizeof (struct st_sample
));
383 void mixeng_volume (struct st_sample
*buf
, int len
, struct mixeng_volume
*vol
)
386 mixeng_clear (buf
, len
);
392 buf
->l
= buf
->l
* vol
->l
;
393 buf
->r
= buf
->r
* vol
->r
;
395 buf
->l
= (buf
->l
* vol
->l
) >> 32;
396 buf
->r
= (buf
->r
* vol
->r
) >> 32;