Re: MIDISend problems
Re: MIDISend problems
- Subject: Re: MIDISend problems
- From: Fredrik Lundkvist <email@hidden>
- Date: Tue, 3 Jun 2003 15:47:06 +0200
2) I made another test sending lots of messages. It looks like the
MIDISend function
runs happily until a buffer is filled, then it waits until there
is room in the buffer,
blocking the calling thread.
How much data can you send before it blocks? The communication
between your program and the MIDIServer process takes place through
a fixed-size ring buffer in shared memory. My understanding is that
if you fill up this buffer before the MIDIServer gets a chance to
empty it, CoreMIDI falls back to putting the data in a secondary
buffer (so it doesn't lose any data). Probably something related to
that is causing the block. I don't know if it is possible for
CoreMIDI to handle this case without blocking or not
not, it's not possible -- no matter how big I make that ring buffer,
it can fill and I'll have to fall back -- but: the thread in the
MIDIServer that empties the ring buffer runs with realtime priority,
and so it should be somewhat difficult to get into these kinds of
cases unless you are sending huge amounts of data *from* a realtime
thread ... or sending data faster than it can get out the interface
port ...
... perhaps someone in the CoreAudio team can say.
If you are sending all the data in one packet list (in one call to
MIDISend()), you might try breaking it up into multiple packet lists
and multiple calls to MIDISend(), in hopes that the MIDIServer will
have more opportunities to read from the buffer before you fill it.
Just an idea -- I don't know if this will work or not.
It's a loop sending thousands of messages, one in each packet list.
It looks like it blocks after one thousand, then each thousand takes
about a second to send.
1000 messages/second * 3 bytes/message * 10 bits/byte
(on a MIDI serial link, there are stop and start bits in addition to
8 data bits/byte)
= 30000 bits/second
The speed of MIDI is 31250 bytes per second -- so it looks like
everything is behaving just as one would expect.
Hi
I just found out that some stupid code of mine was the big culprit in
this case.
It just happened to make my sending test as slow as if it was sent at
the MIDI speed given above.
MIDISend still block sometimes but only a few milliseconds.
Fredrik
This means I must create a separate thread that sends all messages if
my
application should stay responsive when there is a buffer overflow,
right?
If you're sending large amounts of data, yes, although you can use
MIDISendSysEx (if sysex is what you're sending) to create a separate
sending thread for you too.
Doug
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.
_______________________________________________
coreaudio-api mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/coreaudio-api
Do not post admin requests to the list. They will be ignored.