Re: question about CoreMIDI & cocoa
Re: question about CoreMIDI & cocoa
- Subject: Re: question about CoreMIDI & cocoa
- From: lazzaro <email@hidden>
- Date: Wed, 29 Sep 2004 13:49:09 -0700
On Sep 29, 2004, at 2:25 AM, Kurt Revis wrote:
The "right thing" to do would be to use a lockless ring buffer to
communicate from the CoreMIDI thread to the processing thread. Then
the CoreMIDI thread would never block.
If you bundle up the MIDI into a UDP packet and send it on
an AF_UNIX socket from the CoreMIDI thread to the processing
thread, and if you make the socket your send to non-blocking,
you can emulate this ring buffer using OS network services.
AF_UNIX sockets preserve in-order and are lossless on the same
machine, although adding a sequence number field to your packet
and checking it just to be sure never hurts (be conservative in what
you send, and liberal in what you accept).
This method has the advantage that N CoreMIDI threads can send to
one processing thread that is reading from a single socket -- just add
another field to indicate the sending thread.
Sfront uses this method, you can look at:
sfront/src/lib/csys/coremidi.c
in
http://www.cs.berkeley.edu/~lazzaro/sa/sfman/user/install/
index.html#download
for an example. Traditionally, socket code gets high priority in the
kernel, so I don't think latency will be an issue (in practice, it
hasn't
been for sfront). Nor have I ever seen the OS block on a write to
an AF_UNIX socket (I think its allowed to, though, sfront does not
do anything sensible at the moment if it does, as I recall -- better
code would queue the packet for a resend).
---
John Lazzaro
http://www.cs.berkeley.edu/~lazzaro
lazzaro [at] cs [dot] berkeley [dot] edu
---
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Coreaudio-api mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden