Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Definitive way to play sound effects ? (unsigned)  (Read 2055 times)
0 Members and 1 Guest are viewing this topic.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 42
Projects: 6



« Posted 2010-05-27 17:18:57 »

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 :

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
   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 .

Offline zammbi

JGO Coder


Medals: 4



« Reply #1 - Posted 2010-05-27 18:04:05 »

What about 3D sound system? http://www.jpct.net/forum2/topics/howdy-and-quot-help-quot/1057/view.html I don't believe any code signing is needed if your not using hardware support.

Current project - Rename and Sort
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 439
Projects: 4


Hand over your head.


« Reply #2 - Posted 2010-05-28 02:07:59 »

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.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline dishmoth
« Reply #3 - Posted 2010-05-28 11:19:43 »

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

Offline paulscode

Senior Member


Medals: 9


Staff Sergeant


« Reply #4 - Posted 2010-05-28 21:32:13 »

What about 3D sound system? http://www.jpct.net/forum2/topics/howdy-and-quot-help-quot/1057/view.html I don't believe any code signing is needed if your not using hardware support.
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.

We love death.  The US loves life.  That is the difference between us.  -Osama bin Laden, mass murderer
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 42
Projects: 6



« Reply #5 - Posted 2010-05-29 17:45:10 »

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.

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

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.

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!

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Try the Free Demo of Revenge of the Titans

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (123 views)
2013-05-17 21:29:12

alaslipknot (131 views)
2013-05-16 21:24:48

gouessej (161 views)
2013-05-16 00:53:38

gouessej (153 views)
2013-05-16 00:17:58

theagentd (166 views)
2013-05-15 15:01:13

theagentd (151 views)
2013-05-15 15:00:54

StreetDoggy (195 views)
2013-05-14 15:56:26

kutucuk (219 views)
2013-05-12 17:10:36

kutucuk (218 views)
2013-05-12 15:36:09

UnluckyDevil (221 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.133 seconds with 21 queries.