Midi playback is fine using the JDK but not in JRE

Midi files being played work fine in my game and my midi player as long as im running them from the java sdk’s java program (i’ve tried 1.4.0 - 1.4.2) but when i run them from the jre version (such as double clicking a jar file) it’s as if it can’t keep time.

Eg. “C:\Program Files\Java\j2re1.4.0\bin\java.exe” -jar JMidi.jar

is choppy, but
c:\j2sdk1.4.0\bin\java.exe -jar JMidi.jar

works just fine.

anyone have any idea why this happens or how to prevent the poor timing when people want to run java programs that use midi in the JRE?

win xp dell 1ghz laptop.
same on amd k6/2 450 winxp.

Midi playback in Java uses software synthesis, which requires a soundbank. The soundbank is included in Java SDK, and in your case it is located in
c:\j2sdk1.4.0\jre\lib\audio\soundbank.gm

However, to cut down the size of Windows version of JRE, Sun decided not to include the soundbank in Windows JRE (although it is included in Linux and Solaris version). Without a soundbank, JRE cannot perform software synthesis and JRE performs hardware synthesis using your sound card. In hardware synthesis, the sounds are different when using different sound cards and the timing can be poor.

So the only solution to your problem is that the people who only have the JRE version have to install a soundbank. Soundbanks can be downloaded from here:
http://java.sun.com/products/java-media/sound/soundbanks.html

AHHHHHHHH so that explains it!

well, this is good. i didnt even notice that the midi sounded diferent on the jre runtime, just noticed the horrible timing.

the minimum soundbank, only 300 kb sounds like the sound you get out of JDK, although i do admit the medium one sounds much better. i’m downloading the 4 mb one but for a simple tetris game it’s not going anywhere. will be interesting to see the results… i wish i was good at making my own samples for a custom sound bank. that’d make it stand out.

anyway thanks for posting that link!.

-JuddMan!

btw the soundbanks work easily enough by just residing in the directory your Jar file is in. (i would have my program move it to the correct directory if i knew how to locate the JRE installation that’s currently in use.)

very dissappointed… the biggest sound bank actually sounds worse than both the others, but i suppose it depends on your midi files as well. i think they may have been testing with only a few of them…

i’ll listen to a couple more…

nope…
nope…
omg…
hmm not too bad…
nope…
what it sounds like… is a high quality recording through a low quality microphone… or… WMA…

the medium one is good and the small one is a good size to include with a game.

Java uses Beatnik Audio Engine to render MIDI notes. If you want to use other instruments than the ones included in the general midi soundbank, or you want to have a smaller soundbank, you can create a soundbank yourself. This can be done using Beatnik Editor:
http://www.beatnik.com/products/editor.html.

You can load your own soundbanks using
MidiSystem.getSoundbank