When playing sampled sounds using the Windows java 1.4.1 virtual machine, sounds play back incorrectly and the sound thread blocks all other goings-on, causing the main game thread to slow down and chop madly. After some testing I’ve concluded that this problem does not exist under the Windows 1.4.0_* runtimes and all other previous runtimes that implement javax.sound.sampled.
Am I doing something wrong? Or is the new runtime just horribly flawed?
I’ve posted an example jar (source included) that demonstrates the problem at
http://www.zianet.com/emeasure/SoundTest.jar
To run:
java -jar SoundTest.jar
p to play sound
arrow keys to move oval (demonstrates choppiness)
Relevant code:
private Clip clip;
private final void initializeClip()
{
try
{
AudioInputStream stream =
AudioSystem.getAudioInputStream( getClass().getResource( “test.wav” ) );
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat(), ( (int) stream.getFrameLength() * format.getFrameSize() ) );
clip = (Clip) AudioSystem.getLine( info );
// Wait until audio file completely loaded
clip.open( stream );
} catch( Exception e )
{
e.printStackTrace();
}
}
private final void playClip()
{
clip.setFramePosition( 0 );
clip.loop( 0 );
}
Thanks in advance for any insights you can provide,
lamster