Saw a post slightly below this asking same question but didn’t find an answer so I’ll repost his question since I am having the same problem.
I am playing small 22khz 16 bit WAV sound clips in a Java Applet using the following code:
InputStream is = loadFile(filename);
AudioInputStream ain = AudioSystem.getAudioInputStream(is);
DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat());
Clip clip = (Clip)AudioSystem.getLine(info);
clip.open(ain);
clip.start();
// I close the clip object with a linelistener once it's done playing
Works great, but takes about 6ms to execute, even on sounds that have already been loaded. I need to be able to play this sound more than once, and allow overlapping of that same sound.
Would like something more responsive - anyone have a faster method to play sound?
Some things I have tried:
- Holding a reference to the clip instance rather than reinstantiating seems to drop from 6ms to 2ms, but then repeating the same sound interrupts itself… I could get around this by keeping say, 4 references to the same clip but I’m also having issues with sounds entirely cutting out (never playing again) using this method.
- The basic play(getCodeBase(), filename) stuff is slow and doesn’t allow overlapping whatsoever
- OGG code streaming in a separate thread, this seems decent for music but for sound clips not responsive enough
Thanks,
Jesse