title: Java MIDI audio is delayed after laptop comes out of hibernation
body: <p>I'm developing a <a href="https://github.com/alda-lang/alda" rel="noreferrer">music programming language</a>, and using the JVM (via Clojure) to play musical scores written in this language. So far, we are just using the javax.sound.midi MidiSynthesizer to play the scores.</p>
  
  <p>Because Clojure has a slow startup time and we want to be able to play a score from the command-line and hear it immediately, we've chosen to structure the score interpreter as a background server process, and communicate with it using a more lightweight command-line client written in Java.</p>
  
  <p>All of this is working great for the most part, however, there is a strange issue that we're seeing where if you start the server, then close your laptop* and let it hibernate, then open it again and have the server play a score, the audio doesn't happen immediately but is delayed for several seconds. Running the server with debug logging, I can actually see that the MIDI note on/off events are happening immediately (and timed correctly), but the audio is delayed.</p>
  
  <p>*This may or may not be platform-specific. I'm seeing the issue on my 2014 Macbook Pro running OS X 10.9.5 Mavericks.</p>
  
  <p>To help narrow it down, I put together this simple example (using Java, not Clojure) that demonstrates the problem: </p>
  
  <p><a href="https://github.com/daveyarwood/java-midi-delayed-audio-example" rel="noreferrer">https://github.com/daveyarwood/java-midi-delayed-audio-example</a></p>
  
  <p>I've been scratching my head over this for a while now. Why is the audio delayed, and is there anything we can do about it?</p>