Getting nice sound from Java
- by Peter Lang
I managed to play midi files using Java, but it produces some distracting noise. I figured out that this is caused by the poor quality soundbank file shipped with Java 6 SDK/JRE.
How can I improve that quality?
Here is what I have so far:
MidiNote example using a Receiver works fine (sounds the same as when playing midi files with other players), so it does not seem to use the Soundbank shipped with Java but the fallback mechanism that uses a hardware MIDI port.
Using SimpleMidiPlayer example to play a Midi file works, but the quality is poor.
When I delete lib/audio/soundbank.gm, the quality is not bad any more, so the fallback is used again.
When I put soundbank-deluxe.gm into the same directory, it is used and produces much better sound.
Messing with the clients soundbank file as described in the official Installation Instructions certainly isn't an option, so I tried to put the new soundbank-file into the jar-file and load it:
Soundbank soundbank = MidiSystem.getSoundbank(
getClass().getResourceAsStream("soundbank-deluxe.gm"));
if(synthesizer.isSoundbankSupported(soundbank)) {
System.out.println(synthesizer.loadAllInstruments(soundbank));
}
This prints true, but the sound remains unchanged.
What am I doing wrong loading the soundbank file?
Can I force the hardware MIDI port to be used instead of the standard soundbank file?