Le 14/01/2013 19:04, Christian Costa a écrit :
2013/1/14 Christian Costa <titan.co...@gmail.com>:
2013/1/14  <joerg-cyril.hoe...@t-systems.com>:
Hi,

Christian Costa wrote:
I took a look at the
alsa code and this code simply does not do what it is supposed to.
I also looked at it today and noted those bogus lines you quote. Needs
a patch (+ fix memory leak).
I will take a look at it and send a patch unless someone plan to do it.
I will not  be able to test with my 2 HW midi devices right now so I need
someone to test it. That would be good to enter a bug report for that.
Johannes, can you do that?

However, Johannes' change is presumably different, as he wants to
scan the buffer contents for a F7 terminator and ignore subsequent
bytes.  If I were to decide, I'd like to see more supporting evidence.
In the case the first by is F0 and the last one is F7, the code passes
I meant "last one if not F7".

Here are a patch to fix modLongData.
I tested it with the unit test attached.
Please give it a try.


diff --git a/dlls/winealsa.drv/midi.c b/dlls/winealsa.drv/midi.c
index 7c496c5..3f895e9 100644
--- a/dlls/winealsa.drv/midi.c
+++ b/dlls/winealsa.drv/midi.c
@@ -984,15 +984,16 @@ static DWORD modLongData(WORD wDevID, LPMIDIHDR lpMidiHdr, DWORD dwSize)
 	if (lpData[0] != 0xF0) {
 	    /* Send start of System Exclusive */
 	    len_add = 1;
-	    lpData[0] = 0xF0;
-	    memcpy(lpNewData, lpData, lpMidiHdr->dwBufferLength);
+	    lpNewData[0] = 0xF0;
+	    memcpy(lpNewData + 1, lpData, lpMidiHdr->dwBufferLength);
 	    WARN("Adding missing 0xF0 marker at the beginning of "
 		 "system exclusive byte stream\n");
 	}
 	if (lpData[lpMidiHdr->dwBufferLength-1] != 0xF7) {
 	    /* Send end of System Exclusive */
-	    memcpy(lpData + len_add, lpData, lpMidiHdr->dwBufferLength);
-            lpNewData[lpMidiHdr->dwBufferLength + len_add - 1] = 0xF0;
+	    if (!len_add)
+		memcpy(lpNewData, lpData, lpMidiHdr->dwBufferLength);
+            lpNewData[lpMidiHdr->dwBufferLength + len_add] = 0xF7;
 	    len_add++;
 	    WARN("Adding missing 0xF7 marker at the end of "
 		 "system exclusive byte stream\n");
#include <stdio.h>
#include <malloc.h>
#include <memory.h>

unsigned char data[] = {0xF0, 1, 2, 3, 4, 0xF6};

int main(void)
{
    int		len_add = 0;
    unsigned char	*lpData = data, *lpNewData = NULL;
    int dwBufferLength = sizeof(data);
    int i = 0;

    for (i = 0; i < dwBufferLength; i++)
        printf("%#x ", data[i]);
    printf("\n");

    if (lpData[0] != 0xF0 || lpData[dwBufferLength - 1] != 0xF7) {
        printf("Alleged system exclusive buffer is not correct\n\tPlease report with MIDI file\n");
        lpNewData = malloc(dwBufferLength + 2);
    }

    if (lpData[0] != 0xF0) {
        /* Send start of System Exclusive */
        len_add = 1;
        lpNewData[0] = 0xF0;
        memcpy(lpNewData + 1, lpData, dwBufferLength);
        printf("Adding missing 0xF0 marker at the beginning of "
               "system exclusive byte stream\n");
    }
    if (lpData[dwBufferLength-1] != 0xF7) {
        /* Send end of System Exclusive */
        if (!len_add)
            memcpy(lpNewData, lpData, dwBufferLength);
        lpNewData[dwBufferLength + len_add] = 0xF7;
        len_add++;
        printf("Adding missing 0xF7 marker at the end of "
               "system exclusive byte stream\n");
    }

    for (i = 0; i < dwBufferLength + len_add; i++)
        printf("%#x ", lpNewData ? lpNewData[i] : lpData[i]);
    printf("\n");

}


Reply via email to