FULL PRODUCT VERSION :
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Darwin 13.4.0 Darwin Kernel Version 13.4.0: Mon Jan 11 18:17:34 PST 2016; root:xnu-2422.115.15~1/RELEASE_X86_64 x86_64
A DESCRIPTION OF THE PROBLEM :
When running a Java program that makes use of javax.sound.midi.MidiSynthesizer, if the process is suspended and then brought back*, this appears to cause a delay of several seconds in the audio produced by the MIDI synthesizer. MIDI note on/off events still appear to happen without delay, but there is a fixed delay in hearing the notes.
*Either by pressing `Ctrl-Z` followed after a couple seconds by `fg`, or by suspending and re-opening your laptop.
I've created a simple example demonstrating the problem here: https://github.com/daveyarwood/java-midi-delayed-audio-example
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Build and run the jar file for my example program: https://github.com/daveyarwood/java-midi-delayed-audio-example
The program initializes a static MidiSynthesizer instance, and then runs in an infinite loop, waiting for you to press Enter, and then using the MidiSynthesizer instance to play three MIDI piano notes. As it sends each MIDI note on event, it simultaneously prints which note it is playing to the console.
When you first run the program, the playing and printing are exactly in sync.
However, after suspending and bringing back the process*, there is a noticeable delay of several seconds between the printing and the playing.
*Either by pressing `Ctrl-Z` followed after a couple seconds by `fg`, or by suspending and re-opening your laptop.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The JVM MIDI synthesizer should always respond immediately to MIDI note on and off events.
ACTUAL -
After suspending and bringing back the process, there is a noticeable delay of several seconds between MIDI note on/off events and the corresponding audio being heard.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
No error messages are visible.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
https://github.com/daveyarwood/java-midi-delayed-audio-example
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I haven't found a workaround yet. In testing, it appears that after suspending and bringing back the process, there is always a delay in the audio even when initializing and using new MidiSynthesizer instances, so there may not be a workaround short of restarting the process.