[PATCH] dsound: Add mixing and normalization functions
Maarten Lankhorst
maarten at codeweavers.com
Sat Oct 13 13:11:51 CDT 2007
---
dlls/dsound/dsound_convert.c | 132 ++++++++++++++++++++++++++++++++++++++++++
dlls/dsound/dsound_private.h | 4 +
2 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/dlls/dsound/dsound_convert.c b/dlls/dsound/dsound_convert.c
index ab7e288..9d20a75 100644
--- a/dlls/dsound/dsound_convert.c
+++ b/dlls/dsound/dsound_convert.c
@@ -170,3 +170,135 @@ bitsconvertfunc convertbpp[4][4] = {
{ convert_24_to_8, convert_24_to_16, convert_24_to_24, convert_24_to_32 },
{ convert_32_to_8, convert_32_to_16, convert_32_to_24, convert_32_to_32 },
};
+
+static void mix8(int8_t *src, int32_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ while (len--)
+ /* 8-bit WAV is unsigned, it's here converted to signed, normalize function will convert it back again */
+ *(dst++) += (int8_t)(*(src++) ^ 0x80);
+}
+
+static void mix16(int16_t *src, int32_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 2;
+ while (len--)
+ {
+ *dst += *src;
+ ++dst; ++src;
+ }
+}
+
+static void mix24(int24_struct *src, int32_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 3;
+ while (len--)
+ {
+ uint32_t field;
+ field = ((unsigned)src->byte[2] << 16U) + ((unsigned)src->byte[1] << 8U) + (unsigned)src->byte[0];
+ if (src->byte[2] & 0x80)
+ field |= 0xFF000000U;
+ *(dst++) += (int32_t)field;
+ ++src;
+ }
+}
+
+static void mix32(int32_t *src, int64_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 4;
+ while (len--)
+ *(dst++) += *(src++);
+}
+
+mixfunc mixfunctions[4] = {
+ (mixfunc)mix8,
+ (mixfunc)mix16,
+ (mixfunc)mix24,
+ (mixfunc)mix32
+};
+
+static void norm8(int32_t *src, int8_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ while (len--)
+ {
+ *dst = (*src) + 0x80;
+ if (*src < -0x80)
+ *dst = 0;
+ else if (*src > 0x7f)
+ *dst = 0xff;
+ ++dst;
+ ++src;
+ }
+}
+
+static void norm16(int32_t *src, int16_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 2;
+ while (len--)
+ {
+ *dst = *src;
+ if (*src <= -0x8000)
+ *dst = 0x8000;
+ else if (*src > 0x7fff)
+ *dst = 0x7fff;
+ ++dst;
+ ++src;
+ }
+}
+
+static void norm24(int32_t *src, int24_struct *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 3;
+ while (len--)
+ {
+ if (*src <= -0x800000)
+ {
+ dst->byte[0] = 0;
+ dst->byte[1] = 0;
+ dst->byte[2] = 0x80;
+ }
+ else if (*src > 0x7fffff)
+ {
+ dst->byte[0] = 0xff;
+ dst->byte[1] = 0xff;
+ dst->byte[2] = 0x7f;
+ }
+ else
+ {
+ dst->byte[0] = *src;
+ dst->byte[1] = *src >> 8;
+ dst->byte[2] = *src >> 16;
+ }
+ ++dst;
+ ++src;
+ }
+}
+
+static void norm32(int64_t *src, int32_t *dst, unsigned len)
+{
+ TRACE("%p - %p %d\n", src, dst, len);
+ len /= 4;
+ while (len--)
+ {
+ *dst = *src;
+ if (*src <= -0x80000000LL)
+ *dst = 0x80000000;
+ else if (*src > 0x7fffffffLL)
+ *dst = 0x7fffffff;
+ ++dst;
+ ++src;
+ }
+}
+
+normfunc normfunctions[4] = {
+ (normfunc)norm8,
+ (normfunc)norm16,
+ (normfunc)norm24,
+ (normfunc)norm32,
+};
diff --git a/dlls/dsound/dsound_private.h b/dlls/dsound/dsound_private.h
index 92133c2..339877e 100644
--- a/dlls/dsound/dsound_private.h
+++ b/dlls/dsound/dsound_private.h
@@ -72,6 +72,10 @@ typedef struct DirectSoundCaptureDevice DirectSoundCaptureDevice;
/* dsound_convert.h */
typedef void (*bitsconvertfunc)(const void *, void *);
extern bitsconvertfunc convertbpp[4][4];
+typedef void (*mixfunc)(const void *, void *, unsigned);
+extern mixfunc mixfunctions[4];
+typedef void (*normfunc)(const void *, void *, unsigned);
+extern normfunc normfunctions[4];
/*****************************************************************************
* IDirectSoundDevice implementation structure
--
1.5.2.5
--------------090409080307070706060907--
More information about the wine-patches
mailing list