~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Wine Cross Reference
wine/dlls/dsound/dsound_convert.c

Version: ~ [ wine-1.1.5 ] ~ [ wine-1.1.4 ] ~ [ wine-1.1.3 ] ~ [ wine-1.1.2 ] ~ [ wine-1.1.1 ] ~ [ wine-1.1.0 ] ~ [ wine-1.0 ] ~ [ wine-1.0-rc5 ] ~ [ wine-1.0-rc4 ] ~ [ wine-1.0-rc3 ] ~ [ wine-1.0-rc2 ] ~ [ wine-1.0-rc1 ] ~ [ wine-0.9.61 ] ~ [ wine-0.9.60 ] ~ [ wine-0.9.59 ] ~ [ wine-0.9.58 ] ~ [ wine-0.9.57 ] ~ [ wine-0.9.56 ] ~ [ wine-0.9.55 ] ~ [ wine-0.9.54 ] ~ [ wine-0.9.53 ] ~ [ wine-0.9.52 ] ~ [ wine-0.9.51 ] ~ [ wine-0.9.50 ] ~ [ wine-0.9.49 ] ~ [ wine-0.9.48 ] ~ [ wine-0.9.47 ] ~ [ wine-0.9.46 ] ~ [ wine-0.9.45 ] ~ [ wine-0.9.44 ] ~ [ wine-0.9.43 ] ~ [ wine-0.9.42 ] ~ [ wine-0.9.41 ] ~ [ wine-0.9.40 ] ~ [ wine-0.9.39 ] ~ [ wine-0.9.38 ] ~ [ wine-0.9.37 ] ~ [ wine-0.9.36 ] ~ [ wine-0.9.35 ] ~ [ wine-0.9.34 ] ~ [ wine-0.9.33 ] ~ [ wine-0.9.32 ] ~ [ wine-0.9.31 ] ~ [ wine-0.9.30 ] ~ [ wine-0.9.29 ] ~ [ wine-0.9.28 ] ~ [ wine-0.9.27 ] ~ [ wine-0.9.26 ] ~ [ wine-0.9.25 ] ~ [ wine-0.9.24 ] ~ [ wine-0.9.23 ] ~ [ wine-0.9.22 ] ~ [ wine-0.9.21 ] ~ [ wine-0.9.20 ] ~ [ wine-0.9.19 ] ~ [ wine-0.9.18 ] ~ [ wine-0.9.17 ] ~ [ wine-0.9.16 ] ~ [ wine-0.9.15 ] ~ [ wine-0.9.14 ] ~ [ wine-0.9.13 ] ~ [ wine-0.9.12 ] ~ [ wine-0.9.11 ] ~ [ wine-0.9.10 ] ~ [ wine-0.9.9 ] ~ [ wine-0.9.8 ] ~ [ wine-0.9.7 ] ~ [ wine-0.9.6 ] ~ [ wine-0.9.5 ] ~ [ wine-0.9.4 ] ~ [ wine-0.9.3 ] ~ [ wine-0.9.2 ] ~ [ wine-0.9.1 ] ~ [ wine-0.9 ] ~ [ wine20050930 ] ~ [ wine20050830 ] ~ [ wine20050725 ] ~ [ wine20050628 ] ~ [ wine20050524 ] ~ [ wine20050419 ] ~ [ wine20050310 ] ~ [ wine20050211 ] ~ [ wine20050111 ] ~ [ wine20041201 ] ~ [ wine20041019 ] ~ [ wine20040914 ] ~ [ wine20040813 ] ~ [ wine20040716 ] ~ [ wine20040615 ] ~ [ wine20040505 ] ~ [ wine20040408 ] ~ [ wine20040309 ] ~ [ wine20040213 ] ~ [ wine20040121 ] ~ [ wine20031212 ] ~ [ wine20031118 ] ~ [ wine20031016 ] ~ [ wine20030911 ] ~ [ wine20030813 ] ~ [ wine20030709 ] ~ [ wine20030618 ] ~ [ wine20030508 ] ~ [ wine20030408 ] ~ [ wine20030318 ] ~ [ wine20030219 ] ~ [ wine20030115 ] ~ [ wine20021219 ] ~ [ wine20021125 ] ~ [ wine20021031 ] ~ [ wine20021007 ] ~ [ wine20020904 ] ~ [ wine20020804 ] ~ [ wine20020710 ] ~ [ wine20020605 ] ~ [ wine20020509 ] ~ [ wine20020411 ] ~ [ wine20020310 ] ~ [ wine20020228 ] ~ [ wine20011226 ] ~ [ wine20011108 ] ~ [ wine20011004 ] ~ [ wine20010824 ] ~ [ wine20010731 ] ~ [ wine20010629 ] ~ [ wine20010510 ] ~ [ wine20010418 ] ~ [ wine20010326 ] ~ [ wine20010305 ] ~ [ wine20010216 ] ~ [ wine20010112 ] ~ [ wine20001222 ] ~ [ wine20001202 ] ~ [ wine20001026 ] ~ [ wine20001002 ] ~ [ wine20000909 ] ~ [ wine20000821 ] ~ [ wine20000801 ] ~ [ wine20000716 ] ~ [ wine20000326 ] ~ [ wine20000227 ] ~ [ wine20000130 ] ~ [ wine20000109 ] ~

  1 /* DirectSound format conversion and mixing routines
  2  *
  3  * Copyright 2007 Maarten Lankhorst
  4  *
  5  * This library is free software; you can redistribute it and/or
  6  * modify it under the terms of the GNU Lesser General Public
  7  * License as published by the Free Software Foundation; either
  8  * version 2.1 of the License, or (at your option) any later version.
  9  *
 10  * This library is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 13  * Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public
 16  * License along with this library; if not, write to the Free Software
 17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 18  */
 19 
 20 /* 8 bits is unsigned, the rest is signed.
 21  * First I tried to reuse existing stuff from alsa-lib, after that
 22  * didn't work, I gave up and just went for individual hacks.
 23  *
 24  * 24 bit is expensive to do, due to unaligned access.
 25  * In dlls/winex11.drv/dib_convert.c convert_888_to_0888_asis there is a way
 26  * around it, but I'm happy current code works, maybe something for later.
 27  *
 28  * The ^ 0x80 flips the signed bit, this is the conversion from
 29  * signed (-128.. 0.. 127) to unsigned (0...255)
 30  * This is only temporary: All 8 bit data should be converted to signed.
 31  * then when fed to the sound card, it should be converted to unsigned again.
 32  *
 33  * Sound is LITTLE endian
 34  */
 35 
 36 #include "config.h"
 37 #ifdef HAVE_STDINT_H
 38 #include <stdint.h>
 39 #endif
 40 #include <stdarg.h>
 41 
 42 #define NONAMELESSSTRUCT
 43 #define NONAMELESSUNION
 44 #include "windef.h"
 45 #include "winbase.h"
 46 #include "mmsystem.h"
 47 #include "winternl.h"
 48 #include "wine/debug.h"
 49 #include "dsound.h"
 50 #include "dsdriver.h"
 51 #include "dsound_private.h"
 52 
 53 WINE_DEFAULT_DEBUG_CHANNEL(dsound);
 54 
 55 #ifdef WORDS_BIGENDIAN
 56 #define le16(x) RtlUshortByteSwap((x))
 57 #define le32(x) RtlUlongByteSwap((x))
 58 #else
 59 #define le16(x) (x)
 60 #define le32(x) (x)
 61 #endif
 62 
 63 static void convert_8_to_8 (const void *src, void *dst)
 64 {
 65     uint8_t *dest = dst;
 66     *dest = *(uint8_t*)src;
 67 }
 68 
 69 static void convert_8_to_16 (const void *src, void *dst)
 70 {
 71     uint16_t dest = *(uint8_t*)src, *dest16 = dst;
 72     *dest16 = le16(dest * 257 - 32768);
 73 }
 74 
 75 static void convert_8_to_24 (const void *src, void *dst)
 76 {
 77     uint8_t dest = *(uint8_t*)src;
 78     uint8_t *dest24 = dst;
 79     dest24[0] = dest;
 80     dest24[1] = dest;
 81     dest24[2] = dest - 0x80;
 82 }
 83 
 84 static void convert_8_to_32 (const void *src, void *dst)
 85 {
 86     uint32_t dest = *(uint8_t*)src, *dest32 = dst;
 87     *dest32 = le32(dest * 16843009 - 2147483648U);
 88 }
 89 
 90 static void convert_16_to_8 (const void *src, void *dst)
 91 {
 92     uint8_t *dst8 = dst;
 93     *dst8 = (le16(*(uint16_t*)src)) / 256;
 94     *dst8 -= 0x80;
 95 }
 96 
 97 static void convert_16_to_16 (const void *src, void *dst)
 98 {
 99     uint16_t *dest = dst;
100     *dest = *(uint16_t*)src;
101 }
102 
103 static void convert_16_to_24 (const void *src, void *dst)
104 {
105     uint16_t dest = le16(*(uint16_t*)src);
106     uint8_t *dest24 = dst;
107 
108     dest24[0] = dest / 256;
109     dest24[1] = dest;
110     dest24[2] = dest / 256;
111 }
112 
113 static void convert_16_to_32 (const void *src, void *dst)
114 {
115     uint32_t dest = *(uint16_t*)src, *dest32 = dst;
116     *dest32 = dest * 65537;
117 }
118 
119 static void convert_24_to_8 (const void *src, void *dst)
120 {
121     uint8_t *dst8 = dst;
122     *dst8 = ((uint8_t *)src)[2];
123 }
124 
125 static void convert_24_to_16 (const void *src, void *dst)
126 {
127     uint16_t *dest16 = dst;
128     const uint8_t *source = src;
129     *dest16 = le16(source[2] * 256 + source[1]);
130 }
131 
132 static void convert_24_to_24 (const void *src, void *dst)
133 {
134     uint8_t *dest24 = dst;
135     const uint8_t *src24 = src;
136 
137     dest24[0] = src24[0];
138     dest24[1] = src24[1];
139     dest24[2] = src24[2];
140 }
141 
142 static void convert_24_to_32 (const void *src, void *dst)
143 {
144     uint32_t *dest32 = dst;
145     const uint8_t *source = src;
146     *dest32 = le32(source[2] * 16777217 + source[1] * 65536 + source[0] * 256);
147 }
148 
149 static void convert_32_to_8 (const void *src, void *dst)
150 {
151     uint8_t *dst8 = dst;
152     *dst8 = (le32(*(uint32_t *)src) / 16777216);
153     *dst8 -= 0x80;
154 }
155 
156 static void convert_32_to_16 (const void *src, void *dst)
157 {
158     uint16_t *dest16 = dst;
159     *dest16 = le16(le32(*(uint32_t*)src) / 65536);
160 }
161 
162 static void convert_32_to_24 (const void *src, void *dst)
163 {
164     uint32_t dest = le32(*(uint32_t*)dst);
165     uint8_t *dest24 = dst;
166 
167     dest24[0] = dest / 256;
168     dest24[1] = dest / 65536;
169     dest24[2] = dest / 16777216;
170 }
171 
172 static void convert_32_to_32 (const void *src, void *dst)
173 {
174     uint32_t *dest = dst;
175     *dest = *(uint32_t*)src;
176 }
177 
178 const bitsconvertfunc convertbpp[4][4] = {
179     { convert_8_to_8, convert_8_to_16, convert_8_to_24, convert_8_to_32 },
180     { convert_16_to_8, convert_16_to_16, convert_16_to_24, convert_16_to_32 },
181     { convert_24_to_8, convert_24_to_16, convert_24_to_24, convert_24_to_32 },
182     { convert_32_to_8, convert_32_to_16, convert_32_to_24, convert_32_to_32 },
183 };
184 
185 static void mix8(int8_t *src, int32_t *dst, unsigned len)
186 {
187     TRACE("%p - %p %d\n", src, dst, len);
188     while (len--)
189         /* 8-bit WAV is unsigned, it's here converted to signed, normalize function will convert it back again */
190         *(dst++) += (int8_t)((uint8_t)*(src++) - (uint8_t)0x80);
191 }
192 
193 static void mix16(int16_t *src, int32_t *dst, unsigned len)
194 {
195     TRACE("%p - %p %d\n", src, dst, len);
196     len /= 2;
197     while (len--)
198     {
199         *dst += le16(*src);
200         ++dst; ++src;
201     }
202 }
203 
204 static void mix24(uint8_t *src, int32_t *dst, unsigned len)
205 {
206     TRACE("%p - %p %d\n", src, dst, len);
207     len /= 3;
208     while (len--)
209     {
210         uint32_t field;
211         field = ((unsigned)src[2] << 16) + ((unsigned)src[1] << 8) + (unsigned)src[0];
212         if (src[2] & 0x80)
213             field |= 0xFF000000U;
214         *(dst++) += field;
215         ++src;
216     }
217 }
218 
219 static void mix32(int32_t *src, int64_t *dst, unsigned len)
220 {
221     TRACE("%p - %p %d\n", src, dst, len);
222     len /= 4;
223     while (len--)
224         *(dst++) += le32(*(src++));
225 }
226 
227 const mixfunc mixfunctions[4] = {
228     (mixfunc)mix8,
229     (mixfunc)mix16,
230     (mixfunc)mix24,
231     (mixfunc)mix32
232 };
233 
234 static void norm8(int32_t *src, int8_t *dst, unsigned len)
235 {
236     TRACE("%p - %p %d\n", src, dst, len);
237     while (len--)
238     {
239         *dst = (*src) + 0x80;
240         if (*src < -0x80)
241             *dst = 0;
242         else if (*src > 0x7f)
243             *dst = 0xff;
244         ++dst;
245         ++src;
246     }
247 }
248 
249 static void norm16(int32_t *src, int16_t *dst, unsigned len)
250 {
251     TRACE("%p - %p %d\n", src, dst, len);
252     len /= 2;
253     while (len--)
254     {
255         *dst = le16(*src);
256         if (*src <= -0x8000)
257             *dst = le16(0x8000);
258         else if (*src > 0x7fff)
259             *dst = le16(0x7fff);
260         ++dst;
261         ++src;
262     }
263 }
264 
265 static void norm24(int32_t *src, uint8_t *dst, unsigned len)
266 {
267     TRACE("%p - %p %d\n", src, dst, len);
268     len /= 3;
269     while (len--)
270     {
271         if (*src <= -0x800000)
272         {
273             dst[0] = 0;
274             dst[1] = 0;
275             dst[2] = 0x80;
276         }
277         else if (*src > 0x7fffff)
278         {
279             dst[0] = 0xff;
280             dst[1] = 0xff;
281             dst[2] = 0x7f;
282         }
283         else
284         {
285             dst[0] = *src;
286             dst[1] = *src >> 8;
287             dst[2] = *src >> 16;
288         }
289         ++dst;
290         ++src;
291     }
292 }
293 
294 static void norm32(int64_t *src, int32_t *dst, unsigned len)
295 {
296     TRACE("%p - %p %d\n", src, dst, len);
297     len /= 4;
298     while (len--)
299     {
300         *dst = le32(*src);
301         if (*src <= -(int64_t)0x80000000)
302             *dst = le32(0x80000000);
303         else if (*src > 0x7fffffff)
304             *dst = le32(0x7fffffff);
305         ++dst;
306         ++src;
307     }
308 }
309 
310 const normfunc normfunctions[4] = {
311     (normfunc)norm8,
312     (normfunc)norm16,
313     (normfunc)norm24,
314     (normfunc)norm32,
315 };
316 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.