Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (552)
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 2929 times)
0 Members and 1 Guest are viewing this topic.
Offline teletubo
« League of Dukes »

JGO Ninja


Medals: 48
Projects: 4
Exp: 8 years



« Posted 2010-05-27 15: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 16:04:05 »

What about 3D sound system? http://www.jpct.net/forum2/topics/howdy-and/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: 781
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #2 - Posted 2010-05-28 00: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
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline dishmoth
« Reply #3 - Posted 2010-05-28 09: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: 12


Staff Sergeant


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

What about 3D sound system? http://www.jpct.net/forum2/topics/howdy-and/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: 48
Projects: 4
Exp: 8 years



« Reply #5 - Posted 2010-05-29 15: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.

 

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

The first screenshot will be displayed as a thumbnail.

CopyableCougar4 (22 views)
2014-08-22 19:31:30

atombrot (34 views)
2014-08-19 09:29:53

Tekkerue (30 views)
2014-08-16 06:45:27

Tekkerue (28 views)
2014-08-16 06:22:17

Tekkerue (18 views)
2014-08-16 06:20:21

Tekkerue (26 views)
2014-08-16 06:12:11

Rayexar (65 views)
2014-08-11 02:49:23

BurntPizza (41 views)
2014-08-09 21:09:32

BurntPizza (31 views)
2014-08-08 02:01:56

Norakomi (41 views)
2014-08-06 19:49:38
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!