Groboclown, I am guessing getMicrosecondPosition will be based on the frames the hardware has rendered and will be the easiest and most accurate method.
I attempted this on Windows XP, Linux, and OS X Snow Leopard. For each of these, I attempted essentially the following code, with a buffer size of 8 times the frame size:
long startTime = outputLine.getMicrosecondPosition();
for (int i = 0; i < FRAMES_PER_SECOND * 2; i++) {
outputLine.write(buffer, 0, BYTES_PER_FRAME);
}
System.out.println(outputLine.getMicrosecondPosition() - startTime);
On each of these systems, the reported microsecond delta is extremely close to 2 seconds after outputting 2 seconds worth of audio data. The getLongFramePosition() has roughly the same results. However, empirical tests show the latency more like:
Buffer Size: 0.26 seconds
Windows XP: 0.13 seconds
Linux: 0.47 seconds
OS X: 0.37 seconds
As the Windows XP results were below the audio buffer size, this makes me think that it's directly accessing the audio driver, while the others, being larger than my allocated buffer size, use a buffer separate from the audio driver.
Perhaps I'm missing something in my analysis here. Does this look about right?