I am trying to create a java drum machine that should play samples of WAV sound from various parts of a drum (bass drum, trap, etc.). Since I need to play sounds in a difficult sequence, I need high performance. I am currently 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: How can I play sound in Java?
While it is faster than the MP3 + Javazoom jLayer, it still sounds choppy at high speeds, and when I do an intensive processor process, like resizing the application window.
Any tips on improving performance?
BTW. I also read that I am sun.audio.*
out of date. Is there a similar solution?
source
share