Hi,
I am trying to build a java drum machine that needs to play WAV sound samples of the various drum parts (bass drum, snare, etc). Because I need to play the sounds in a tight sequence, I need high performance. Currently I'm using:
import sun.audio.*;
import java.io.*;
public class MusicPlayer {
private String filename;
public MusicPlayer(String filename) {
this.filename = filename;
}
public void play() {
try {
InputStream in = new FileInputStream(filename);
AudioStream as = new AudioStream(in);
AudioPlayer.player.start(as);
} catch (IOException e) {
e.printStackTrace();
}
}
}
as suggested here: http://stackoverflow.com/questions/26305/how-can-i-play-sound-in-java
While it does work faster than MP3 + Javazoom jLayer, it still sounds choppy at high tempo and when I do cpu intensive stuff like resizing the app window.
Any tips on improving performance?
BTW. I've also read that sun.audio.*
is deprecated. Is there a similar solution?