FTDI latency on Linux (w/ patch)
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
ttyMIDI |
Fix Released
|
Undecided
|
Unassigned |
Bug Description
By default, it seems like the FTDI drivers on Linux can introduce perceptible amounts of latency. Running the example sketch on an Duemilanove, I found I could hear the 3 notes of the chord arpeggiated (briefly) each time the 3 note_on messages were sent.
I think this is because the FTDI accumulates individual bytes from the serial link, in order to send them in a single USB packet. It has an adjustable timer for this "Nagling".
The patch I've attached sets the ASYNC_LOW_LATENCY flag, which the FTDI driver interprets as a request to drop the timer to 1ms (ie send all accumulated bytes after 1ms.)
It seems you can also set the timer via the sysfs interface. I didn't realise that until after I wrote the patch! It still seems like it might be helpful if ttymidi does it automatically, though.
I haven't put #ifdef __linux__ around the linux-specific bits, because AFAIK ttymidi is Linux-only. This does add an additional dependency on the Linux userspace headers, though.
Hope the patch is useful. Ttymidi seems like a great package, by the way (we are planning to use it to run a "make your own MIDI controller" workshop at the Electrofringe electronic arts festival in Newcastle, Australia!)
Cheers
- Angus.
Hi Angus, thanks for the bug report and for the patch! I love patches :)
At a glance your code looks good. I will give it a quick test and update trunk as soon as possible.
Cheers,
- T