Definitive way to play sound effects ? (unsigned)

Hello folks.
I am having a hard time with sound effects on my TinyGame entry (Zombie Defense ) .

I tried using EasyOgg from kevGlass, but I was having bad sound glitches … then I read somewhere it was supposed to be used to play background music , not sound effects .

Then I switched back to my old WAV playing code . It seems to work well, except that my final jar got much much bigger than when I used ogg (from 700K to 2.5 MB), for obvious reasons , and additionally it seems to create a major leak .

my code for playing a wave is the following :


	byte[] bytes ;
        Clip clip;
	public SSound (String s)
	{
 
				bytes = loadBytesFromStream(Thread.currentThread().getContextClassLoader().getResourceAsStream(s));

        }



	public void play()
	{

 
			ByteArrayInputStream is = new ByteArrayInputStream(bytes);
			AudioInputStream ain;
			try {
				ain = AudioSystem.getAudioInputStream(is);			
				DataLine.Info info = new DataLine.Info(Clip.class, ain.getFormat());		
				clip  = (Clip)AudioSystem.getLine(info);
				clip.open(ain);
				clip.start();
			} catch (Exception e) {
				e.printStackTrace();
			}
	}


I know there are alternatives using 3d sounds, but I would have to sign my jar, which is neither desirable for me nor for the TinyGame Comp.

So is there a good and memory friendly way to play sound effects ?

Thank you in advance .

What about 3D sound system? http://www.jpct.net/forum2/index.php/topic,1057.0.html I don’t believe any code signing is needed if your not using hardware support.

If a low initial download size is a high priority, why not stream in your WAV data over HTTP?

The only downside is that you can only ‘cache’ it in RAM.

I expect there are better examples, but if you get desperate you could try “OggDecode.java” and “SoundEffect.java” from here.

They work on top of the JOrbis library. OggDecode is basically a cleaned-up version of JOrbis’s DecodeExample with better error reporting (because I couldn’t get DecodeExample to work). It reads an Ogg Vorbis stream in as a Clip object.

SoundEffect is just a wrapper around a Clip, but it tries to limit the overall number of active Clips (since I found that some machines impose a limit, although this seems to be rare).

I can’t promise that the code works any better than what you’ve got already though. :wink:

Simon

Zammbi is right, you could use the core SoundSystem Library along with the LibraryJavaSound plug-in and any of the codec plug-ins (CodecJOrbis to play OGG files for example). These are all pure-java and wouldn’t require your applet to be signed. This library is designed to be for 3D sound so it may be overkill for your project, but the license is basically “do what you want” so you are free to copy and paste just what you need from the source code.

Well the priority was just to make it work ! But thanks for the suggestion

Thank you zammbi and paulscode . I gave it a shot and worked great (at least on my browser ) .
I even changed my code a bit to take afvantage of 3d sound and so now I have “2d sound” on my game.

Great library paulscode, thanks!