[PATCH] dmusic: Midi message takes 4 bytes space but only 3 are relevant + add tests to check buffer content.

Christian Costa titan.costa at gmail.com
Mon Apr 30 04:42:40 CDT 2012


---
 dlls/dmusic/buffer.c       |    4 ++--
 dlls/dmusic/tests/dmusic.c |   45 +++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 44 insertions(+), 5 deletions(-)

diff --git a/dlls/dmusic/buffer.c b/dlls/dmusic/buffer.c
index bf60470..2fd76b5 100644
--- a/dlls/dmusic/buffer.c
+++ b/dlls/dmusic/buffer.c
@@ -109,7 +109,7 @@ static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER
     if (new_write_pos > This->size)
         return DMUS_E_BUFFER_FULL;
 
-    /* Channel_message 0xZZYYXX is a midi message where XX = status byte, YY = byte 1 and ZZ = byte 2 */
+    /* Channel_message 0xZZYYXX (3 bytes) is a midi message where XX = status byte, YY = byte 1 and ZZ = byte 2 */
 
     if (!(channel_message & 0x80))
     {
@@ -120,7 +120,7 @@ static HRESULT WINAPI IDirectMusicBufferImpl_PackStructured(LPDIRECTMUSICBUFFER
     if (!This->write_pos)
         This->start_time = ref_time;
 
-    header.cbEvent = sizeof(channel_message);
+    header.cbEvent = 3; /* Midi message takes 4 bytes space but only 3 are relevant */
     header.dwChannelGroup = channel_group;
     header.rtDelta = ref_time - This->start_time;
     header.dwFlags = DMUS_EVENT_STRUCTURED;
diff --git a/dlls/dmusic/tests/dmusic.c b/dlls/dmusic/tests/dmusic.c
index a05afcc..038f8b2 100644
--- a/dlls/dmusic/tests/dmusic.c
+++ b/dlls/dmusic/tests/dmusic.c
@@ -39,6 +39,13 @@ static inline char* debugstr_guid(CONST GUID *id)
     return string;
 }
 
+static inline char* debugstr_longlong(LONGLONG val)
+{
+    static char string[17];
+    sprintf(string, "%08x%08x", *((DWORD*)&val + 1), *(DWORD*)&val);
+    return string;
+}
+
 static void test_dmusic(void)
 {
     IDirectMusic *dmusic = NULL;
@@ -114,6 +121,7 @@ static void test_dmbuffer(void)
     DWORD size;
     DWORD bytes;
     REFERENCE_TIME time;
+    LPBYTE data;
 
     hr = CoCreateInstance(&CLSID_DirectMusic, NULL, CLSCTX_INPROC_SERVER, &IID_IDirectMusic, (LPVOID*)&dmusic);
     if (hr != S_OK)
@@ -148,18 +156,49 @@ static void test_dmbuffer(void)
     ok(hr == DMUS_E_INVALID_EVENT, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
     hr = IDirectMusicBuffer_PackStructured(dmbuffer, 20, 0, 0x000090); /* note on : chan 0, note 0 & vel 0 */
     ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
+    hr = IDirectMusicBuffer_PackStructured(dmbuffer, 30, 0, 0x000080); /* note off : chan 0, note 0 & vel 0 */
+    ok(hr == S_OK, "IDirectMusicBuffer_PackStructured returned %x\n", hr);
     hr = IDirectMusicBuffer_GetUsedBytes(dmbuffer, &bytes);
     ok(hr == S_OK, "IDirectMusicBuffer_GetUsedBytes returned %x\n", hr);
-    ok(bytes == 24, "Buffer size is %u instead of 0\n", bytes);
+    ok(bytes == 48, "Buffer size is %u instead of 48\n", bytes);
 
     hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
     ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
     ok(time == 20, "Buffer start time is wrong\n");
-    hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 30);
+    hr = IDirectMusicBuffer_SetStartTime(dmbuffer, 40);
     ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
     hr = IDirectMusicBuffer_GetStartTime(dmbuffer, &time);
     ok(hr == S_OK, "IDirectMusicBuffer_GetStartTime returned %x\n", hr);
-    ok(time == 30, "Buffer start time is wrong\n");
+    ok(time == 40, "Buffer start time is wrong\n");
+
+    hr = IDirectMusicBuffer_GetRawBufferPtr(dmbuffer, &data);
+    ok(hr == S_OK, "IDirectMusicBuffer_GetRawBufferPtr returned %x\n", hr);
+    if (hr == S_OK)
+    {
+        DMUS_EVENTHEADER* header;
+        DWORD message;
+
+        /* Check message 1 */
+        header = (DMUS_EVENTHEADER*)data;
+        data += sizeof(DMUS_EVENTHEADER);
+        ok(header->cbEvent == 3, "cbEvent is %u instead of 3\n", header->cbEvent);
+        ok(header->dwChannelGroup == 0, "dwChannelGroup is %u instead of 0\n", header->dwChannelGroup);
+        ok(header->rtDelta == 0, "rtDelta is %s instead of 0\n", debugstr_longlong(header->rtDelta));
+        ok(header->dwFlags == DMUS_EVENT_STRUCTURED, "dwFlags is %x instead of %x\n", header->dwFlags, DMUS_EVENT_STRUCTURED);
+        message = *(DWORD*)data & 0xffffff; /* Only 3 bytes are relevant */
+        data += sizeof(DWORD);
+        ok(message == 0x000090, "Message is %0x instead of 0x000090\n", message);
+
+        /* Check message 2 */
+        header = (DMUS_EVENTHEADER*)data;
+        data += sizeof(DMUS_EVENTHEADER);
+        ok(header->cbEvent == 3, "cbEvent is %u instead of 3\n", header->cbEvent);
+        ok(header->dwChannelGroup == 0, "dwChannelGroup is %u instead of 0\n", header->dwChannelGroup);
+        ok(header->rtDelta == 10, "rtDelta is %s instead of 0\n", debugstr_longlong(header->rtDelta));
+        ok(header->dwFlags == DMUS_EVENT_STRUCTURED, "dwFlags is %x instead of %x\n", header->dwFlags, DMUS_EVENT_STRUCTURED);
+        message = *(DWORD*)data & 0xffffff; /* Only 3 bytes are relevant */
+        ok(message == 0x000080, "Message 2 is %0x instead of 0x000080\n", message);
+    }
 
     if (dmbuffer)
         IDirectMusicBuffer_Release(dmbuffer);




More information about the wine-patches mailing list