My recent Arduino project: I connected the ACIA 6850 chip to the UNO R3 and wrote a fast little program which just passes incoming MIDI data right through the USB to my Linux ubuntu 12.04.
Then I wrote a test program in C which opens the serial port (/dev/ttyACM0) and a fast native MIDI-IN-via-PCI port and reads both and plots the precise time stamps in µs. The input to both MIDI ports (6850 and PCI-based) was exactly identical during all of my tests.
(I have lots of experience with this program because I already applied it to compare the MIDI-PCI transfer latency with a simple MIDI-USB-converter latency. The results were absolutely plausible: USB was between 0.20ms and 1.19ms too late (which is absolutely acceptable because the polling rate of MIDI-USB is 1ms).)
Now, the Arduino UNO R3 performs different: 1) The minimum latency compared with native MIDI is better than the simple MIDI-USB-converter: 0.14ms ! 2) The maximum latency is 5.1ms ! 3) Data is coming in at time stamps being multiples of 4ms (which is to expect according to here and here). But not always: From time to time the distance between two incoming MIDI events on the serial port is only 1ms, or 2ms, or 3ms, or 5ms. Conclusion: For MIDI-applications the provided latency is not good, but Jitter (from 0.14ms to 5.1ms behind the real MIDI event) is really terrible.
I wonder if the opinions from 2007 here, that 4ms is really a good choice for the latency timer configured in the firmware of the 16u2, changed in the meantime?
Is there an alternative firmware that handles incoming data (e.g. written with Serial.write() ) in a better way?
What is better? I can guess of several solutions:
1) If the latency timer is set according to the serial speed: I.e. if 38400 or less is chosen than you maximally transfer 3800 bytes per second, so a USB-latency of 10ms shouldn't be a problem, and if 115200 is chosen, the good old 4ms apply. But if a higher transfer rate is chosen (say >=1MBit) then the lowest latency timer should be chosen to achieve the 1ms latency.
2) Add a Serial.write_low_latency()
3) The latency timer is abandoned and instead the 16u2 collects the data coming in via Serial.write() only until the next USB-poll (which is each ms). If there is no data, then nothing is sent via USB.
I would be happy to assist in improving this, but at the moment I have no idea where to begin. Is it the sources of the LUFA lib?