bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU Mixing engine |
| 3 | * |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 4 | * Copyright (c) 2004-2005 Vassili Karpov (malc) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 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 | */ |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 25 | #include "qemu-common.h" |
| 26 | #include "audio.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 27 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 28 | #define AUDIO_CAP "mixeng" |
| 29 | #include "audio_int.h" |
| 30 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 31 | /* 8 bit */ |
| 32 | #define ENDIAN_CONVERSION natural |
| 33 | #define ENDIAN_CONVERT(v) (v) |
| 34 | |
| 35 | /* Signed 8 bit */ |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 36 | #define IN_T int8_t |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 37 | #define IN_MIN SCHAR_MIN |
| 38 | #define IN_MAX SCHAR_MAX |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 39 | #define SIGNED |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 40 | #define SHIFT 8 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 41 | #include "mixeng_template.h" |
| 42 | #undef SIGNED |
| 43 | #undef IN_MAX |
| 44 | #undef IN_MIN |
| 45 | #undef IN_T |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 46 | #undef SHIFT |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 47 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 48 | /* Unsigned 8 bit */ |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 49 | #define IN_T uint8_t |
| 50 | #define IN_MIN 0 |
| 51 | #define IN_MAX UCHAR_MAX |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 52 | #define SHIFT 8 |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 53 | #include "mixeng_template.h" |
| 54 | #undef IN_MAX |
| 55 | #undef IN_MIN |
| 56 | #undef IN_T |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 57 | #undef SHIFT |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 58 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 59 | #undef ENDIAN_CONVERT |
| 60 | #undef ENDIAN_CONVERSION |
| 61 | |
| 62 | /* Signed 16 bit */ |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 63 | #define IN_T int16_t |
| 64 | #define IN_MIN SHRT_MIN |
| 65 | #define IN_MAX SHRT_MAX |
| 66 | #define SIGNED |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 67 | #define SHIFT 16 |
| 68 | #define ENDIAN_CONVERSION natural |
| 69 | #define ENDIAN_CONVERT(v) (v) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 70 | #include "mixeng_template.h" |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 71 | #undef ENDIAN_CONVERT |
| 72 | #undef ENDIAN_CONVERSION |
| 73 | #define ENDIAN_CONVERSION swap |
| 74 | #define ENDIAN_CONVERT(v) bswap16 (v) |
| 75 | #include "mixeng_template.h" |
| 76 | #undef ENDIAN_CONVERT |
| 77 | #undef ENDIAN_CONVERSION |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 78 | #undef SIGNED |
| 79 | #undef IN_MAX |
| 80 | #undef IN_MIN |
| 81 | #undef IN_T |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 82 | #undef SHIFT |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 83 | |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 84 | /* Unsigned 16 bit */ |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 85 | #define IN_T uint16_t |
| 86 | #define IN_MIN 0 |
| 87 | #define IN_MAX USHRT_MAX |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 88 | #define SHIFT 16 |
| 89 | #define ENDIAN_CONVERSION natural |
| 90 | #define ENDIAN_CONVERT(v) (v) |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 91 | #include "mixeng_template.h" |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 92 | #undef ENDIAN_CONVERT |
| 93 | #undef ENDIAN_CONVERSION |
| 94 | #define ENDIAN_CONVERSION swap |
| 95 | #define ENDIAN_CONVERT(v) bswap16 (v) |
| 96 | #include "mixeng_template.h" |
| 97 | #undef ENDIAN_CONVERT |
| 98 | #undef ENDIAN_CONVERSION |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 99 | #undef IN_MAX |
| 100 | #undef IN_MIN |
| 101 | #undef IN_T |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 102 | #undef SHIFT |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 103 | |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 104 | /* Signed 32 bit */ |
| 105 | #define IN_T int32_t |
| 106 | #define IN_MIN INT32_MIN |
| 107 | #define IN_MAX INT32_MAX |
| 108 | #define SIGNED |
| 109 | #define SHIFT 32 |
| 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 |
| 120 | #undef SIGNED |
| 121 | #undef IN_MAX |
| 122 | #undef IN_MIN |
| 123 | #undef IN_T |
| 124 | #undef SHIFT |
| 125 | |
malc | ad483a5 | 2010-03-11 18:28:38 +0300 | [diff] [blame] | 126 | /* Unsigned 32 bit */ |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 127 | #define IN_T uint32_t |
| 128 | #define IN_MIN 0 |
| 129 | #define IN_MAX UINT32_MAX |
| 130 | #define SHIFT 32 |
| 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 |
| 141 | #undef IN_MAX |
| 142 | #undef IN_MIN |
| 143 | #undef IN_T |
| 144 | #undef SHIFT |
| 145 | |
| 146 | t_sample *mixeng_conv[2][2][2][3] = { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 147 | { |
| 148 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 149 | { |
| 150 | conv_natural_uint8_t_to_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 151 | conv_natural_uint16_t_to_mono, |
| 152 | conv_natural_uint32_t_to_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 153 | }, |
| 154 | { |
| 155 | conv_natural_uint8_t_to_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 156 | conv_swap_uint16_t_to_mono, |
| 157 | conv_swap_uint32_t_to_mono, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 158 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 159 | }, |
| 160 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 161 | { |
| 162 | conv_natural_int8_t_to_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 163 | conv_natural_int16_t_to_mono, |
| 164 | conv_natural_int32_t_to_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 165 | }, |
| 166 | { |
| 167 | conv_natural_int8_t_to_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 168 | conv_swap_int16_t_to_mono, |
| 169 | conv_swap_int32_t_to_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 170 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 171 | } |
| 172 | }, |
| 173 | { |
| 174 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 175 | { |
| 176 | conv_natural_uint8_t_to_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 177 | conv_natural_uint16_t_to_stereo, |
| 178 | conv_natural_uint32_t_to_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 179 | }, |
| 180 | { |
| 181 | conv_natural_uint8_t_to_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 182 | conv_swap_uint16_t_to_stereo, |
| 183 | conv_swap_uint32_t_to_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 184 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 185 | }, |
| 186 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 187 | { |
| 188 | conv_natural_int8_t_to_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 189 | conv_natural_int16_t_to_stereo, |
| 190 | conv_natural_int32_t_to_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 191 | }, |
| 192 | { |
| 193 | conv_natural_int8_t_to_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 194 | conv_swap_int16_t_to_stereo, |
| 195 | conv_swap_int32_t_to_stereo, |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 196 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 197 | } |
| 198 | } |
| 199 | }; |
| 200 | |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 201 | f_sample *mixeng_clip[2][2][2][3] = { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 202 | { |
| 203 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 204 | { |
| 205 | clip_natural_uint8_t_from_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 206 | clip_natural_uint16_t_from_mono, |
| 207 | clip_natural_uint32_t_from_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 208 | }, |
| 209 | { |
| 210 | clip_natural_uint8_t_from_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 211 | clip_swap_uint16_t_from_mono, |
| 212 | clip_swap_uint32_t_from_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 213 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 214 | }, |
| 215 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 216 | { |
| 217 | clip_natural_int8_t_from_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 218 | clip_natural_int16_t_from_mono, |
| 219 | clip_natural_int32_t_from_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 220 | }, |
| 221 | { |
| 222 | clip_natural_int8_t_from_mono, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 223 | clip_swap_int16_t_from_mono, |
| 224 | clip_swap_int32_t_from_mono |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 225 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 226 | } |
| 227 | }, |
| 228 | { |
| 229 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 230 | { |
| 231 | clip_natural_uint8_t_from_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 232 | clip_natural_uint16_t_from_stereo, |
| 233 | clip_natural_uint32_t_from_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 234 | }, |
| 235 | { |
| 236 | clip_natural_uint8_t_from_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 237 | clip_swap_uint16_t_from_stereo, |
| 238 | clip_swap_uint32_t_from_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 239 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 240 | }, |
| 241 | { |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 242 | { |
| 243 | clip_natural_int8_t_from_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 244 | clip_natural_int16_t_from_stereo, |
| 245 | clip_natural_int32_t_from_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 246 | }, |
| 247 | { |
| 248 | clip_natural_int8_t_from_stereo, |
ths | f941aa2 | 2007-02-17 22:19:29 +0000 | [diff] [blame] | 249 | clip_swap_int16_t_from_stereo, |
| 250 | clip_swap_int32_t_from_stereo |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 251 | } |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 252 | } |
| 253 | } |
| 254 | }; |
| 255 | |
| 256 | /* |
| 257 | * August 21, 1998 |
| 258 | * Copyright 1998 Fabrice Bellard. |
| 259 | * |
| 260 | * [Rewrote completly the code of Lance Norskog And Sundry |
| 261 | * Contributors with a more efficient algorithm.] |
| 262 | * |
| 263 | * This source code is freely redistributable and may be used for |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 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. |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 267 | */ |
| 268 | |
| 269 | /* |
| 270 | * Sound Tools rate change effect file. |
| 271 | */ |
| 272 | /* |
| 273 | * Linear Interpolation. |
| 274 | * |
| 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). |
| 279 | * |
| 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. |
| 283 | * |
| 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 |
| 286 | */ |
| 287 | |
| 288 | /* Private data */ |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 289 | struct rate { |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 290 | uint64_t opos; |
| 291 | uint64_t opos_inc; |
| 292 | uint32_t ipos; /* position in the input stream (integer) */ |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 293 | struct st_sample ilast; /* last sample in the input stream */ |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 294 | }; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 295 | |
| 296 | /* |
| 297 | * Prepare processing. |
| 298 | */ |
| 299 | void *st_rate_start (int inrate, int outrate) |
| 300 | { |
bellard | c0fe382 | 2005-11-05 18:55:28 +0000 | [diff] [blame] | 301 | struct rate *rate = audio_calloc (AUDIO_FUNC, 1, sizeof (*rate)); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 302 | |
| 303 | if (!rate) { |
bellard | e7cad33 | 2005-11-11 00:03:36 +0000 | [diff] [blame] | 304 | dolog ("Could not allocate resampler (%zu bytes)\n", sizeof (*rate)); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 305 | return NULL; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | rate->opos = 0; |
| 309 | |
| 310 | /* increment */ |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 311 | rate->opos_inc = ((uint64_t) inrate << 32) / outrate; |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 312 | |
| 313 | rate->ipos = 0; |
| 314 | rate->ilast.l = 0; |
| 315 | rate->ilast.r = 0; |
| 316 | return rate; |
| 317 | } |
| 318 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 319 | #define NAME st_rate_flow_mix |
| 320 | #define OP(a, b) a += b |
| 321 | #include "rate_template.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 322 | |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 323 | #define NAME st_rate_flow |
| 324 | #define OP(a, b) a = b |
| 325 | #include "rate_template.h" |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 326 | |
| 327 | void st_rate_stop (void *opaque) |
| 328 | { |
Anthony Liguori | 7267c09 | 2011-08-20 22:09:37 -0500 | [diff] [blame] | 329 | g_free (opaque); |
bellard | 85571bc | 2004-11-07 18:04:02 +0000 | [diff] [blame] | 330 | } |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 331 | |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 332 | void mixeng_clear (struct st_sample *buf, int len) |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 333 | { |
malc | 1ea879e | 2008-12-03 22:48:44 +0000 | [diff] [blame] | 334 | memset (buf, 0, len * sizeof (struct st_sample)); |
bellard | 1d14ffa | 2005-10-30 18:58:22 +0000 | [diff] [blame] | 335 | } |
Michael Walle | 00e0767 | 2011-01-05 01:05:47 +0100 | [diff] [blame] | 336 | |
| 337 | void mixeng_volume (struct st_sample *buf, int len, struct mixeng_volume *vol) |
| 338 | { |
| 339 | #ifdef CONFIG_MIXEMU |
| 340 | if (vol->mute) { |
| 341 | mixeng_clear (buf, len); |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | while (len--) { |
| 346 | #ifdef FLOAT_MIXENG |
| 347 | buf->l = buf->l * vol->l; |
| 348 | buf->r = buf->r * vol->r; |
| 349 | #else |
| 350 | buf->l = (buf->l * vol->l) >> 32; |
| 351 | buf->r = (buf->r * vol->r) >> 32; |
| 352 | #endif |
| 353 | buf += 1; |
| 354 | } |
| 355 | #else |
| 356 | (void) buf; |
| 357 | (void) len; |
| 358 | (void) vol; |
| 359 | #endif |
| 360 | } |